Neural Ratio Estimation

Summary

Neural ratio estimation (NRE) converts Bayesian inference for a simulator into binary classification. Train a classifier to tell dependent pairs from independent pairs ; the optimal classifier’s logit is the log likelihood-to-evidence ratio , so . MCMC needs only likelihood ratios between consecutive states, so drops straight into Metropolis-Hastings or HMC without ever evaluating a density. Hermans, Begy & Louppe (2020) call this AALR-MCMC. No density estimator, no invertibility constraint, no normalizing constant: just a well-calibrated classifier.

Overview

Cranmer, Brehmer & Louppe (2020, Sec. 3.B) describe the idea as a relative of the GAN discriminator: “a classifier is trained using supervised learning to discriminate two sets of data, though in this case both sets come from the simulator and are generated for different parameter points and . The classifier output function can be converted into an approximation of the likelihood ratio between and !” They call this “manifestation of the Neyman-Pearson lemma in a machine learning setting” the likelihood ratio trick, and they recommend it whenever sampling synthetic data from the surrogate is not needed, because “estimating the likelihood ratio through a classifier is an example of supervised learning and often a simpler task” than density estimation.

The reason a ratio is enough (Hermans et al., Sec. 2.1): the Metropolis-Hastings acceptance probability for a move is

in which the evidence cancels and the intractable likelihood enters only through .

Main Content

The likelihood ratio trick (Hermans et al., Sec. 2.2) ^thm-lr-trick

Train a classifier to separate (label 1) from (label 0). The optimal decision function is

Parameterizing the classifier by and fixing a reference hypothesis gives a likelihood-to-reference ratio , from which any pairwise ratio follows as .

Why the reference hypothesis fails. Hermans et al. (Sec. 3.1) report that “simply relying on the amortized likelihood-to-reference ratio estimator does not yield satisfactory results, even when considering simple toy problems.” If an observation has negligible density under both and there is no training data there, so “the ratio can take on an arbitrary value”: many decision functions minimize the loss equally well (their Fig. 2). becomes “a sensitive hyper-parameter which requires careful tuning.”

Likelihood-to-evidence ratio estimator (Hermans et al., Sec. 3.1) ^def-lte-ratio

Train to distinguish dependent pairs with label from independent pairs with label . The optimal classifier and the induced ratio are

The ratio “will always be defined everywhere it needs to be evaluated, as the joint is consistently supported by the product of marginals.” The posterior density follows directly: .

Training (Hermans et al., Algorithm 1)

Repeat until converged, with batch size and criterion (binary cross-entropy):

  1. sample ;
  2. sample ;
  3. simulate ;
  4. ;
  5. .

The “independent” class costs no extra simulations: it is the same re-paired with a fresh (or shuffled) .

Numerical stability. In the saturating regime where the classifier separates the classes almost perfectly, is unstable. The fix is to take ” from the neural network before applying the sigmoidal projection in the output layer, since is the logit of ”, which also prevents vanishing gradients when computing .

Likelihood-free MCMC

  • Metropolis-Hastings. Replace the likelihood ratio in by ; “the algorithm remains otherwise unchanged.”
  • Hamiltonian Monte Carlo. With potential , the energy difference is and the force is recoverable from a differentiable classifier, since (the evidence does not depend on ). Cost: a backward pass through the ratio network per leapfrog step. See HMC and Stan in Practice.

The method is amortized: “once the likelihood ratio estimator is trained, it is possible to run MCMC for any ” (Lueckmann et al. 2021, App. A.7). Since is constant in , is proportional to the likelihood, so a different prior can be applied at inference time as without retraining; the practical limit is that the classifier is only trustworthy where the training prior put mass.

ROC diagnostic (Hermans et al., Sec. 3.2) ^ex-roc-diagnostic

An exact ratio satisfies the identity . So draw , reweight by , and train a second classifier to distinguish the reweighted marginal from fresh simulations at . “A diagonal ROC (AUC = 0.5) curve indicates that a classifier is insensitive and ”; with the caveat that the same result arises “if the classifier is not powerful enough to extract any predictive features.” The paper reports AUC = 0.58 on the tractable SLCP-style problem, 0.5 on detector calibration and M/G/1, and 0.55 on Lotka-Volterra. This is a classifier two-sample test applied to the surrogate, cousin of the C2ST metric in Benchmarking and Diagnosing SBI (SBC, Coverage, C2ST).

Multi-class generalization and SNRE

Durkan et al. (2020), as summarized in Dyer et al. (2022, Sec. 3.3.2) and Lueckmann et al. (2021, App. A.7), recast the task as picking the one correct out of a contrasting set of size for a given ; the network then learns . This shows the AALR loss “is closely related to the atomic SNPE-C/APT approach” and that both fit one contrastive framework. The benchmark used this variant with , a ResNet classifier (two hidden layers of 50 units), and slice sampling with 100 chains.

Sequential NRE (Lueckmann et al. 2021, Algorithm 8) replaces the prior by a proposal sampled by MCMC from the previous round’s estimate, with positives from and negatives from . “Exact posterior evaluation is not possible anymore, but samples can be obtained as before via MCMC”, “at the cost of needing to train new classifiers for different .”

Predecessors

CARL (Cranmer et al. 2015) learns likelihood ratios against a reference for frequentist tests. LFIRE (Dutta et al. 2016) estimates a likelihood-to-evidence ratio by logistic regression on summary statistics but “requires retraining for every evaluation of different ”; AALR trains one amortized classifier. Classifier ABC (Gutmann et al.) uses classification accuracy as the ABC discrepancy itself.

Examples

A 1-D sanity check. Let and , so and the exact log ratio is

A small MLP on inputs trained by Algorithm 1 should reproduce this quadratic surface in its logit. Then is, up to a constant, : the conjugate posterior recovered with no density model at all.

# one NRE training step (binary cross-entropy on logits)
theta   = prior.sample((M,))
x       = simulate(theta)
theta_p = theta[torch.randperm(M)]                 # break the pairing -> p(x)p(theta)
logit_j = net(x, theta)                            # log r_hat on dependent pairs
logit_m = net(x, theta_p)                          # log r_hat on independent pairs
loss    = bce_with_logits(logit_j, ones) + bce_with_logits(logit_m, zeros)
 
# likelihood-free MH acceptance at observation x_o
log_alpha = (net(x_o, th_new) + prior.log_prob(th_new)) - (net(x_o, th_old) + prior.log_prob(th_old))

Connections

See Also