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):
- sample ;
- sample ;
- simulate ;
- ;
- .
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
- Neural Simulation-Based Inference - Overview - NRE is the “amortized likelihood ratio” panel (Fig. 3g) of the Cranmer et al. taxonomy.
- Neural Likelihood Estimation and Sequential Neural Likelihood - “AALR-MCMC mirrors SNL as the trained conditional density estimator is plugged into MCMC samplers”; unlike SNL, a ratio cannot generate synthetic data but can evaluate the posterior density directly.
- Neural Posterior Estimation (NPE) - the multi-class NRE loss and SNPE-C are two faces of one contrastive objective.
- MCMC Basics - the acceptance ratio that makes a ratio sufficient.
- Likelihood-Free ACE and Gradient Estimation - for implicit models in experimental design, Foster et al. train an unnormalized likelihood approximation inside a contrastive bound, the same “you only need the likelihood up to a -free factor” insight. The log ratio that NRE learns is the pointwise mutual information whose expectation is the expected information gain.
- Approximate Bayesian Computation for ABMs - ABC “does not lend itself to frequentist inference”; a learned ratio does, via likelihood-ratio tests.
See Also
- Amortized vs Sequential Inference - NRE amortizes the network but not the MCMC.
- Neural SBI for Agent-Based and Economic Models - NRE with recurrent embedding networks on economic ABMs, motivated as a discriminative alternative to modelling time series generatively.
- Implicit Likelihood Estimator - the density-estimation alternative in the design setting.
- Simulation-Based and Amortized Inference - workflow-level context.