arXiv:2610.26733cs.LGOct 2026

Manuscript Offprint

arXiv:2610.26733

Cross-Fitting for Neural Posterior Estimation

Jeffrey Regier

Abstract

Neural Posterior Estimation (NPE) fits an amortized conditional density estimator to a simulated training set of complete-data realizations. NPE's training objective, log-likelihood, favors posterior approximations that assign arbitrarily high density to the training points, and typical families of amortized conditional density estimators (e.g., normalizing flows, Gaussian encoders) are flexible enough to oblige. The resulting policy of extreme overconfidence translates poorly to held-out data. Early stopping and other regularizers can prevent this degeneracy, but they are limited to selecting posterior approximations along an unfavorable optimization trajectory set by in-sample residuals, where the posterior mean is underfit while the posterior variance is overfit. To avoid this trade-off, we propose Cross-Fitting NPE (CF-NPE), which uses sample splitting to separate conditional-mean estimation from the estimation of the posterior's higher moments. Using K-fold cross-fitting, CF-NPE fits K posterior-mean regressors and then fits a conditional density estimator to the resulting out-of-fold residuals. In experiments with synthetic data and in a cosmological application, CF-NPE achieves higher held-out log-likelihood than standard NPE and typically improves calibration. CF-NPE is most useful in high-dimensional, simulation-limited settings.

1 Introduction

Neural Posterior Estimation (NPE) is a widely used method of simulation-based inference [Papamakarios and Murray, 2016, Greenberg et al., 2019]. Given a prior p(z)p(\mathbf{z}) and a simulator p(x∣z)p(\mathbf{x} \mid \mathbf{z}) from which samples can be drawn, NPE trains an amortized conditional density estimator qϕ(z∣x)q_{\phi}(\mathbf{z} \mid \mathbf{x}) with parameters ϕ\phi to approximate the posterior. During training, NPE maximizes the log-likelihood:

L^(ϕ)=1N∑i=1Nlog⁡qϕ(zi∣xi),\hat{\mathcal{L}}(\phi)=\frac{1}{N}\sum_{i=1}^{N}\log q_{\phi}(\mathbf{z}_{i}\mid\mathbf{x}_{i}),

where {(xi,zi)}i=1N\{(\mathbf{x}_i, \mathbf{z}_i)\}_{i=1}^N are independent samples from the joint distribution p(x,z)p(\mathbf{x}, \mathbf{z}).

The amortized conditional density estimator qϕq_{\phi} is often taken to be a Gaussian encoder or a normalizing flow [Papamakarios et al., 2021]. The approximators typically used, including these two, are sufficiently flexible that, without regularity conditions on the approximating family Q={qϕ}\mathcal{Q} = \{q_{\phi}\}, the NPE training objective is unbounded above: at each training input xi\mathbf{x}_i, the fitted conditional density can place arbitrarily high density near zi\mathbf{z}_i, making the empirical log-likelihood arbitrarily large. Thus, very different predicted variances can achieve the same training log-likelihood, and the posterior approximation selected is determined by the regularity conditions.

The necessity of regularizers to prevent degeneracy is not unique to NPE. The unbounded-likelihood problem for densities concentrated on observations is well known [Kiefer and Wolfowitz, 1956,

Preprint.

Test trajectory

Early stopping

MSE endpoint

--- Perfect calibration

(a) Conditional-mean accuracy

Figure

(b) Posterior calibration

Figure

Figure 1: Raw per-epoch training trajectories for standard NPE (three width-256 hidden layers) on the Gaussian–Gaussian problem ( d=dx=200d = d_x = 200, N=10,000N = 10,000), shown for one seed. Left: held-out mean squared error (MSE) to the analytic posterior mean. Right: χd2(q;P)\chi_d^2(q; P) over a test set, with the expectation over z∣xz \mid x evaluated analytically and averaged over 10,000 fixed test inputs.

Sec. 6]. In regression, without regularity conditions, the training data can be perfectly interpolated by regressors that perform arbitrarily poorly on held-out data.

However, for regression with neural networks, the network architecture and the optimization path of stochastic first-order optimizers act as powerful regularizers; overfitting by neural networks is “benign” or “tempered” rather than “catastrophic,” in the taxonomy of Mallinar et al. [2022]. Early stopping is still useful, but it is not what stands in the way of catastrophic validation performance.

Neural conditional density estimation is different. In NPE, overfitting is better described as catastrophic than as benign or tempered. With a Gaussian encoder, for example, finite network capacity does not prevent setting standard deviations to the smallest positive value that floating-point numbers can represent. Early stopping is left to prevent degeneracy, and thus to set the scale of the posterior approximation.

But will early stopping recover the correct posterior scale? Early stopping effectively performs a one-dimensional search along the optimizer's trajectory, identifying the epoch with the best validation-set performance. Given that the search space is restricted to this trajectory, this is a reasonable policy: maximizing validation-set log-likelihood minimizes the KL divergence from the posterior to its approximation (that is, the forward KL divergence), averaged over simulated data realizations [Ambrogioni et al., 2019].

However, the optimizer’s trajectory is an unfortunate space to search for a good approximation of the posterior. This trajectory is produced by fitting the posterior mean and scale simultaneously to the same training pairs. Because fitting the mean reduces its in-sample residuals, those residuals underestimate held-out residual error for the fitted mean. As the mean function comes to perfectly interpolate the data points, the residuals, and therefore the fitted variance, approach zero.

Figure 1 illustrates the shortcomings of this search space for a particular NPE training run. We quantify posterior calibration with the reduced chi-square statistic:

χd2(q;P):=EP[1d∑ℓ=1d(zℓ−μq,ℓ(x))2σq,ℓ2(x)],(1)\chi_{d}^{2}(q;P):=\mathbb{E}_{P}\left[\frac{1}{d}\sum_{\ell=1}^{d}\frac{(\mathbf{z}_{\ell}-\boldsymbol{\mu}_{q,\ell}(\mathbf{x}))^{2}}{\sigma_{q,\ell}^{2}(\mathbf{x})}\right], \tag{1}

where dd is the dimension of the latent space, qq is the fitted posterior approximation with conditional mean μq(x):=Eq[z∣x]\boldsymbol{\mu}_q(\mathbf{x}) := \mathbb{E}_q[\mathbf{z} \mid \mathbf{x}] and coordinate-wise variances σq,ℓ2(x):=Varq(zℓ∣x)\sigma_{q,\ell}^2(\mathbf{x}) := \mathrm{Var}_q(\mathbf{z}_\ell \mid \mathbf{x}), and PP is a generic distribution over pairs (x,z)(\mathbf{x}, \mathbf{z}). The reduced chi-square equals one when the fitted variances match the squared errors about the fitted mean under PP. Here we take PP to be the empirical distribution of a held-out test set.

In Figure 1, posterior mean estimation improves for 337 epochs before overfitting dominates (left panel), whereas posterior calibration steadily worsens across epochs (right panel), as the posterior spread is trained in-sample with increasingly overfit means. Early stopping (based on validation log-likelihood) trades off between mean estimation and calibration, selecting epoch 278, which is optimal for both validation- and test-set log-likelihood given the search space. However, the MSE endpoint line (left panel) shows that substantially better posterior mean estimation is possible. The MSE endpoint is the held-out MSE of a network with a similar architecture trained to minimize MSE. It is lower than the NPE trajectory's MSE not only at epoch 278 but also at its minimum, epoch 337. The MSE endpoint benefits from benign overfitting, with early stopping responding solely to the quality of conditional mean estimation.

To avoid the trade-off NPE faces between the accurate estimation of the posterior's first and second moments, we propose Cross-Fitting NPE (CF-NPE). CF-NPE fits the conditional mean and residual density in separate stages using K-fold cross-fitting ( §3\S3). Stage 1 partitions the data into K folds and trains K posterior-mean regressors, each with a different fold held out. These regressors produce out-of-fold residuals, and stage 2 fits the conditional distribution of these residuals.

On three high-dimensional synthetic inference problems, CF-NPE achieves higher test log-likelihood than standard NPE ( §4\S4). Its posterior calibration, assessed by χd2\chi_{d}^{2}, is within a few percent of one in every case except one, where it is 1.15, whereas standard NPE's is as high as 1.51. On a strong-gravitational-lensing source-reconstruction problem, CF-NPE achieves higher test log-likelihood than standard NPE and compute-matched standard NPE mixtures ( §5\S5).

CF-NPE is most beneficial when the simulator is computationally expensive and the latent space dimension is high. If the simulator is cheap enough to draw fresh pairs at every optimizer step, the deficiency of standard NPE motivating this work is not exercised ( §6\S6).

References (55)