sp_validation.nz.modes¶
Likelihood-aware n(z) modes: the n(z) uncertainty a data vector can see.
Method by William d’Assignies Doumerg (likelihood-aware PCA following Bernstein et al.). Given an ensemble of tomographic n(z) realisations and the Fisher information of an observable with respect to n(z), it finds the few n(z) distortions that carry the observable’s χ², ordered by how much each one contributes, and keeps enough of them to leave a chosen fraction of the χ² behind.
The ensemble is whitened by its own covariance, C_n = V Λ Vᵀ, so that n − n̄ = A w with A = V Λ^½ and w white. In those coordinates the observable’s χ² metric is G = Aᵀ F A, whose eigenvalues λ_k are the expected χ² each mode contributes for a draw from the ensemble. The kept modes give
n(z | u) = n̄ + Σ_k u_k d_k, u ~ N(0, 1) under the ensemble,
with d_k the columns of A V_G and u = V_Gᵀ Λ^{-½} Vᵀ (n − n̄). The prior on u
is exactly a unit Gaussian only if the ensemble is Gaussian; plot
encode(realisations) to check.
Only G is needed, so the Fisher matrix is never formed on the full (bin, z)
grid: observable_metric() differentiates the theory along the columns of
A, one finite difference per ensemble direction, and sacc_metric() does
so for a SACC data vector with its own covariance and the pyccl theory of
sp_validation.blinding.shear(). A precomputed Fisher matrix enters
through fisher_metric().
- class NzModes(z: ndarray, mean: ndarray, decoder: ndarray, encoder: ndarray, eigenvalues: ndarray)[source]¶
Bases:
objectAn n(z) model n̄ + Σ u_k d_k on a fixed z grid.
eigenvaluesholds λ_k for every ensemble direction, not only the kept ones, sochi2_leftcan show what any truncation would discard.- property n_modes¶
- property chi2_left¶
Expected χ² discarded when keeping 0, 1, …, n_directions modes.
- fit(z, realisations, metric, threshold=0.01, n_modes=None, rtol=1e-12)[source]¶
Find the modes of an n(z) ensemble under an observable’s χ² metric.
- Parameters:
z ((n_z,) array)
realisations ((n_real, n_bin, n_z) array) – n(z) draws. Each draw holds every bin, so modes span bins jointly.
metric (callable) –
metric(mean, directions)returns Aᵀ F A for the(n_dir, n_bin, n_z)stack of n(z) directions A aboutmean; seefisher_metric(),observable_metric(),sacc_metric().threshold (float) – Keep the fewest modes whose discarded expected χ² is below
thresholdtimes the total.n_modes (int, optional) – Keep exactly this many modes instead.
rtol (float) – Ensemble directions with variance below
rtoltimes the largest are treated as fixed.
- observable_metric(theory, cov, step=0.1)[source]¶
Metric of a data vector: Jᵀ C⁻¹ J along each ensemble direction.
theory(nz)maps an(n_bin, n_z)n(z) to the data vector, andcovis its covariance. J is a central difference along each direction, scaled so the perturbation peaks atsteptimes the peak of the mean n(z). A fixed amplitude keeps every direction in the linear regime and well above the theory’s numerical noise, however small its variance.
- sacc_metric(s, params=None, step=0.1)[source]¶
Metric of a SACC data vector under
sp_validation.blinding.shear().Uses every data point in
s(cut it to the statistic and scales the analysis uses first) and its covariance. Tracerssource_0… carry the n(z); the z grid of the realisations must be theirs.
- shift_stretch(z, nz, shift, stretch)[source]¶
Each bin of
nzshifted byshiftand stretched about its mean.nzis(n_bin, n_z);shiftandstretchare(..., n_bin), and the result(..., n_bin, n_z)keeps each bin’s normalisation.