Configuring an SMC runner

Configuring an SMC runner#

The SequentialMonteCarlo runner applies a sequence of steps and optional callbacks at every iteration. The quickest way to build a Bayesian inference pipeline is the pre-built helper:

from sequince import make_standard_bayesian_smc
from sequince.callbacks import TracePlot

smc, posterior, metadata = make_standard_bayesian_smc(
    log_prior,
    log_likelihood,
    mutation="emcee",
    resampling="systematic",
    callbacks=[TracePlot()],
)

make_standard_bayesian_smc constructs an SMC runner that adaptively steps through a series of simulated annealing temperatures (AdaptiveTemperedWeighting), applying a resampling step (SystematicResampling) and a mutation step (MutationStep) at each iteration. See Resampling configuration and Mutation configuration for the available reasmpling and mutation options and configuration.

See Built-in callbacks for the available plotting callbacks and their settings.

When starting the run, pass the metadata returned by the convenience constructor:

result = smc.run(
    initial_state,
    rng=rng,
    shared_context=shared_context,
    metadata=metadata,
)

See Step context for the distinction between static shared_context data and evolving metadata.

Building a pipeline manually#

For full control, instantiate the runner with steps in execution order. For example, to reproduce the pre-built SMC defined above:

from sequince import SequentialMonteCarlo
from sequince.callbacks import TracePlot
from sequince.steps import (
    AdaptiveTemperedWeighting,
    EmceeMutation,
    SystematicResampling,
)

smc = SequentialMonteCarlo(
    steps=[
        AdaptiveTemperedWeighting(posterior),
        SystematicResampling(always_resample=True),
        EmceeMutation(posterior, n_steps=10),
    ],
    callbacks=[TracePlot()],
)

Each entry in steps must follow the SMCStep interface. Each callback must follow the SMCCallback interface. See Custom steps and Custom callbacks when implementing these interfaces yourself.