---
kind: concept
slug: simulation-based-inference
title: Simulation-based inference
summary: >-
  Simulation-based inference estimates the posterior over a black-box simulator's parameters from simulated runs, without a computable likelihood. Three neural families: posterior, likelihood and ratio estimation. One toolkit card, no benchmark numbers, so no variant is shown to be more accurate.
tags: [likelihood-free-inference, density-estimation, bayesian-inference, software]
papers: ["2007.09114"]
related: [normalizing-flows, variational-inference, surrogate-modeling, uncertainty-estimation]
status: draft
updated_at: 2026-11-05
---

## Overview

A simulator maps settings to outputs, but its likelihood, the probability of an
output given the settings, cannot be written down. Simulation-based inference
(SBI) draws settings from a prior, runs the simulator on them, and learns from
the pairs which settings are consistent with an observed output. The answer is
a posterior distribution over the settings, not one best guess
[arxiv:2007.09114 §1]. The classic alternative named there is approximate
Bayesian computation, which uses Monte-Carlo rejection [arxiv:2007.09114 §1].

The shared idea of the neural variants: the learned estimator is trained on
simulated pairs, instead of a likelihood that is written down
[arxiv:2007.09114 §1] [arxiv:2007.09114 §2].

## Variants

Only one card covers this concept. It describes the `sbi` toolkit, which
implements three families [arxiv:2007.09114 §2].

### Sequential neural posterior estimation (SNPE)

Trains a density estimator that gives the posterior directly. The paper names
SNPE-C as the implemented variant [arxiv:2007.09114 §2]. Card:
[SBI -- A toolkit for simulation-based inference](/papers/2007.09114).

### Sequential neural likelihood estimation (SNLE)

Trains a density estimator of the likelihood, then samples the posterior with a
method such as MCMC [arxiv:2007.09114 §2]. Same card.

### Sequential neural ratio estimation (SNRE)

Trains a classifier that estimates density ratios, which are then used to
sample the posterior, for example with MCMC [arxiv:2007.09114 §2]. Same card.

All three return a posterior object with one sampling interface. It can be
evaluated where the method allows [arxiv:2007.09114 §2].

## When to use which

The paper reports no benchmark results, so no table below ranks the variants
on accuracy [arxiv:2007.09114 §1] [arxiv:2007.09114 §2]. Choose on the
constraints the paper does state.

| Situation | Use | Why |
|---|---|---|
| A ready PyTorch package, defaults acceptable, one call wanted | Simple interface | One function call with reasonable defaults [arxiv:2007.09114 §2] |
| Custom networks or hyperparameters needed | Flexible interface | The flexible interface allows both [arxiv:2007.09114 §2] |
| The posterior itself should be the trained object | SNPE | Trains the posterior directly [arxiv:2007.09114 §2] |
| A learned likelihood is wanted, and MCMC sampling at inference is acceptable | SNLE | Samples the posterior with MCMC after training the likelihood [arxiv:2007.09114 §2] |
| A classifier is preferred to a density model | SNRE | Trains a ratio classifier, then samples with MCMC [arxiv:2007.09114 §2] |
| Accuracy of one variant over another must be justified | None from this concept | No benchmark numbers in the paper [arxiv:2007.09114 §1] [arxiv:2007.09114 §2] |

Two caveats from the card's review of the code [the card](/papers/2007.09114):

- The simple interface returns a posterior that is amortized: one training run
  serves any observed output. The paper does not explain what this means for
  accuracy [arxiv:2007.09114 §2].
- The code is much newer than the 2020 paper. Method names and defaults have
  changed, so pin a commit before copying any value.

## Implementation sketch

Language-agnostic pseudocode of the common core. It follows the paper's
description; the round-by-round procedure of the sequential variants is not
reproduced here.

```pseudocode
# Common core of neural SBI  [arxiv:2007.09114 §2]
# Input:  simulator (theta -> x), prior with sample() and log_prob()
# Output: posterior p(theta | x_obs), sampled for an observed x_obs

# 1. Draw parameters from the prior and run the simulator on each
theta = prior.sample(N)
x = simulator(theta)

# 2. Drop failed simulations (NaN or Inf) when the method excludes them
theta, x = keep_valid(theta, x)

# 3. Train one neural estimator on the simulated pairs
#    SNPE: posterior density   SNLE: likelihood density
#    SNRE: density ratio (classifier)
estimator = train(theta, x, kind)

# 4. Wrap the estimator as a posterior and sample for the observation
posterior = build_posterior(estimator, prior)
samples = posterior.sample(x_obs)
```

## Contradictions

- **Licence.** The paper's footnote states AGPLv3 [arxiv:2007.09114 p. 1]. The
  card records Apache-2.0 for the code it cites, and does not check the licence
  of the 2020 release [the card](/papers/2007.09114). Not resolved here.
- **Names.** The paper names SNPE-C, SNLE and SNRE [arxiv:2007.09114 §2]. The
  code's trainer names differ, and the card's mapping between them is inferred
  from names [the card](/papers/2007.09114).

## Papers

- [SBI -- A toolkit for simulation-based inference](/papers/2007.09114): a
  PyTorch toolkit with SNPE, SNLE and SNRE behind a simple and a flexible
  interface; reports no benchmark numbers.
