Table of Contents
Fetching ...

Approximate Bayesian Computation Made Easy: A Practical Guide to ABC-SMC for Dynamical Systems with \texttt{pymc}

Mario Castro

TL;DR

This work addresses parameter inference for mechanistic dynamical models when likelihoods are intractable by presenting ABC-SMC as an accessible, likelihood-free Bayesian approach implemented in PyMC. Through four case studies—ranging from fully observed Lotka–Volterra to latent-structural SEIR with hierarchical pooling—the tutorial demonstrates practical workflow, diagnostics, and interpretation of approximate posteriors and posterior predictive checks. It emphasizes design choices (summaries, distances, tolerances), diagnostic tools (ESS, tolerance trajectories, PPCs), and strategies to leverage partial observability and information sharing across groups. By combining a practical, example-driven narrative with a unified PyMC-based interface, the paper provides a transferable blueprint for researchers to apply ABC-SMC to complex biological systems and to progressively integrate likelihood-based methods as needed.

Abstract

Mechanistic models are essential tools across ecology, epidemiology, and the life sciences, but parameter inference remains challenging when likelihood functions are intractable. Approximate Bayesian Computation with Sequential Monte Carlo (ABC-SMC) offers a powerful likelihood-free alternative that requires only the ability to simulate data from mechanistic models. Despite its potential, many researchers remain hesitant to adopt these methods due to perceived complexity. This tutorial bridges that gap by providing a practical, example-driven introduction to ABC-SMC using Python. From predator-prey dynamics to hierarchical epidemic models, we illustrate by example how to implement, diagnose, and interpret ABC-SMC analyses. Each example builds intuition about when and why ABC-SMC works, how partial observability affects parameter identifiability, and how hierarchical structures naturally emerge in Bayesian frameworks. All code leverages PyMC's modern probabilistic programming interface, ensuring reproducibility and easy adaptation to new problems. The code its fully available for download at \href{https://github.com/mariocastro73/ABCSMC_pymc_by_example}{mariocastro73/ABCSMC\_pymc\_by\_example}

Approximate Bayesian Computation Made Easy: A Practical Guide to ABC-SMC for Dynamical Systems with \texttt{pymc}

TL;DR

This work addresses parameter inference for mechanistic dynamical models when likelihoods are intractable by presenting ABC-SMC as an accessible, likelihood-free Bayesian approach implemented in PyMC. Through four case studies—ranging from fully observed Lotka–Volterra to latent-structural SEIR with hierarchical pooling—the tutorial demonstrates practical workflow, diagnostics, and interpretation of approximate posteriors and posterior predictive checks. It emphasizes design choices (summaries, distances, tolerances), diagnostic tools (ESS, tolerance trajectories, PPCs), and strategies to leverage partial observability and information sharing across groups. By combining a practical, example-driven narrative with a unified PyMC-based interface, the paper provides a transferable blueprint for researchers to apply ABC-SMC to complex biological systems and to progressively integrate likelihood-based methods as needed.

Abstract

Mechanistic models are essential tools across ecology, epidemiology, and the life sciences, but parameter inference remains challenging when likelihood functions are intractable. Approximate Bayesian Computation with Sequential Monte Carlo (ABC-SMC) offers a powerful likelihood-free alternative that requires only the ability to simulate data from mechanistic models. Despite its potential, many researchers remain hesitant to adopt these methods due to perceived complexity. This tutorial bridges that gap by providing a practical, example-driven introduction to ABC-SMC using Python. From predator-prey dynamics to hierarchical epidemic models, we illustrate by example how to implement, diagnose, and interpret ABC-SMC analyses. Each example builds intuition about when and why ABC-SMC works, how partial observability affects parameter identifiability, and how hierarchical structures naturally emerge in Bayesian frameworks. All code leverages PyMC's modern probabilistic programming interface, ensuring reproducibility and easy adaptation to new problems. The code its fully available for download at \href{https://github.com/mariocastro73/ABCSMC_pymc_by_example}{mariocastro73/ABCSMC\_pymc\_by\_example}

Paper Structure

This paper contains 21 sections, 3 equations, 12 figures.

Figures (12)

  • Figure 1: Mechanistic Lotka--Volterra model and simulator. The function competition_model maps parameters $(a,b)$ to a simulated prey--predator trajectory evaluated at the observation times, flattened into a one-dimensional array suitable for use in pm.Simulator.
  • Figure 2: PyMC model for ABC--SMC inference in the Lotka--Volterra system. The pm.Simulator distribution wraps the ODE-based simulator and uses an initial tolerance epsilon=10.0. The call to pm.sample_smc runs the ABC--SMC algorithm and returns an InferenceData object containing the approximate posterior samples.
  • Figure 3: Posterior predictive trajectories for the Lotka--Volterra system with both species observed. The points denote the observed prey (blue) and predator (orange) time series. The thick lines show the trajectories at the posterior mean parameters, while the light curves represent simulations from randomly selected posterior samples. The close alignment between the observed data and the posterior predictive ensemble indicates that the inferred parameters provide a good description of the predator--prey dynamics.
  • Figure 4: (Left) Marginal posterior distributions of the prey growth rate $a$ and predation rate $b$ obtained by ABC--SMC. The histograms and shaded regions show the approximate posterior densities together with high-density intervals. Both parameters are well-identified, with posterior mass concentrated around the true generating values used in the synthetic data. (Right) Joint posterior distribution of $(a,b)$, visualized via kernel density estimation. The nested contours represent regions of increasing posterior probability density. The elongated shape of the contours reveals a correlation between $a$ and $b$, indicating that certain combinations of growth and predation rates are jointly plausible given the data.
  • Figure 5: Simulator for the partially observed Lotka--Volterra model. In contrast to the fully observed case (where the flattened prey--predator matrix was returned), the distance in ABC is now computed only on the prey trajectory, while the predator dynamics remain latent but constrained through the ODE system.
  • ...and 7 more figures