Skip to main content
Sandbox Physics
Trusting posteriors learned from simulations

Finding a wrong simulator with importance weights and residuals

Sandbox Physics ·

Calibration on simulations tests a neural posterior against its simulator, not the simulator against the data. Two further checks fill part of that gap. Importance weights compare the network with the exact posterior of the assumed model on the one record you have, so they catch a network that is out of its depth. A residual test asks whether the data minus the best-fit signal looks like the assumed noise, so it catches some ways the model itself is wrong. An unmodelled signal that the fit can absorb by shifting its parameters passes both.

This chapter follows checking posterior calibration with ranks and coverage. It adds expectation values under a change of distribution, the chi-square distribution and a first-order Taylor expansion. The Lab's model is defined first, because every number below comes from it.

The teaching model

The record is synthetic whitened strain: 128 samples dkd_k at times tk=k/(4096 Hz)t_k=k/(4096\,\mathrm{Hz}), covering 31.25 ms31.25\,\mathrm{ms}. The assumed signal is one damped sinusoid with fixed amplitude and phase,

hk(f,τ)=A e−tk/τcos⁡(2πftk+φ),A=1,  φ=0,h_k(f,\tau)=A\,\mathrm e^{-t_k/\tau}\cos(2\pi f t_k+\varphi),\qquad A=1,\;\varphi=0,

with frequency ff uniform on 200200 to 300 Hz300\,\mathrm{Hz} and damping time τ\tau uniform on 22 to 10 ms10\,\mathrm{ms}. This is the convention of Berti, Cardoso and Will, whose quality factor Q=πfτQ=\pi f\tau is about 4.74.7 at the Lab's default source of 250 Hz250\,\mathrm{Hz} and 6 ms6\,\mathrm{ms}. Berti, Cardoso and Will, 2006, Section II The assumed noise is white and Gaussian with known standard deviation σ\sigma per sample, so

ln⁡p(d∣f,τ)=−12σ2∑k=0127[dk−hk(f,τ)]2+const.\ln p(d\mid f,\tau)=-\frac{1}{2\sigma^2}\sum_{k=0}^{127}\bigl[d_k-h_k(f,\tau)\bigr]^2+\text{const}.

The amplitude and noise are in the same whitened units. At σ=0.2\sigma=0.2 the default signal has an optimal signal-to-noise ratio ∑khk2/σ≃13.0\sqrt{\textstyle\sum_k h_k^2}/\sigma\simeq13.0. The network was trained only on records drawn from this model with σ\sigma between 0.150.15 and 0.60.6.

Importance weights compare the network with the exact posterior

Let q(θ∣d)q(\theta\mid d) be the network's posterior for θ=(f,τ)\theta=(f,\tau) and π(θ)\pi(\theta) the prior. Any expectation under the exact posterior can be written as an expectation under qq:

Ep[g]=∫g(θ) π(θ) p(d∣θ) dθ∫π(θ) p(d∣θ) dθ=Eq[g w]Eq[w],w(θ)=π(θ) p(d∣θ)q(θ∣d).\mathbb E_{p}[g]=\frac{\int g(\theta)\,\pi(\theta)\,p(d\mid\theta)\,\mathrm d\theta}{\int\pi(\theta)\,p(d\mid\theta)\,\mathrm d\theta} =\frac{\mathbb E_{q}[g\,w]}{\mathbb E_{q}[w]},\qquad w(\theta)=\frac{\pi(\theta)\,p(d\mid\theta)}{q(\theta\mid d)} .

Draw nn samples θi\theta_i from the network, compute each weight wiw_i and replace the expectations by averages. When qq equals the exact posterior, every weight equals the same number p(d)p(d). When qq misses part of the posterior, a few samples in the missed region carry huge weights. The sample efficiency

ϵ=(∑iwi)2n∑iwi2\epsilon=\frac{\bigl(\sum_i w_i\bigr)^2}{n\sum_i w_i^2}

measures this: it is one for equal weights and close to 1/n1/n when one sample dominates. Dax and colleagues use this quantity for the gravitational-wave network DINGO and treat a low value as a sign that the data lie outside what the network learned. Dax and colleagues, 2023

For many samples, ϵ\epsilon tends to Eq[w]2/Eq[w2]\mathbb E_q[w]^2/\mathbb E_q[w^2]. A one-dimensional example shows how fast it falls. Let the exact posterior be standard normal and the network return a normal with the right centre and standard deviation kk. Then

Eq[w2]Eq[w]2=∫p(θ)2q(θ) dθ=k22k2−1.\frac{\mathbb E_q[w^2]}{\mathbb E_q[w]^2}=\int\frac{p(\theta)^2}{q(\theta)}\,\mathrm d\theta=\frac{k^2}{\sqrt{2k^2-1}} .

A network 1.51.5 times too wide has ϵ→0.83\epsilon\to0.83. One 0.750.75 times too narrow has ϵ→0.63\epsilon\to0.63. For k≤1/2k\le1/\sqrt2 the integral diverges: the weights have infinite variance, and the efficiency of any finite run is unreliable. A proposal that is too narrow is far more dangerous than one that is too wide. This is one reason DINGO is trained with a loss that favours covering all of the posterior mass.

In the Lab's model, the network has a median efficiency of 0.9660.966 over 2000 records drawn across the training range. For records with σ\sigma between 0.060.06 and 0.10.1, cleaner than anything in training, the median falls to 0.0290.029. On those records the network's 90% regions caught the source in only 0.380.38 of 400 cases, while the exact grid caught it in 0.890.89.

A residual test checks the model against the data

Importance weights use the assumed likelihood, so they can only tell whether the network matches the assumed model. To test the model, look at what is left after fitting it. If the assumed model is right, then at the true parameters the scaled residuals (dk−hk)/σ(d_k-h_k)/\sigma are 128 independent standard normal numbers. Fitting two parameters removes about two degrees of freedom, so the minimum

χmin⁡2=min⁡f,τ1σ2∑k[dk−hk(f,τ)]2\chi^2_{\min}=\min_{f,\tau}\frac{1}{\sigma^2}\sum_{k}\bigl[d_k-h_k(f,\tau)\bigr]^2

approximately follows a chi-square distribution with 126126 degrees of freedom, with mean 126126 and standard deviation 252≃15.9\sqrt{252}\simeq15.9. The Lab reports the probability of a value at least this large. A value below 0.010.01 flags the record.

On well-specified records the test flagged 0.9%0.9\%, close to the 1%1\% it should. It flagged 96.5%96.5\% of records containing a glitch at 20 ms20\,\mathrm{ms} and every record whose true noise was 1.51.5 times the assumed σ\sigma. In both cases the importance-sampling efficiency stayed well above the 0.10.1 warning level, with medians near 0.700.70 and 0.960.96, because the network still matched the exact posterior of the assumed model. The exact posterior was wrong as well: its 90% regions caught the source in 0.400.40 and 0.620.62 of the records.

How a small missing signal shifts the answer

Suppose the data contain an extra signal δh\delta h that the model lacks. Define the noise-weighted inner product (a∣b)=∑kakbk/σ2(a\mid b)=\sum_k a_k b_k/\sigma^2 and the Fisher matrix Γij=(∂ih∣∂jh)\Gamma_{ij}=(\partial_i h\mid\partial_j h). Expanding the best fit to first order in δh\delta h, Cutler and Vallisneri obtain the shift

δθi=(Γ−1)ij (∂jh∣δh).\delta\theta^{i}=\bigl(\Gamma^{-1}\bigr)^{ij}\,\bigl(\partial_j h\mid\delta h\bigr).

Cutler and Vallisneri, 2007, Section II Both Γ\Gamma and the inner product scale as 1/σ21/\sigma^2, so the shift does not depend on the noise level. The posterior width scales as σ\sigma. A fixed mismatch therefore matters more as the signal gets louder.

The saved grid check tests the formula with a schematic second mode added at the default source. At strength 0.020.02 the formula predicts a frequency shift of 0.0888 Hz0.0888\,\mathrm{Hz} and the grid finds 0.0882 Hz0.0882\,\mathrm{Hz}; for the damping time it predicts 0.0208 ms0.0208\,\mathrm{ms} and the grid finds 0.0207 ms0.0207\,\mathrm{ms}. At strength 0.30.3, lowering σ\sigma from 0.60.6 to 0.050.05 moves the frequency shift from 1.76 Hz1.76\,\mathrm{Hz} toward a high-signal value near 1.23 Hz1.23\,\mathrm{Hz}, while the shift measured in posterior standard deviations grows from 0.160.16 to 1.701.70.

The mismatch both checks miss

Put a second mode of strength 0.60.6 into the default source at σ=0.2\sigma=0.2. The fit absorbs most of it by moving ff and τ\tau, so the residual looks almost like noise: the test flagged only 6%6\% of 400 records. The network still matches the exact posterior of the assumed model, so the median efficiency is 0.980.98. Yet both posteriors caught the source in only about 0.740.74 of the records at nominal 90%.

Table 4.1 Which check sees which failure, 400 synthetic records per row, nominal 90% regions.
RecordNetwork coverageExact coverageMedian efficiencyResidual flags
Trained conditions0.9050.9050.9000.9000.9900.9900.8%0.8\%
Cleaner than the training data0.2850.2850.8930.8930.0200.0201.3%1.3\%
Glitch in the record0.3730.3730.1130.1130.2920.292100%100\%
Noise louder than assumed0.6480.6480.6500.6500.9800.980100%100\%
Hidden second mode0.7350.7350.7430.7430.9830.9836.3%6.3\%

The rows are the Lab's presets at fixed sources. In the glitch row the efficiency also drops, to a median of 0.290.29, because a glitch this strong moves the record away from anything in training; the residual test is what flags it. Talts and colleagues state the boundary in general form: calibration says nothing about whether the model is rich enough to capture the truth. Talts and colleagues, 2018, Section 4 A study of neural methods under deliberately wrong simulators found that none of the mitigations it tried prevented failure in every case. Cannon, Ward and Schmon, 2022 A richer model that includes the second mode, with its own posterior and calibration, is what would expose this case.

Lab tasks

Open the neural posterior Lab.

  1. Predict: choose the glitch, then drag the violet handle down toward zero strength. Which readout recovers first, the efficiency or the residual p-value?
  2. Change one condition: in the hidden second mode preset, raise the strength from 0.60.6 to 11. Does the residual test start to fire, and does the coverage gap grow?
  3. Compare: drag the noise band edge just below 0.150.15 and then just above 0.60.6. Which side of the training range hurts the network more, and why does the exact posterior not care?

Exercises

  1. Twenty importance weights are all equal except one, which is ten times larger. Compute ϵ\epsilon.
  2. Why does the residual test use 126126 degrees of freedom and not 128128?
  3. Using the scaling argument above, by what factor does the frequency shift in posterior standard deviations grow when σ\sigma halves, if the linear formula holds?
Answers
  1. Write the weights as nineteen of 11 and one of 1010. Then ∑w=29\sum w=29 and ∑w2=19+100=119\sum w^2=19+100=119, so ϵ=292/(20×119)≃0.353\epsilon=29^2/(20\times119)\simeq0.353. A single outlier removes almost two thirds of the useful samples.
  2. The minimum is taken over two fitted parameters. For a model that is close to linear in its parameters near the best fit, each fitted parameter removes one degree of freedom from the sum of squared residuals.
  3. The shift itself is unchanged and the posterior width halves, so the shift in posterior standard deviations doubles. The grid values at σ=0.3\sigma=0.3 and 0.150.15, 0.290.29 and 0.570.57, agree with this.

Sources

  1. Berti, Cardoso and Will, 2006, Section II
  2. Dax and colleagues, 2023
  3. Cutler and Vallisneri, 2007, Section II
  4. Talts and colleagues, 2018, Section 4
  5. Cannon, Ward and Schmon, 2022

Keep reading

What this page links to directly

Trusting posteriors learned from simulations · Reading path

From a posterior to calibration and model mismatch

  1. ArticleHow can you tell whether a neural network's posterior deserves trust?
  2. ArticleWhat a posterior and a 90% credible region promise
  3. ArticleChecking posterior calibration with ranks and coverage
  4. You are hereFinding a wrong simulator with importance weights and residuals
  5. ArticleRecompute the ringdown posterior calibration
  6. ArticleReading the DINGO evidence: P–P plots, divergences and sample efficiency
Something broken, confusing, or missing on this page?Tell us
What kind of feedback?

Sent with this page’s address, its Lab ID, the site language and your device type. Please leave out personal details. Feedback is kept for up to 12 months.Privacy policy