Concepts
Diagnostics
gspice.calibration() and
gspice.noise_audit() evaluate two complementary diagnostics on held-out spectra: calibration
checks the predicted conditional uncertainties, and noise_audit checks the reported inverse variances (ivar). A training spectrum has smaller residuals than a held-out
one (Held-out uncertainty), so neither check holds on the
training spectra. Check your model runs both and reads their
numbers.
Calibration
Section titled “Calibration”A predicted variance is right only if the residuals of real spectra match it. For each
spectrum and each size , calibration therefore hides good pixels, predicts them,
and compares. It draws the set of hidden pixels independently of the data:
- with
layout="run", the default, is consecutive good pixels from a random start; - with
layout="scattered", is good pixels drawn at random.
It then predicts from the pixels outside , as
gspice.infill() does, and computes
with the residuals and their full conditional covariance. It also gives
the finite-sample factor
, or 1 for a model without a derived factor. The
default sizes are the powers of 4 from 1 to 1024 that do not exceed half the median
number of good pixels per spectrum. The rng argument, a numpy.random.Generator,
draws the masks.
For held-out Gaussian spectra and a correct model, has the mean 1. The
methods of gspice.Calibration read the
result:
ratio()returns the mean of for each size, and its standard error. A mean above 1 shows predicted variances that are too small, and a mean below 1 variances that are too large. A mean that changes with shows that the covariance describes the correlations between the predicted pixels less well than their variances.tail(q)returns the fraction of entries with above the quantile of the χ² distribution with degrees of freedom. The fraction approaches only for . A fraction above shows a heavier tail than the Gaussian model.qq(i)returns the points of a quantile-quantile plot of column , one size. The points lie on the line of slope 1 where follows that χ² distribution.
A spectrum with fewer good pixels than a size has no entry for that size. The where
argument of each method selects the spectra, for example those with an entry at every
size.
Two effects can move the mean away from 1 in a correct model. does not hold for data that are not Gaussian, such as scaled spectra with a spread of S/N. A model without a derived factor reports , so its mean includes the widening that would describe.
The standard error is conditional on the fitted model. It falls with the number of held-out spectra, and the spread between training sets does not.
Calibration also holds other held-out results, such as the χ² of an infill with
masks that do not depend on the data. Its API entry
gives the fields to pass.
Noise audit
Section titled “Noise audit”Every model trusts ivar. A scaled model
takes into its covariance the noise level that its training spectra share. Its z-scores
therefore cannot show an ivar that is wrong in all of them. noise_audit compares the
residuals of the pixelwise prediction with the reported noise instead. With
the prediction of gspice.pixelwise() in flux
units, and the mean over the spectra whose pixel is good,
Let be the noise-free flux. Then , with two terms:
- , the mean of , is 1
where
ivaris right. - , the mean of , holds the error of the prediction. Its parts are the spectral variation that the model misses, the noise of the conditioning pixels and the estimation error of the model. It is at least 0, and it grows with the S/N.
So in expectation. A below 1 shows that ivar at pixel
reports more noise than the spectra have. A above 1 can come from either
term.
The identity holds where does not depend on the noise of . This
needs held-out spectra, mask and ivar independent of the noise, and noise
uncorrelated beyond nguard. It can fail where the interpolation of a bad pixel carries
, or a pixel within nguard of , into . Next to a run of bad
pixels longer than nguard, can fall below . noise_audit returns
of shape (npix,), with NaN where no spectrum is good.
held-out spectrum
A spectrum that the model was not fitted to.
finite-sample factor
: the factor by which the error of an estimated mean and covariance widens the residuals of a held-out spectrum, (Held-out uncertainty).
scaled model
A model in scaled units, whose one covariance holds both the variation between spectra and the noise. Every model is a scaled model except a noise-aware model.
noise-free flux
The flux that a spectrum would have without noise, . gspice.simulate returns it
as truth.