Skip to content

Particle Filter

cuthbert.smc.particle_filter

Implements the generic particle filter.

See Algorithm 10.1, Chopin and Papaspiliopoulos, 2020.

build_filter(init_sample, propagate_sample, log_potential, n_filter_particles, resampling_fn, ess_threshold)

Builds a particle filter object.

Parameters:

Name Type Description Default
init_sample InitSample

Function to sample from the initial distribution \(M_0(x_0)\).

required
propagate_sample PropagateSample

Function to sample from the Markov kernel \(M_t(x_t \mid x_{t-1})\).

required
log_potential LogPotential

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

required
n_filter_particles int

Number of particles for the filter.

required
resampling_fn Resampling

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

required
ess_threshold float

Fraction of particle count specifying when to resample. Resampling is triggered when the effective sample size (ESS) < ess_threshold * n_filter_particles.

required

Returns:

Type Description
Filter

Filter object for the particle filter.

Source code in cuthbert/smc/particle_filter.py
def build_filter(
    init_sample: InitSample,
    propagate_sample: PropagateSample,
    log_potential: LogPotential,
    n_filter_particles: int,
    resampling_fn: Resampling,
    ess_threshold: float,
) -> Filter:
    r"""Builds a particle filter object.

    Args:
        init_sample: Function to sample from the initial distribution $M_0(x_0)$.
        propagate_sample: Function to sample from the Markov kernel $M_t(x_t \mid x_{t-1})$.
        log_potential: Function to compute the log potential $\log G_t(x_{t-1}, x_t)$.
        n_filter_particles: Number of particles for the filter.
        resampling_fn: Resampling algorithm to use (e.g., systematic, multinomial).
        ess_threshold: Fraction of particle count specifying when to resample.
            Resampling is triggered when the
            effective sample size (ESS) < ess_threshold * n_filter_particles.

    Returns:
        Filter object for the particle filter.
    """
    return Filter(
        init_prepare=partial(
            init_prepare,
            init_sample=init_sample,
            log_potential=log_potential,
            n_filter_particles=n_filter_particles,
        ),
        filter_prepare=partial(
            filter_prepare,
            init_sample=init_sample,
            n_filter_particles=n_filter_particles,
        ),
        filter_combine=partial(
            filter_combine,
            propagate_sample=propagate_sample,
            log_potential=log_potential,
            resampling_fn=resampling_fn,
            ess_threshold=ess_threshold,
        ),
        associative=False,
    )