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 dk at times tk=k/(4096Hz), covering 31.25ms. The assumed signal is one damped sinusoid with fixed amplitude and phase,
hk(f,τ)=Ae−tk/τcos(2πftk+φ),A=1,φ=0,
with frequency f uniform on 200 to 300Hz and damping time τ uniform on 2 to 10ms. This is the convention of Berti, Cardoso and Will, whose quality factor Q=πfτ is about 4.7 at the Lab's default source of 250Hz and 6ms. Berti, Cardoso and Will, 2006, Section II The assumed noise is white and Gaussian with known standard deviation σ per sample, so
lnp(d∣f,τ)=−2σ21k=0∑127[dk−hk(f,τ)]2+const.
The amplitude and noise are in the same whitened units. At σ=0.2 the default signal has an optimal signal-to-noise ratio ∑khk2/σ≃13.0. The network was trained only on records drawn from this model with σ between 0.15 and 0.6.
Importance weights compare the network with the exact posterior
Let q(θ∣d) be the network's posterior for θ=(f,τ) and π(θ) the prior. Any expectation under the exact posterior can be written as an expectation under q:
Draw n samples θi from the network, compute each weight wi and replace the expectations by averages. When q equals the exact posterior, every weight equals the same number p(d). When q misses part of the posterior, a few samples in the missed region carry huge weights. The sample efficiency
ϵ=n∑iwi2(∑iwi)2
measures this: it is one for equal weights and close to 1/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, ϵ tends to Eq[w]2/Eq[w2]. 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 k. Then
Eq[w]2Eq[w2]=∫q(θ)p(θ)2dθ=2k2−1k2.
A network 1.5 times too wide has ϵ→0.83. One 0.75 times too narrow has ϵ→0.63. For k≤1/2 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.966 over 2000 records drawn across the training range. For records with σ between 0.06 and 0.1, cleaner than anything in training, the median falls to 0.029. On those records the network's 90% regions caught the source in only 0.38 of 400 cases, while the exact grid caught it in 0.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)/σ are 128 independent standard normal numbers. Fitting two parameters removes about two degrees of freedom, so the minimum
χmin2=f,τminσ21k∑[dk−hk(f,τ)]2
approximately follows a chi-square distribution with 126 degrees of freedom, with mean 126 and standard deviation 252≃15.9. The Lab reports the probability of a value at least this large. A value below 0.01 flags the record.
On well-specified records the test flagged 0.9%, close to the 1% it should. It flagged 96.5% of records containing a glitch at 20ms and every record whose true noise was 1.5 times the assumed σ. In both cases the importance-sampling efficiency stayed well above the 0.1 warning level, with medians near 0.70 and 0.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.40 and 0.62 of the records.
How a small missing signal shifts the answer
Suppose the data contain an extra signal δh that the model lacks. Define the noise-weighted inner product (a∣b)=∑kakbk/σ2 and the Fisher matrix Γij=(∂ih∣∂jh). Expanding the best fit to first order in δh, Cutler and Vallisneri obtain the shift
δθi=(Γ−1)ij(∂jh∣δh).
Cutler and Vallisneri, 2007, Section II Both Γ and the inner product scale as 1/σ2, so the shift does not depend on the noise level. The posterior width scales as σ. 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.02 the formula predicts a frequency shift of 0.0888Hz and the grid finds 0.0882Hz; for the damping time it predicts 0.0208ms and the grid finds 0.0207ms. At strength 0.3, lowering σ from 0.6 to 0.05 moves the frequency shift from 1.76Hz toward a high-signal value near 1.23Hz, while the shift measured in posterior standard deviations grows from 0.16 to 1.70.
The mismatch both checks miss
Put a second mode of strength 0.6 into the default source at σ=0.2. The fit absorbs most of it by moving f and τ, so the residual looks almost like noise: the test flagged only 6% of 400 records. The network still matches the exact posterior of the assumed model, so the median efficiency is 0.98. Yet both posteriors caught the source in only about 0.74 of the records at nominal 90%.
Table 4.1 Which check sees which failure, 400 synthetic records per row, nominal 90% regions.
Record
Network coverage
Exact coverage
Median efficiency
Residual flags
Trained conditions
0.905
0.900
0.990
0.8%
Cleaner than the training data
0.285
0.893
0.020
1.3%
Glitch in the record
0.373
0.113
0.292
100%
Noise louder than assumed
0.648
0.650
0.980
100%
Hidden second mode
0.735
0.743
0.983
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.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.
Predict: choose the glitch, then drag the violet handle down toward zero strength. Which readout recovers first, the efficiency or the residual p-value?
Change one condition: in the hidden second mode preset, raise the strength from 0.6 to 1. Does the residual test start to fire, and does the coverage gap grow?
Compare: drag the noise band edge just below 0.15 and then just above 0.6. Which side of the training range hurts the network more, and why does the exact posterior not care?
Exercises
Twenty importance weights are all equal except one, which is ten times larger. Compute ϵ.
Why does the residual test use 126 degrees of freedom and not 128?
Using the scaling argument above, by what factor does the frequency shift in posterior standard deviations grow when σ halves, if the linear formula holds?
AnswersShow the answer
Write the weights as nineteen of 1 and one of 10. Then ∑w=29 and ∑w2=19+100=119, so ϵ=292/(20×119)≃0.353. A single outlier removes almost two thirds of the useful samples.
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.
The shift itself is unchanged and the posterior width halves, so the shift in posterior standard deviations doubles. The grid values at σ=0.3 and 0.15, 0.29 and 0.57, agree with this.