API reference#

Prior and simulator#

sbi.utils.BoxUniform

Uniform distribution in multiple dimensions.

sbi.utils.MultipleIndependent

Wrap a sequence of PyTorch distributions into a joint PyTorch distribution.

sbi.utils.process_prior

Return PyTorch distribution-like prior from user-provided prior.

sbi.utils.process_simulator

Returns a simulator that meets the requirements for usage in sbi.

sbi.utils.RestrictedPrior

Distribution that restricts the prior distribution to a smaller region.

sbi.utils.RestrictionEstimator

Classifier to estimate regions of the prior that give good simulation results.

sbi.inference.simulate_for_sbi

Returns pairs \((\theta, x)\) by sampling proposal and running simulations.

Neural nets#

sbi.neural_nets.classifier_nn

Returns a function that builds a classifier for learning density ratios.

sbi.neural_nets.likelihood_nn

Returns a function that builds a density estimator for learning the likelihood.

sbi.neural_nets.marginal_nn

Returns a function that builds a density estimator for learning the marginal.

sbi.neural_nets.posterior_flow_nn

Build util function that builds a FlowMatchingEstimator object for flow-based posteriors.

sbi.neural_nets.posterior_nn

Returns a function that builds a density estimator for learning the posterior.

sbi.neural_nets.posterior_score_nn

Build util function that builds a ScoreEstimator object for score-based posteriors.

Embedding nets#

sbi.neural_nets.embedding_nets.CausalCNNEmbedding

Embedding network that uses 1D causal convolutions.

sbi.neural_nets.embedding_nets.CNNEmbedding

Convolutional embedding network (1D or 2D convolutions).

sbi.neural_nets.embedding_nets.FCEmbedding

Fully-connected multi-layer neural network to be used as embedding network.

sbi.neural_nets.embedding_nets.LRUEmbedding

Embedding network backed by a stack of Linear Recurrent Unit (LRU) blocks.

sbi.neural_nets.embedding_nets.PermutationInvariantEmbedding

Permutation invariant embedding network.

sbi.neural_nets.embedding_nets.ResNetEmbedding1D

Residual neural network mapping vector-like data to a fixed-size vector.

sbi.neural_nets.embedding_nets.ResNetEmbedding2D

Residual neural network mapping image-like data to a fixed sized vector.

sbi.neural_nets.embedding_nets.SpectralConvEmbedding

sbi.neural_nets.embedding_nets.TransformerEmbedding

Transformer-based embedding network for time series and image data.

Training#

sbi.inference.BNRE

Balanced Neural Ratio Estimation (BNRE) as in Delaunoy et al. (2022) [1].

sbi.inference.FMPE

Flow Matching Posterior Estimation (FMPE) [1].

sbi.inference.MarginalTrainer

Utility class for training a marginal density estimator $p(x)$.

sbi.inference.MCABC

Monte-Carlo Approximate Bayesian Computation (Rejection ABC).

sbi.inference.MNLE

Mixed Neural Likelihood Estimation for discrete and continuous data [1].

sbi.inference.MNPE

Method that can infer discrete and continuous parameters (Mixed NPE).

sbi.inference.NLE_A

Neural Likelihood Estimation (NLE) as in Papamakarios et al. (2019) [1].

sbi.inference.NPE_A

Neural Posterior Estimation algorithm as in Papamakarios et al. (2016) [1].

sbi.inference.NPE_B

Neural Posterior Estimation algorithm (NPE-B) as in Lueckmann et al. (2017) [1].

sbi.inference.NPE_C

Neural Posterior Estimation algorithm (NPE-C) as in Greenberg et al. (2019) [1].

sbi.inference.NPSE

Neural Posterior Score Estimation (NPSE) [1, 2].

sbi.inference.NRE_A

Neural Ratio Estimation (NRE-A / AALR) as in Hermans et al. (2020) [1].

sbi.inference.NRE_B

Neural Ratio Estimation (NRE-B / SRE) as in Durkan et al. (2020) [1].

sbi.inference.NRE_C

Neural Ratio Estimation (NRE-C / CNRE) as in Miller et al. (2022) [1].

sbi.inference.SMCABC

Sequential Monte Carlo Approximate Bayesian Computation.

Potentials#

sbi.inference.likelihood_estimator_based_potential

Returns potential \(\log(p(x_o|\theta)p(\theta))\) for likelihood estimator.

sbi.inference.mixed_likelihood_estimator_based_potential

Returns $log(p(x_o|theta)p(theta))$ for mixed likelihood-based methods.

sbi.inference.posterior_estimator_based_potential

Returns the potential for posterior-based methods.

sbi.inference.ratio_estimator_based_potential

Returns the potential for ratio-based methods.

sbi.inference.vector_field_estimator_based_potential

Returns the potential function gradient for vector field estimators.

Posteriors#

sbi.inference.DirectPosterior

Posterior based on neural networks that directly estimate the posterior (NPE).

sbi.inference.EnsemblePosterior

Wrapper for bundling together different posterior instances into an ensemble.

sbi.inference.ImportanceSamplingPosterior

Provides importance sampling to sample from the posterior.

sbi.inference.MCMCPosterior

Provides MCMC to sample from the posterior.

sbi.inference.RejectionPosterior

Provides rejection sampling to sample from the posterior.

sbi.inference.VectorFieldPosterior

Posterior based on flow- or score-matching estimators.

sbi.inference.VIPosterior

Provides VI (Variational Inference) to sample from the posterior.

Posterior Parameters#

sbi.inference.posteriors.DirectPosteriorParameters

Parameters for initializing DirectPosterior.

sbi.inference.posteriors.ImportanceSamplingPosteriorParameters

Parameters for initializing ImportanceSamplingPosterior.

sbi.inference.posteriors.MCMCPosteriorParameters

Parameters for initializing MCMCPosterior.

sbi.inference.posteriors.RejectionPosteriorParameters

Parameters for initializing RejectionPosterior.

sbi.inference.posteriors.VectorFieldPosteriorParameters

Parameters for initializing VectorFieldPosterior.

sbi.inference.posteriors.VIPosteriorParameters

Parameters for VIPosterior, supporting both single-x and amortized VI.

Diagnostics#

sbi.diagnostics.calc_misspecification_logprob

Perform hypothesis test to check if estimator.log_prob(x_o) is unusually low.

sbi.diagnostics.calc_misspecification_mmd

Misspecification test based on MMD in data- or embedding space.

sbi.diagnostics.check_sbc

Return uniformity checks and data-averaged posterior checks for SBC.

sbi.diagnostics.check_tarp

check the obtained TARP credibitlity levels and expected coverage probabilities.

sbi.diagnostics.get_nltp

Return negative log prob of true parameters under the posterior.

sbi.diagnostics.LC2ST

L-C2ST: Local Classifier Two-Sample Test.

sbi.diagnostics.run_sbc

Run simulation-based calibration (SBC) or expected coverage.

sbi.diagnostics.run_tarp

Estimates coverage of samples given true values thetas with the TARP method.

Analysis#

sbi.analysis.ActiveSubspace

Identify the active subspace of the posterior for sensitivity analyses.

sbi.analysis.conditional_corrcoeff

Returns the conditional correlation matrix of a distribution.

sbi.analysis.conditional_pairplot

Plot conditional distribution given all other parameters.

sbi.analysis.conditional_potential

Returns potential function that can be used to sample the conditional potential.

sbi.analysis.marginal_plot

Plot samples in a row showing 1D marginals of selected dimensions.

sbi.analysis.pairplot

Plot samples in a 2D grid showing marginals and pairwise marginals.

sbi.analysis.plot_tarp

Plots the expected coverage probability (ECP) against the credibility level,alpha, for a given alpha grid.

sbi.analysis.pp_plot

Probability - Probability (P-P) plot for hypothesis tests to assess the validity of one (or several) estimator(s).

sbi.analysis.pp_plot_lc2st

Probability - Probability (P-P) plot for LC2ST.

sbi.analysis.sbc_rank_plot

Plot simulation-based calibration ranks as empirical CDFs or histograms.

Utilities#

sbi.utils.get_density_thresholder

Returns function that thresholds a density at a particular 1-quantile.

sbi.utils.mcmc_transform

Builds a transform that is applied to parameters during MCMC.

sbi.utils.transformed_potential

Return potential after a transformation by adding the log-abs-determinant.