Skip to content

Backward Sampler

cuthbert.smc.backward_sampler

Implements backward sampling for particle filters.

Supports 3 different algorithms for backward sampling:

build_smoother(log_potential, backward_sampling_fn, resampling_fn, n_smoother_particles)

Build a particle smoother object.

Parameters:

Name Type Description Default
log_potential LogPotential

Function to compute the JOINT log potential \(\log G_t(x_{t-1}, x_t) + \log M_t(x_t \mid x_{t-1})\).

required
backward_sampling_fn BackwardSampling

Backward sampling algorithm to use (e.g., genealogy tracing, exact backward sampling). This choice specifies how to sample \(x_{t-1} \sim p(x_{t-1} \mid x_t, y_{0:t-1})\) given samples \(x_{t} \sim p(x_t \mid y_{0:T})\). See cuthbertlib/smc/smoothing/ for possible choices.

required
resampling_fn Resampling

Resampling algorithm to use (e.g., multinomial, systematic).

required
n_smoother_particles int

Number of samples to draw from the backward sampling algorithm.

required

Returns:

Type Description
Smoother

Particle smoother object.

Source code in cuthbert/smc/backward_sampler.py
def build_smoother(
    log_potential: LogPotential,
    backward_sampling_fn: BackwardSampling,
    resampling_fn: Resampling,
    n_smoother_particles: int,
) -> Smoother:
    r"""Build a particle smoother object.

    Args:
        log_potential: Function to compute the JOINT log potential $\log G_t(x_{t-1}, x_t) + \log M_t(x_t \mid x_{t-1})$.
        backward_sampling_fn: Backward sampling algorithm to use (e.g., genealogy tracing, exact backward sampling).
            This choice specifies how to sample $x_{t-1} \sim p(x_{t-1} \mid x_t, y_{0:t-1})$ given
            samples $x_{t} \sim p(x_t \mid y_{0:T})$. See `cuthbertlib/smc/smoothing/` for possible choices.
        resampling_fn: Resampling algorithm to use (e.g., multinomial, systematic).
        n_smoother_particles: Number of samples to draw from the backward sampling algorithm.

    Returns:
        Particle smoother object.
    """
    return Smoother(
        convert_filter_to_smoother_state=partial(
            convert_filter_to_smoother_state,
            resampling=resampling_fn,
            n_smoother_particles=n_smoother_particles,
        ),
        smoother_prepare=smoother_prepare,
        smoother_combine=partial(
            smoother_combine,
            backward_sampling_fn=backward_sampling_fn,
            log_potential=log_potential,
        ),
        associative=False,
    )