Skip to content
GSPICE

Concepts

Held-out uncertainty

A model fitted to NsN_s training spectra carries estimation error in its sample mean and covariance, which widens the standardized residuals of held-out spectra by a closed-form finite-sample factor fsf_s.

A held-out spectrum is a spectrum that the model was not fitted to, such as a spectrum that you repair. Its residuals include the error of the estimated mean and covariance. A training spectrum is different: it helped to fit the model, so the model leans toward it, and its in-sample residuals are smaller. The figure shows both:

training spectra per pixel, Ns / npix (log scale)

  • held-out spectra
  • training spectra
  • square root of the mean finite-sample factor

The points show the RMS of the pixelwise z, with nguard 20, for models of 100 pixels fitted to Ns exactly Gaussian simulated spectra. Each point averages 10 training sets, and the held-out points use the same 2000 other spectra. At Ns = 2 npix the held-out RMS is 1.486, and at 20 npix it is 1.032. The training spectra stay near 1.

With few training spectra per pixel, the z-scores of held-out spectra are much wider than 1. A threshold of 5 on such z-scores then flags far more pixels than a Gaussian distribution would. With many training spectra per pixel, the effect becomes small.

The finite-sample factor fsf_s states the widening exactly. A model predicts N∗N_* pixels of a held-out spectrum from NkN_k conditioning pixels. Let Z2Z^2 be the χ² of those pixels, with their full conditional covariance. Then E[Z2]/N∗=fsE[Z^2] / N_* = f_s, with

fs=(1+1Ns)Ns−2Ns−Nk−2⋅Ns−1Ns−Nk−N∗−2.f_s = \left(1 + \frac{1}{N_s}\right) \frac{N_s - 2}{N_s - N_k - 2} \cdot \frac{N_s - 1}{N_s - N_k - N_* - 2} .

The factor grows as NsN_s approaches NkN_k. It is not defined where Ns−Nk−N∗−2≤0N_s - N_k - N_* - 2 \le 0. For one pixel of a pixelwise prediction, N∗=1N_* = 1 and NkN_k is the number of pixels outside the guard window. The curve of the figure is the square root of the mean of fsf_s over the pixels, and it matches the points. What GSPICE needs gives fsf_s for a spectrum of 200 pixels, and Why 1500 pixels for the survey of the worked example. gspice.finite_sample_factor() computes fsf_s.

fsf_s is exact under five conditions:

  1. The model is dense and mean-centered: no low rank and no constant center.
  2. The model is unweighted and not noise-aware.
  3. The working vectors are independent draws from one Gaussian distribution.
  4. The pixel sets do not depend on the data.
  5. NkN_k counts the conditioning pixels only. Guard and ignored pixels do not count.

Condition 3 fails for scaled spectra with a spread of S/N, which are a mixture of Gaussian distributions. Condition 4 fails for gspice.repair(), whose replaced and ignored pixels depend on the z-scores. A model of another kind has no derived factor and reports 1, although its held-out residuals are wider too. Calibration measures the widening on your own held-out spectra.

inflate=True corrects the predicted uncertainty for this widening. pixelwise, infill and repair then multiply each conditional variance and covariance by fs(Ns,Nk,1)f_s(N_s, N_k, 1). Here NsN_s counts the training spectra of the S/N bin of the spectrum, and NkN_k the conditioning pixels of the prediction. The deviation of each draw from the conditional mean grows by the square root of that factor.

The factor of one pixel, N∗=1N_* = 1, calibrates every fixed linear combination of the predicted pixels, such as the flux in a band. The joint χ² of N∗N_* pixels needs fs(Ns,Nk,N∗)f_s(N_s, N_k, N_*) instead, which is larger. inflate=True raises a ValueError for a model without a derived factor, and where fs(Ns,Nk,1)f_s(N_s, N_k, 1) is not defined. Find outliers and Fill known bad pixels show the effect on simulated spectra.

Repaired.fs holds the factor that keeps chi2 / (dof * fs) at the mean 1 for held-out Gaussian spectra, with or without inflate:

  • without inflate, fs(Ns,Nk,dof)f_s(N_s, N_k, \mathrm{dof});
  • with inflate=True, fs(Ns,Nk,dof)/fs(Ns,Nk,1)f_s(N_s, N_k, \mathrm{dof}) / f_s(N_s, N_k, 1), because chi2 already uses the inflated covariance.

It is NaN where fs(Ns,Nk,dof)f_s(N_s, N_k, \mathrm{dof}) is not defined, and 1 for a model without a derived factor.