Abstract
Modern scientific simulators often lack a tractable likelihood, making parameter inference computationally expensive. Traditional methods like Markov Chain Monte Carlo (MCMC) or Nested Sampling are often inefficient, requiring millions of simulations and discarding valuable data. We present swyft, a framework that utilizes Nested Ratio Estimation (NRE) and an innovative iP3 sample caching system to achieve order-of-magnitude improvements in simulation efficiency. By targeting marginal posteriors directly and reusing all previous simulations, swyft enables fast, accurate inference even for complex, multi-modal distributions.
Introduction
In fields such as astrophysics and particle physics, researchers rely on complex stochastic "black-box" simulators to model physical phenomena. Parameter inference—the process of determining the posterior distribution of model parameters given observed data—is critical for scientific discovery. However, the "gold standard" MCMC requires a known likelihood function, which is often unavailable for these simulators.
Existing likelihood-free inference (LFI) techniques often struggle with high-dimensional parameter spaces or require starting from scratch for every new observation. Furthermore, traditional samplers are "wasteful," rejecting many simulation runs that do not meet specific criteria. There is a pressing need for a method that is both simulation-efficient and allows for the seamless reuse of computational effort.
Methods
The swyft framework introduces two core innovations to address these challenges:
Nested Ratio Estimation (NRE)
Instead of estimating the high-dimensional joint posterior $p(\theta | x)$, NRE focuses on low-dimensional marginal posteriors $p(\theta_i | x)$ or $p(\theta_i, \theta_j | x)$. This approach bypasses the "curse of dimensionality." Inference is framed as a binary classification task: a neural network is trained to distinguish between "joint" pairs $(\theta, x)$ drawn from the simulator and "shuffled" pairs $(\theta, x')$ where parameters and data are mismatched. The network's output can be mathematically mapped to the likelihood-to-evidence ratio, providing the necessary components for Bayesian inference. This process is performed iteratively in "rounds" to focus on high-probability regions.
iP3 Sample Caching
To eliminate redundant simulations, swyft implements an inhomogeneous Poisson point process (iP3) based caching system. This cache stores every simulator run. When the NRE algorithm requires new samples for a refined search region, it queries the cache to identify and "recycle" relevant previous runs. The expensive simulator is only invoked for parameter combinations not already represented in the cache.
Experiments and Results
The performance of swyft was evaluated against MultiNest, a standard nested sampling tool, using two benchmark problems.
3-Parameter Gaussian Simulator
In a standard inference task, swyft achieved comparable accuracy to MultiNest while requiring significantly fewer simulations (~20,000 vs. ~160,000). When tasked with a second inference run using the same simulator, the iP3 cache allowed swyft to complete the task with only ~3,700 new simulations, whereas MultiNest required a full restart of ~171,000 simulations.
The Eggbox Problem
The "Eggbox" problem features a highly multi-modal posterior, a classic challenge for samplers. As shown in Figure 2, the number of samples required by MultiNest grows exponentially with the number of modes. In contrast, swyft maintains a nearly constant simulation cost, successfully scaling to high-dimensional versions of the problem that are intractable for traditional methods.
Key Insights
- Marginals as a Shortcut: Targeting 1D or 2D marginals directly avoids the computational burden of the full joint distribution, which is often unnecessary for scientific error analysis.
- Efficiency through Reuse: By treating every simulation as a training point and utilizing a sophisticated cache,
swyftensures that no computational effort is wasted. - Scalability: The classification-based approach allows
swyftto handle complex, multi-modal posteriors with a fixed simulator budget, independent of the number of modes.
Conclusion
swyft represents a significant step forward in simulation-based inference. By combining machine learning with efficient sample management, it provides a powerful tool for researchers dealing with expensive "black-box" models. While care must be taken with extremely highly correlated parameters, the iterative nature of NRE and the ability to target higher-dimensional marginals offer robust pathways for future development. The swyft package is available as an open-source Python library.
Summary updated