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: object

An n(z) model n̄ + Σ u_k d_k on a fixed z grid.

eigenvalues holds λ_k for every ensemble direction, not only the kept ones, so chi2_left can show what any truncation would discard.

z: ndarray
mean: ndarray
decoder: ndarray
encoder: ndarray
eigenvalues: ndarray
property n_modes
property chi2_left

Expected χ² discarded when keeping 0, 1, …, n_directions modes.

decode(u)[source]

n(z) at mode amplitudes u (shape (..., n_modes)).

encode(nz)[source]

Mode amplitudes of nz (shape (..., n_bin, n_z)).

save(path)[source]
classmethod load(path)[source]
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 about mean; see fisher_metric(), observable_metric(), sacc_metric().

  • threshold (float) – Keep the fewest modes whose discarded expected χ² is below threshold times the total.

  • n_modes (int, optional) – Keep exactly this many modes instead.

  • rtol (float) – Ensemble directions with variance below rtol times the largest are treated as fixed.

fisher_metric(fisher)[source]

Metric from a Fisher matrix over the flattened (bin, z) n(z) values.

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, and cov is its covariance. J is a central difference along each direction, scaled so the perturbation peaks at step times 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. Tracers source_0 … carry the n(z); the z grid of the realisations must be theirs.

sacc_nz(s)[source]

The z grid and (n_bin, n_z) n(z) of a SACC’s source tracers.

set_sacc_nz(s, nz)[source]

Replace the n(z) of a SACC’s source tracers, in place, bin by bin.

_source_tracers(s)[source]
shift_stretch(z, nz, shift, stretch)[source]

Each bin of nz shifted by shift and stretched about its mean.

nz is (n_bin, n_z); shift and stretch are (..., n_bin), and the result (..., n_bin, n_z) keeps each bin’s normalisation.

cut_sacc(s, statistic='xi', scales=None)[source]

A copy of s holding one statistic, optionally within a scale range.

statistic is "xi" (ξ±, scales in arcmin on the theta tag) or "cl" (C_ℓ^EE, scales in ℓ on the ell tag).

main(argv=None)[source]

Write the n(z) modes of a realisation ensemble for a SACC’s statistic.

Reads only the SACC’s tracers and covariance, never its data vector, so a blinded SACC is safe to use.