pyCE.cosmology.analysis.aps module

Information-theoretic analysis of angular power spectra.

Tools for CMB angular power spectra C_ell: forming the modal fraction (the normalized distribution over multipoles, including the 2*ell+1 degeneracy), Shannon entropy and Kullback-Leibler divergence of such distributions, and a nonparametric (shrinkage) fit of a noisy spectrum to an orthogonal basis following Aghamousa, Arjunwadkar & Souradeep (arXiv:1107.0516).

pyCE.cosmology.analysis.aps.KL_divergence(p, q)[source]

Kullback-Leibler divergence D(p || q) in bits.

Note that the divergence is not symmetric in its arguments.

Parameters:
  • p (ndarray) – A modal fraction.

  • q (ndarray) – A modal fraction. Zero entries are set to NaN in place and dropped from the sum.

Returns:

sum_i p_i * log2(p_i / q_i) over finite entries.

Return type:

float

pyCE.cosmology.analysis.aps.basis_cos(j, x)[source]

j-th orthonormal cosine basis function on [0, 1].

Returns 1 for j = 0 and sqrt(2)*cos(j*pi*x) otherwise.

pyCE.cosmology.analysis.aps.basis_leg(j, x)[source]

j-th orthonormal Legendre polynomial rescaled to [0, 1].

pyCE.cosmology.analysis.aps.entropy(p)[source]

Shannon entropy of a modal fraction, in bits.

Parameters:

p (ndarray) – A modal fraction. Non-positive entries are set to NaN in place and dropped from the sum.

Returns:

-sum_i p_i * log2(p_i) over finite entries.

Return type:

float

pyCE.cosmology.analysis.aps.modal_fraction(ell, Cl)[source]

Modal fraction of an angular power spectrum.

Weights each multipole by its 2*ell+1 degenerate m-modes and normalizes, giving the fraction of the total power carried by each ell. Negative entries (unphysical, e.g. noise-dominated estimates) are set to NaN.

Parameters:
  • ell (ndarray) – Multipole moments.

  • Cl (ndarray) – Angular power spectrum C_ell. Modified in place where negative.

Returns:

Normalized modal fraction over ell.

Return type:

ndarray

pyCE.cosmology.analysis.aps.nonparametric_fit(data, error, U, lType='NSS', JRange=[1, 100])[source]

Nonparametric shrinkage fit of noisy data to an orthogonal basis.

Expands the data in the basis U, shrinks the coefficient vector, and selects the amount of shrinkage by minimizing an unbiased estimate of the risk. The algorithm follows arXiv:1107.0516v2.

Parameters:
  • data (ndarray) – Data vector of length N.

  • error (ndarray) – One-sigma errors on the data. Used both for the inverse-variance weights and as a diagonal stand-in for the covariance matrix (the off-diagonal terms are set to zero until a full covariance is available).

  • U (ndarray, shape (N, N)) – Orthogonal basis matrix from npf_makeU.

  • lType (str) – Shrinkage scheme: ‘NSS’ keeps the first j coefficients (Nested Subset Selection); ‘Fractional’ applies monotone fractional weights 2**-i.

  • JRange (list of int) – [minJ, maxJ], the range of shrinkage parameters scanned.

Returns:

‘nbf’ : the nonparametric best fit evaluated at the data points, ‘Risk’ : the risk estimate at each J in the scan, ‘EDoF’ : the effective degrees of freedom at each J.

Return type:

dict

pyCE.cosmology.analysis.aps.norm(p)[source]

L1-normalize an array (NaN-safe).

Parameters:

p (ndarray)

Returns:

p divided by its nansum, so the finite entries sum to one.

Return type:

ndarray

pyCE.cosmology.analysis.aps.npf_makeU(x, basis)[source]

Orthogonal design matrix for a nonparametric fit.

Parameters:
  • x (ndarray) – Sample points in [0, 1].

  • basis (callable) – Basis function basis(j, x), e.g. basis_cos or basis_leg.

Returns:

Column i holds basis(i, x)/sqrt(N), so that U is (approximately) orthogonal: U^T U ~ identity.

Return type:

ndarray, shape (len(x), len(x))