Simulation-based inference via sbi
Overview
Modern methods for simulation-based inference (SBI) leverage powerful and expressive density estimators, often parameterized by neural networks. These algorithms are designed to solve inference problems of the form:
\[ p(\theta \mid y) \propto p(\theta)\int_\mathcal{Z} p(y \mid z, \theta)p(z\mid\theta)dz $ where $z\]
corresponds to some set of latent variables internal to the simulator. In the context of dynamical systems, $z$ often represents the trajectory of the system state(s) over time.
In cases where $z$ is a random variable, e.g., in the presence of stochastic dynamics or model errors, obtaining numerical estimates of the posterior distribution $p(\theta \mid y)$ formally requires integrating over all possible latent states of the simulator in the likelihood, which is usually intractable. This precludes the use of most standard methods for statistical inference.
Traditionally, this problem was solved using so-called Approximate Bayesian Computation (ABC) methods which sidestep the need to compute the likelihood by simplying comparing low-dimensional summary statistics computed from the simulator outputs. More modern methods use powerful density estimation techniques to approximate the likelihood or the posterior directly. The python package sbi provides an easy-to-use interface for applying such methods to a wide variety of problems.
SimulationBasedInference.jl
provides a Julia-wrapper around sbi
via the PySBI
extension module, which is loaded using Requires.jl
. In order for PySBI
to be loaded, the PythonCall
package must be installed in your local environment.
Once PythonCall
is installed, the PySBI
module can be imported as
import PythonCall
import SimulationBasedInference.PySBI
The python module sbi
can be directly accessed via PySBI.sbi
.
The PySBI.PySNE type wraps an sbi
algorithm (by default NPE_C
) which can then be used with the standard CommonSolve
interface:
init(::SimulatorInferenceProblem, ::PySNE)
PySBI API reference
SimulationBasedInference.PySBI.PySNE
— TypePySNE <: SBI.SimulatorInferenceAlgorithm
Wrapper for the sequential neural estimator (SNxE) algorithms from the python sbi
package. algtype
should typically be one of SNPE_A
, SNPE_B
, SNPE_C
, or 'SNLE_A', though any suitable algorithm type can be used.
SimulationBasedInference.PySBI.pyprior
— Methodpyprior(prior::AbstractSimulatorPrior, approx::GaussianApproximationMethod)
Currently, it seems that torch
does not provide a generic product distribution for combining univariate distributions into a higher dimensional multivariate distribution. As a cheap workaround, we follow here the same strategy as with the ensemble Kalman methods, and we use the Bijector
s defined for each AbstractSimulatorPrior
to construct an empirical multivariate normal approximation.