specsrbench.metrics¶
Reconstruction metrics, and the four guards that keep tuning honest.
MAE alone is not a safe objective, in four separate ways, and no one guard catches the others:
Smoothing – erase every line and no line-shaped residual is incurred.
Shrinkage – scale toward zero and absolute error against a noisy reference falls, whatever the reconstruction quality.
Blurring – a unit-gain Wiener filter with
snr <= 1peaks at zero frequency, so it can only broaden lines, and the amplitude guard is width-invariant.Merging – all three of the above can pass while two close lines are smeared into one peak, because a Gaussian fitted to a blended doublet has much the same amplitude, S/N and width as one fitted to a separated pair.
mae_scalefree() and std_ratio() are what make (2) visible, and they
live here rather than in a build script because the tuner, the cache build, the
figures and the tests all have to agree on them. They did not, once: the tuner
retuned every method against a corrected kernel while the build went on using
the old parameters, and every classical number in the paper was wrong for a day
while the whole test suite passed.
Module Attributes
|
Amplitude guard band. |
|
Amplitude guard band. |
Functions
|
|
|
Standard deviation of the mean under resampling of spectra. |
|
Gaussian FWHM in nanometres from a fitted sigma in microns. |
|
One row of the global-fidelity table, guards included. |
|
Mean over spectra of the per-spectrum mean absolute error. |
|
MAE after rescaling each spectrum by its own least-squares optimal gain. |
|
|
|
Output scale over target scale. |
|
Per-spectrum z-score, the units every cached reconstruction is in. |
- specsrbench.metrics.zscore(arr)[source]¶
Per-spectrum z-score, the units every cached reconstruction is in.
- specsrbench.metrics.mae(pred, truth, mask)[source]¶
Mean over spectra of the per-spectrum mean absolute error.
- Return type:
- specsrbench.metrics.mae_scalefree(pred, truth, mask)[source]¶
MAE after rescaling each spectrum by its own least-squares optimal gain.
Invariant under any global rescale of
predby construction, which is the entire point: shrinkage cannot improve it. This is the metric on which SR2 ranks eighth of nine while leading the raw-MAE table by 30%.- Return type:
- specsrbench.metrics.std_ratio(pred, truth, mask)[source]¶
Output scale over target scale. 1.0 means amplitude was preserved.
- Return type:
- specsrbench.metrics.bootstrap_std(per_spectrum, n_boot=1000, seed=42)[source]¶
Standard deviation of the mean under resampling of spectra.
Spectra, not pixels: pixels within one spectrum are correlated, and resampling them would report an error bar several times too small.
- specsrbench.metrics.fwhm_from_sigma(sigma_um)[source]¶
Gaussian FWHM in nanometres from a fitted sigma in microns.
- Return type:
- specsrbench.metrics.global_stats(name, pred, truth, mask, *, n_boot=1000, seed=42)[source]¶
One row of the global-fidelity table, guards included.
MAEandMAE_scalefreeare reported together, always. Quoting the first without the second is how this paper twice came to state a conclusion that the scale-free number reverses.