Cross-Fitting for Neural Posterior Estimation

Jeffrey RegierNeurIPS 2026

TL;DR

When scientists use neural networks to infer hidden parameters from simulated data—a technique called Neural Posterior Estimation (NPE)—the networks tend to become wildly overconfident, memorizing training points and shrinking their uncertainty estimates toward zero. Standard fixes like early stopping force an ugly compromise between an underfit average prediction and an overfit uncertainty estimate. By borrowing a classic statistical trick called cross-fitting, Cross-Fitting NPE (CF-NPE) decouples predicting the center of the distribution from predicting its spread, yielding dramatically more accurate and well-calibrated scientific inferences when simulations are scarce.

What Problem Does This Paper Address?

In many corners of science—from particle physics to cosmology—we have fantastic simulators that generate fake observations $x$ from hidden parameters $z$, but no tractable math to go backward from $x$ to $z$. Neural Posterior Estimation (NPE) solves this by training a flexible neural density estimator (like a normalizing flow or Gaussian encoder) on simulated $(x, z)$ pairs to directly output the posterior probability distribution $q_\phi(z \mid x)$.

Here is the catch: NPE maximizes log-likelihood. If your network is flexible enough, it can cheat. By placing an infinitely tall, razor-thin probability spike right on top of each training point $z_i$, it can drive the training log-likelihood to infinity.

In standard neural regression, overfitting is often "benign." In conditional density estimation, it is catastrophic. Practitioners rely on early stopping to halt training before the variance collapses. However, early stopping just searches along a flawed optimization path. Because the network learns the posterior mean and spread simultaneously on the same data, as the mean prediction gets better and starts interpolating the training points, the in-sample errors (residuals) shrink artificially.

Standard NPE training trajectories showing the trade-off between conditional-mean accuracy (MSE) and posterior calibration across epochs.

As shown above, calibration steadily worsens from epoch one, while the mean prediction keeps improving for ratusan of epochs. Early stopping is trapped in a tug-of-war: stop early and your mean is underfit; stop late and your uncertainty is severely overconfident.

Methods

To break this trade-off, Jeffrey Regier introduces Cross-Fitting NPE (CF-NPE), which splits NPE into two distinct stages using $K$-fold sample splitting:

  1. Stage 1 (Find the Center): Partition the training data into $K$ folds. For each fold, train a standard neural regressor (or a small ensemble of $M$ regressors) on the other $K-1$ folds using simple Mean Squared Error (MSE) loss. Use each regressor to predict the posterior mean on its held-out fold, and subtract these predictions from the true $z$ values to get out-of-fold residuals.
  2. Stage 2 (Measure the Spread): Train a standard conditional density estimator (e.g., a zero-mean Gaussian encoder or a normalizing flow) to model the distribution of those out-of-fold residuals, conditioned on $x$ and the Stage 1 mean prediction.

At test time, you pair a Stage 1 mean predictor with the Stage 2 residual density estimator (or average across all $K$ pairs in a variant called CF-NPE-mixture). What is novel here is bringing cross-fitting—famous in econometrics—into simulation-based inference to isolate mean estimation from higher-moment estimation.

Datasets

Because NPE is a simulation-based method, datasets are generated via simulators (typically using $N = 10,000$ training pairs per run):

  • Synthetic Benchmarks: Three high-dimensional testbeds designed to stress-test density estimators: a 200D hierarchical Gaussian–Gaussian model, Neal’s pathological 200D Funnel distribution, and a 20D bimodal Mixture model.
  • Cosmological Strong Lensing: A realistic astrophysics problem using the Lenstronomy simulator. Background galaxies ($16 \times 16$ latent pixel grids drawn from a Gaussian process) are gravitationally warped by foreground dark matter halos into $64 \times 64$ observed images. Here, fast Lenstronomy runs stand in for million-core-hour hydrodynamical simulations where sample efficiency is paramount.
Strong-lensing source reconstruction showing the true unlensed galaxy, the warped observation, and posterior samples from CF-NPE-mixture.

Key Insights and Ideas

  • Out-of-fold residuals cure "in-sample optimism": Because Stage 1 never sees fold $k$ during training, the residuals on fold $k$ behave just like fresh test data. Mathematically, the expected squared out-of-fold residual equals the true posterior variance plus the regressor's error—providing a safe lower bound that prevents variance collapse.
  • Why doesn't Stage 2 just overfit again? Stage 2 is standard NPE, so why doesn't it suffer the same fate? Because the residuals are already centered near zero! A Gaussian encoder can hardcode a zero mean (guaranteeing perfect training calibration at its likelihood maximum), and normalizing flows start centered at zero via symmetric initialization, allowing early stopping to focus purely on capturing higher moments.
  • Deep ensembles fix the wrong problem: A popular alternative is averaging several standard NPE models (deep ensembles). While mixing models improves the mean estimate, it widens the overall distribution without shrinking individual component variances—swinging the pendulum from overconfident to underconfident (overdispersed).

Key Results

Calibration is measured via the reduced chi-square statistic ($\chi^2_d$), where $1.0$ is ideal, $>1$ is overconfident, and $<1$ is underconfident.

  • Sample Efficiency: On the 200D Gaussian–Gaussian problem, CF-NPE ($M=3$) trained on $10,000$ simulations achieves a higher test log-likelihood than standard NPE given $30,000$ simulations.
  • Pathological Funnel (200D): Standard NPE with a Neural Spline Flow (NSF) scores $-58.98$ nats in test log-likelihood; CF-NPE ($M=1$) leaps to $+38.09$ nats, and $+114.09$ nats with $M=10$.
  • Calibration: Across synthetic tasks, CF-NPE keeps $\chi^2_d$ within a few percent of $1.0$ (peaking at $1.15$), whereas standard NPE hits $1.51$ (overconfident) and standard NPE mixtures drop as low as $0.20$ (severely underconfident).
  • Strong Lensing: CF-NPE-mixture ($M=3$) reaches a median test log-likelihood of $88.08$ nats ($\chi^2_d = 0.997$, MSE $= 0.043$), trouncing standard NPE ($2.59$ nats, $\chi^2_d = 1.196$, MSE $= 0.124$) and a slower, 50-component standard NPE ensemble ($29.83$ nats, $\chi^2_d = 0.810$).

Limitations and Future Work

  • When you don't need it: If your simulator is fast enough to generate fresh data at every single gradient step (no multi-epoch reuse), or if your parameter space is very low-dimensional (e.g., $d=2$), standard NPE doesn't overfit the mean, and CF-NPE offers little advantage.
  • Compute cost: Training $O(K)$ networks means CF-NPE takes roughly an order of magnitude more training time when models saturate the GPU (e.g., ~1 hour vs. 7.5 minutes on the lensing task), though this is negligible when real-world simulations dominate the budget.
  • Open questions: The paper only analyzes single-round amortized NPE, leaving multi-round sequential NPE for future exploration. Furthermore, Stage 2 still estimates variance, skewness, and kurtosis jointly; extending cross-fitting to separate these higher moments—perhaps via fast approximate refitting—and developing formal calibration proofs for normalizing flows (potentially using continuous flow matching) remain exciting next steps.

Summary updated

Abstract

Neural Posterior Estimation (NPE) trains an amortized conditional density estimator to approximate posterior distributions in simulation-based inference. Each training pair is a single draw from the joint distribution of latent and observation, so posterior variance at an observation must be inferred from variation across pairs rather than within them. However, with a sufficiently flexible variational distribution, the NPE training objective is unbounded, and standard optimizers yield arbitrarily small variance. Regularizers like early stopping, dropout, and weight decay constrain network capacity without targeting the correct posterior variance. We propose Cross-Fitting NPE (CF-NPE), which separates mean estimation from higher-moment estimation via sample splitting. Concretely, CF-NPE estimates a conditional-mean ensemble by $K$-fold cross-fitting, then fits a conditional density to the resulting out-of-fold residuals. The conditional variance of an out-of-fold residual is bounded below by the true posterior variance, giving CF-NPE a well-defined population-level target that standard NPE lacks. Across eight synthetic benchmarks and a cosmological application, CF-NPE achieves higher held-out log-likelihood than standard NPE, with gains that grow with the latent dimension.
BibTeX
@inproceedings{regier2026cross,
  author = {Jeffrey Regier},
  title = {{Cross-Fitting for Neural Posterior Estimation}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=JmM3HShlbu},
}
Figure