PyVBMC: Efficient Bayesian inference in Python

Bobby Huggins, Chengkun Li, Marlon Tobaben, Mikko J. Aarnos, Luigi AcerbiJ. Open Source Softw 2023 · DBLP

Abstract

PyVBMC is a new Python library designed for efficient Bayesian inference on "black-box" computational models that are expensive to evaluate or lack gradient information. By combining Gaussian Process surrogates with variational inference, it achieves 1–2 orders of magnitude speedup over traditional methods like MCMC, often requiring only a few hundred model evaluations.

Introduction

In many scientific fields—from neuroscience to nuclear engineering—researchers work with complex simulators where a single run might take seconds or minutes. Performing Bayesian inference (estimating model parameters and their uncertainty) on these models is notoriously difficult. Standard tools like Markov Chain Monte Carlo (MCMC) typically require tens of thousands of model evaluations, which is computationally prohibitive for slow models. Other methods, like traditional Variational Inference, often require the model to be differentiable, which isn't possible for many "black-box" simulators. PyVBMC addresses this gap by providing a sample-efficient, gradient-free framework for models with up to roughly 15 continuous parameters.

Methods

PyVBMC implements the Variational Bayesian Monte Carlo (VBMC) algorithm. Its core innovation is a "dual-approximation" strategy:

  1. Gaussian Process (GP) Surrogate: It builds a GP model to mimic the (unnormalized) log posterior density. This surrogate is updated iteratively using active sampling, where the algorithm intelligently chooses new points to evaluate based on where it is most uncertain about the posterior's shape.
  2. Variational Approximation: Simultaneously, it fits an expressive mixture of Gaussian distributions to the GP surrogate.

Because the variational approximation is fit to the surrogate rather than the expensive true model, it is computationally cheap to optimize. The algorithm uses Bayesian Quadrature to efficiently estimate the Evidence Lower Bound (ELBO), providing both a tractable posterior distribution and an estimate of the model evidence (marginal likelihood) for model selection.

Key Insights and Results

PyVBMC's active learning approach is designed to map the entire shape of the posterior distribution, rather than just finding a single maximum. This is particularly useful for complex, non-Gaussian distributions.

PyVBMC captures complex, non-Gaussian posterior shapes such as this 'banana' distribution through its expressive variational approximation.

The library also includes robust "integrated acquisition functions" to handle stochastic simulators that return noisy likelihoods. By fitting a Gaussian mixture to the GP surrogate, PyVBMC provides users with a final object that is easy to visualize, manipulate, and sample from.

In terms of performance, PyVBMC typically requires only a few hundred likelihood evaluations, compared to the tens of thousands required by MCMC or nested sampling. This leads to dramatic speed-ups of 1–2 orders of magnitude when model evaluations take more than a second.

A corner plot illustrating the joint and marginal posterior distributions estimated by PyVBMC, demonstrating its ability to provide a complete picture of parameter uncertainty.

Limitations and Future Work

The method is currently limited to models with a relatively small number of continuous parameters (roughly 10–15) and does not directly support discrete parameters. While the MATLAB version has seen success in niche fields, PyVBMC aims to bring these capabilities to the broader open-source Python community, with ongoing efforts to expand tutorials and documentation for diverse scientific applications.

Summary updated

BibTeX
@article{huggins2023pyvbmc,
  author = {Bobby Huggins and Chengkun Li and Marlon Tobaben and Mikko J. Aarnos and Luigi Acerbi},
  title = {{PyVBMC: Efficient Bayesian inference in Python}},
  journal = {J. Open Source Softw.},
  year = {2023},
  doi = {10.21105/joss.05428},
}
Figure