Abstract
The sbi package is a flexible, PyTorch-based toolkit designed to perform Bayesian inference on complex, "black-box" simulators where traditional likelihood evaluations are impossible. By leveraging state-of-the-art neural networks, it allows scientists and engineers to align their simulation models with real-world empirical data efficiently, without needing gradients or explicit likelihood functions.
Introduction
In many scientific and engineering fields, researchers use complex stochastic simulators to model real-world phenomena. To make these models useful, their underlying parameters must be tuned so that the simulator's output matches actual empirical observations—a classic use case for Bayesian inference. However, traditional Bayesian methods, such as Markov-Chain Monte Carlo (MCMC), rely on evaluating a "likelihood function" to determine how probable an observation is given a set of parameters. For many modern simulators, this likelihood function is mathematically intractable; while one can generate simulated samples, calculating their exact probabilities is impossible. Furthermore, simulators are often slow to run and non-differentiable, precluding gradient-based inference methods.
Simulation-based inference (SBI) addresses these challenges by using machine learning to deduce the relationship between parameters and outputs directly from simulated data. This paper introduces the updated sbi toolkit, a comprehensive, user-friendly software ecosystem for applying advanced neural network-based SBI algorithms.
Simulation-Based Inference Methods
The sbi toolkit implements a wide array of neural network-based SBI algorithms, treating the user's simulator entirely as a "black box." The core methods include:
- Neural Posterior Estimation (NPE): Directly estimates the posterior distribution of the parameters.
- Neural Likelihood Estimation (NLE): Learns a surrogate model of the intractable likelihood function.
- Neural Ratio Estimation (NRE): Estimates the likelihood-to-evidence ratio to perform inference.
These methods support both amortized inference—where a network is trained once on a large dataset to perform instant inference on any new observation—and sequential inference, which focuses simulations actively on a single specific observation to optimize computational resource usage.
The sbi Toolkit Ecosystem
The sbi package is designed to be both flexible for researchers and accessible for domain scientists. It supports cutting-edge density estimators, including normalizing flows, diffusion models, mixture density networks, and flow matching. Additionally, it provides embedding networks (such as CNNs) to automatically extract summary statistics from high-dimensional simulation outputs.
As shown in the workflow above, the toolkit covers the entire pipeline from simulator integration to final analysis. Key technical features include:
- Decoupling the Simulator: Unlike probabilistic programming languages that require simulators to be written in specific differentiable frameworks,
sbionly requires inputs (parameters) and outputs (simulated data). This allows for the use of legacy simulators written in C++, Fortran, or other languages. - Sampling and Diagnostics: Once trained, models can be sampled using MCMC, variational inference, or rejection sampling. The toolkit includes robust diagnostic tools like Simulation-Based Calibration (SBC) and expected coverage to ensure inference results are trustworthy.
- Balancing Flexibility and Usability:
sbiprovides highly optimized, pre-configured defaults for all inference methods while exposing low-level APIs to customize training loops, neural architectures, and sampling strategies.
Impact and Conclusion
Since its initial release, the sbi package has become a staple in the machine learning research community, fostering the application of SBI across diverse fields such as neuroscience, astrophysics, and computational biology. The recent expansion of the toolkit includes support for diffusion models, flow-matching, truncated priors, and advanced posterior diagnostics. By lowering the barrier to entry for Bayesian inference, sbi encourages collaboration between machine learning researchers and applied scientists dealing with complex, intractable models.
Summary updated