Skip to content

Probabilistic Programming API

This page is a flat index of the public exports of Reactant.ProbProg, Reactant's probabilistic-programming module. Names are qualified as ProbProg.<name>; using Reactant: ProbProg unqualifies them.

For walkthroughs and runnable end-to-end programs, follow the Probabilistic Programming tutorials:

The conceptual vocabulary (traces, choice maps, selections, generative functions) is the same as in Gen.jl; readers familiar with Gen can map Constraint onto Gen's ChoiceMap, select onto Gen.select, and so on.

Types

SymbolSignatureSee
Tracemutable struct Trace; choices, retval, weight, subtraces; endTraces and constrained inference
AddressAddress(syms::Symbol...)Traces and constrained inference
Selectionconst Selection = OrderedSet{Address}; built via selectTraces and constrained inference
ConstraintConstraint(pairs::Pair...)Traces and constrained inference
MCMCStatemutable struct MCMCState; position, gradient, potential_energy, step_size, inverse_mass_matrix, rng; endRunning and resuming chains

Distributions

ProbProg.sample(rng, dist; symbol=:x) works on any Distribution subtype. Built-in distributions (Normal, Exponential, LogNormal, Bernoulli) and the recipe for defining custom ones are described in the Sampling and distributions tutorial.

Modeling

SymbolSignatureSee
samplesample(rng, dist; symbol) &nbsp;/&nbsp; sample(rng, f, args...; symbol, logpdf, support, bounds)Sampling and distributions
untraced_calluntraced_call(rng, f, args...)Sampling and distributions
simulatesimulate(rng, f, args...) -> (trace_tensor, weight, retval)Traces and constrained inference
simulate_simulate_(rng, f, args...) -> (trace::Trace, weight)Traces and constrained inference
generategenerate(rng, constraint_tensor, f, args...; constrained_addresses)Traces and constrained inference
generate_generate_(rng, constraint, f, args...) -> (trace::Trace, weight)Traces and constrained inference

Inference

SymbolSignatureSee
mhmh(rng, trace, weight, f, args...; selection)MCMC: MH, HMC, NUTS
mcmcmcmc(rng, original_trace, f, args...; selection, algorithm, step_size, inverse_mass_matrix, num_warmup, num_samples, ...) &nbsp;/&nbsp; mcmc(state::MCMCState, ...)MCMC: MH, HMC, NUTS
mcmc_logpdfmcmc_logpdf(rng, logdensity_fn, initial_position, args...; algorithm, step_size, inverse_mass_matrix, ...) &nbsp;/&nbsp; mcmc_logpdf(state::MCMCState, ...)MCMC: MH, HMC, NUTS
run_chainrun_chain(rng, logpdf_fn, initial_position, args...; num_warmup, num_samples, chunk_size, ...) &nbsp;/&nbsp; run_chain(state::MCMCState, ...)Running and resuming chains

NUTS currently requires an explicit step_size; the default step_size = nothing is rejected by the pass implementation (find_reasonable_step_size is not yet implemented). Pass Reactant.ConcreteRNumber(0.1) (or similar) and rely on dual averaging when adapt_step_size = true.

State persistence

SymbolSignatureSee
save_statesave_state(filename::String, state::MCMCState)Running and resuming chains
load_stateload_state(filename::String) -> MCMCStateRunning and resuming chains

Utilities

SymbolSignatureSee
selectselect(addrs::Address...) -> SelectionTraces and constrained inference
get_choicesget_choices(trace::Trace) -> Dict{Symbol,Any}Traces and constrained inference
with_tracewith_trace(f) -> (f_result, tt) (installs the Impulse tracing context for the duration of f(); collects the layout metadata unflatten_trace needs)Traces and constrained inference
unflatten_traceunflatten_trace(trace_tensor, weight, entries, retval) -> TraceTraces and constrained inference
filter_entries_by_selectionfilter_entries_by_selection(entries, selection)MCMC: MH, HMC, NUTS
extract_addressesextract_addresses(constraint::Constraint) -> Set{Address}Traces and constrained inference
mcmc_summarymcmc_summary(samples; names) &nbsp;/&nbsp; mcmc_summary(trace::Trace)Running and resuming chains