nchopin/particles

Sequential Monte Carlo in python

What it solves

This library provides ready-to-use tools for Sequential Monte Carlo (SMC) methods, also known as particle filtering and smoothing. It lets you estimate the hidden states of a system from noisy observations, and it also supports parameter inference and model comparison. The authors built it to complement a textbook on SMC, and it now includes newer algorithms beyond the book.

How it works

You define a state-space model by specifying three probability distributions: the initial state, the transition from one state to the next, and the observation given the state. The library then runs a particle filter that simulates many possible state trajectories ("particles") and reweights them based on how well they match the data. It offers multiple resampling schemes (multinomial, residual, stratified, systematic, SSP) and several filtering variants (bootstrap, guided, APF). For smoothing, it provides forward filtering backward sampling (FFBS) with fast approximations, fixed-lag smoothing, online smoothing, and two-filter smoothing. It also includes exact Kalman filtering for linear Gaussian models and forward-backward recursions for finite hidden Markov models. Beyond filtering, the library supports SMC samplers for Bayesian inference (SMC tempering, IBIS), PMCMC, SMC^2, nested sampling, variance estimators, and parallel execution across CPU cores.

Who it’s for

Researchers, statisticians, and practitioners who need a reliable, tested Python implementation of particle filtering and related Monte Carlo techniques. It is also useful for educators and students following the companion textbook, or anyone who wants to prototype state-space models quickly using a small amount of probabilistic programming.

Highlights

  • Define complex state-space models with a few Python methods (PX0, PX, PY) and simulate data directly.
  • Run a full particle filter with one line of code: particles.SMC(fk=ssm.Bootstrap(ssm=my_model, data=y), N=200).run().
  • Includes many resampling schemes and filtering variants (bootstrap, guided, APF).
  • Supports fast FFBS variants using MCMC or rejection for efficient smoothing.
  • Implements advanced Bayesian inference methods: PMCMC, SMC^2, and SMC samplers for variable selection.
  • Provides variance estimators and nested sampling, plus basic parallel computation.

Related

  • Project
  • Project
  • Project
  • Project