Contrastive Neural Ratio Estimation for Simulation-based Inference

Benjamin Kurt Miller, Christoph Weniger, Patrick Forré

TL;DR

This paper introduces Contrastive Neural Ratio Estimation (NRE-C), a generalized framework for simulation-based inference that eliminates a critical bias inherent in previous multiclass methods. By adding a single "independent" class to the classification objective, NRE-C enables reliable diagnostic testing and achieves superior posterior accuracy by exploring a previously overlooked region of hyperparameter space.

What Problem Does This Paper Address?

In many scientific fields, we have complex simulators (e.g., for exoplanet orbits or disease outbreaks) that can generate data $x$ from parameters $\theta$, but they don't provide an explicit likelihood function $p(x|\theta)$. Simulation-based inference (SBI) aims to estimate the posterior $p(\theta|x)$ using only these simulations.

A popular approach is Neural Ratio Estimation (NRE), which trains a neural network to distinguish between "correct" $(\theta, x)$ pairs (drawn from the joint distribution) and "incorrect" pairs.

  • NRE-A uses binary classification.
  • NRE-B uses multiclass classification to identify which of $K$ parameter sets generated a specific observation.

While NRE-B is often more simulation-efficient, it suffers from an intrinsic, unknown bias term $c_w(x)$ at its optimum. This bias makes it impossible to use standard diagnostics—like importance sampling tests—that practitioners rely on to know if their inferred posteriors are actually trustworthy.

Methods

The authors propose NRE-C, which bridges the gap between binary and multiclass approaches. The key innovation is adding an additional "class 0" to the multiclass task, representing the case where the observation $x$ and all $K$ parameter sets in a batch are drawn independently.

Schematic of the NRE-C loss function compared to NRE-A and NRE-B.

As shown in Figure 2 above, NRE-C introduces two main hyperparameters:

  1. $K$: The number of contrastive parameter candidates.
  2. $\gamma$: The odds of a pair being drawn dependently versus independently.

Mathematically, NRE-C recovers NRE-A when $\gamma=1, K=1$ and approaches NRE-B as $\gamma \to \infty$. Crucially, for any finite $\gamma$, the optimal classifier in NRE-C is unbiased, meaning the learned ratio directly approximates the true likelihood-to-evidence ratio without the problematic $c_w(x)$ term.

Datasets

The authors evaluated their method using the standard SBI benchmark (sbibm), focusing on three primary tasks for hyperparameter grid searches:

  • SLCP: A task with a simple likelihood but a complex, non-spherical posterior.
  • Two Moons: A classic 2D benchmark with a crescent-shaped, bimodal posterior.
  • Gaussian Mixture: A task involving a mixture of two normal distributions with very different covariances.

They also performed the full sbibm benchmark across 10 different inference tasks to compare against a wide array of existing SBI algorithms.

Key Insights and Ideas

  • The "Bias-Free" Sweet Spot: The most surprising finding is that the best performance doesn't happen at the extremes (NRE-A or NRE-B). Instead, it occurs in a "middle ground" where $K > 1$ and $\gamma \approx 1$.
  • Generalization is Power: By framing NRE as a continuum (Figure 1), the authors show that previous methods were just specific corners of a much larger, more capable hyperparameter plane.
Figure 1: Conceptual, interpolated map from in- vestigated hyperparameters of proposed algorithm NRE-C to a measurement of posterior exactness using the Classifier Two-Sample Test. Best 0.5, worst 1.0. Red dot indicates NRE-A’s hyperparam- eters, γ = 1 and K = 1 [30]. Purple line implies NRE-B [16] with γ = ∞and K ≥1. NRE-C cov- ers the entire plane, generalizing other methods. Best performance occurs with K > 1 and γ ≈1, in contrast with the settings of existing algorithms.
  • Restoring Trust: Because NRE-C is unbiased, it passes the importance sampling diagnostic. This test checks if the learned ratio can successfully reweight marginal samples to look like the likelihood. NRE-B fails this test even when it produces a seemingly accurate posterior, creating a "trust gap" that NRE-C closes.
  • Mutual Information as a Metric: The authors propose using variational bounds on mutual information ($I_w^{(0)}$ and $I_w^{(1)}$) as performance metrics. These are valuable because they can be calculated without knowing the ground-truth posterior, making them practical for real-world scientific problems.

Key Results

  • Superior Accuracy: In the sbibm benchmark, NRE-C outperformed NRE-B across all simulation budgets ($10^3, 10^4, 10^5$ simulations). For example, at a $10^5$ budget, NRE-C achieved an average C2ST score of 0.705, compared to 0.762 for amortized NRE-B.
  • Diagnostic Success: Figure 3 in the paper demonstrates that while both NRE-B and NRE-C can produce visually similar posteriors, only NRE-C produces a ratio that passes the ROC-based importance sampling diagnostic.
  • Hyperparameter Recommendation: Based on extensive testing, the authors recommend setting $K$ as large as computationally feasible (e.g., half the batch size) and $\gamma \approx 1$ for the best balance of accuracy and convergence speed.

Limitations and Future Work

  • Partition Function Costs: Calculating the proposed mutual information bounds requires estimating the partition function, which can be computationally expensive and introduces its own small estimation bias.
  • Sequential Inference: While NRE-C works excellently for amortized inference (learning a global surrogate), the authors note that it isn't yet "trivially applicable" to sequential versions of methods like NPE, which focus on a specific observation.
  • Architecture Sensitivity: The paper notes that as $K$ and $\gamma$ increase, the demands on the neural network's capacity also increase, suggesting that larger architectures might be needed to fully unlock the potential of high-$K$ NRE-C.

Summary updated

Abstract

Likelihood-to-evidence ratio estimation is usually cast as either a binary (NRE-A) or a multiclass (NRE-B) classification task. In contrast to the binary classification framework, the current formulation of the multiclass version has an intrinsic and unknown bias term, making otherwise informative diagnostics unreliable. We propose a multiclass framework free from the bias inherent to NRE-B at optimum, leaving us in the position to run diagnostics that practitioners depend on. It also recovers NRE-A in one corner case and NRE-B in the limiting case. For fair comparison, we benchmark the behavior of all algorithms in both familiar and novel training regimes: when jointly drawn data is unlimited, when data is fixed but prior draws are unlimited, and in the commonplace fixed data and parameters setting. Our investigations reveal that the highest performing models are distant from the competitors (NRE-A, NRE-B) in hyperparameter space. We make a recommendation for hyperparameters distinct from the previous models. We suggest two bounds on the mutual information as performance metrics for simulation-based inference methods, without the need for posterior samples, and provide experimental results. This version corrects a minor implementation error in $γ$, improving results.
BibTeX
@inproceedings{miller2022contrastive,
  author = {Benjamin Kurt Miller and Christoph Weniger and Patrick Forré},
  title = {{Contrastive Neural Ratio Estimation for Simulation-based Inference}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
  url = {https://openreview.net/forum?id=kOIaB1hzaLe},
}
Figure