like_cl_gauss module

Likelihood module to evaluate the joint likelihood of a set of tomographic 3x2pt power spectra on the full sky using a multivariate Gaussian likelihood.

The main functions are setup, which should be called once per analysis, and execute, which is called for every new point in parameter space.

like_cl_gauss.cl_cov(theory_cl, l, n_fields)

Returns the Gaussian covariance matrix of full-sky Cl estimates for a single l.

Parameters
  • theory_cl (1D numpy array) – All Cls for this l, in diagonal ordering.

  • l (int) – The l value.

  • n_fields (int) – The number of fields, where the number of spectra = n_fields * (n_fields + 1) / 2.

Returns

The covariance matrix for this l.

Return type

2D numpy array

like_cl_gauss.cl_invcov(ell, fid_cl, nl, n_field)

Calculate the inverse covariance matrix for all l (each l separately), from fiducial Cls including noise.

Parameters
  • ell (1D numpy array) – All l values, shape (n_ell,).

  • fid_cl (2D numpy array) – Theory Cls, shape (n_ell, n_spectra), with spectra in diagonal ordering.

  • nl (2D numpy array) – Noise Cls, shape (n_ell, n_spectra).

  • n_field (int) – Number of fields, such that n_spectra = n_field * (n_field + 1) / 2.

Returns

Inverse covariance for each ell, shape (n_ell, n_spectra, n_spectra).

Return type

inv_cov (3D numpy array)

like_cl_gauss.execute(theory_ell, theory_cl, config)

Perform some consistency checks then evaluate the likelihood for particular theory Cls.

Parameters
  • theory_ell (1D numpy array) – Ell range for all of the theory spectra (must be consistent between spectra).

  • theory_cl (2D numpy array) – Theory power spectra, in diagonal ordering, with shape (n_spectra, n_ell).

  • config (dict) – Config dictionary returned by setup.

Returns

log-likelihood value.

Return type

float

like_cl_gauss.is_even(x)

True if x is even, false otherwise.

Parameters

x (float) – Number to test.

Returns

True if even.

Return type

bool

like_cl_gauss.is_odd(x)

True if x is odd, false otherwise.

Parameters

x (float) – Number to test.

Returns

True if odd.

Return type

bool

like_cl_gauss.joint_log_likelihood(ell, theory_cl, noise_cl, obs_cl, inv_cov, lmax)

Returns the joint log-likelihood of a whole observed 3x2pt data vector.

Parameters
  • ell (1D numpy array) – Array of all ells.

  • theory_cl (2D numpy array) – Theory Cls, with ells along the first axis and different spectra along the second.

  • noise_cl (2D numpy array) – Noise Cls, in the same shape as theory_cl.

  • obs_cl (2D numpy array) – Observed Cls, in the same shape as theory_cl.

  • inv_cov (2D numpy array) – Inverted covariance matrix.

  • lmax (int) – Maximum ell to include in the likelihood.

Returns

Joint log-likelihood value.

Return type

float

like_cl_gauss.load_cls(n_zbin, pos_pos_dir, she_she_dir, pos_she_dir, lmax=None, lmin=0)

Given the number of redshift bins and relevant directories, load power spectra (position, shear, cross) in the correct order (diagonal / healpy new=True ordering). If lmin is supplied, the output will be padded to begin at l=0.

Parameters
  • n_zbin (int) – Number of redshift bins.

  • pos_pos_dir (str) – Path to directory containing position-position power spectra.

  • she_she_dir (str) – Path to directory containing shear-shear power spectra.

  • pos_she_dir (str) – Path to directory containing position-shear power spectra.

  • lmax (int, optional) – Maximum l to load - if not supplied, will load all lines, which requires the individual lmax of each file to be consistent.

  • lmin (int, optional) – Minimum l supplied. Output will be padded with zeros below this point.

Returns

All Cls, with different spectra along the first axis and increasing l along the second.

Return type

2D numpy array

like_cl_gauss.log_likelihood_single_l(theory_cl, noise_cl, obs_cl, inv_cov)

Returns the log-likelihood of a set of Cls for a single l.

Parameters
  • theory_cl (1D numpy array) – Set of theorys Cls for this l.

  • noise_cl (1D numpy array) – Set of noise Cls for this l.

  • obs_cl (1D numpy array) – Set of observed Cls for this l.

  • inv_cov (2D numpy array) – Inverted covariance matrix.

Returns

Log-likelihood value.

Return type

float

like_cl_gauss.matrix_indices(vector_idx, matrix_size)

Convert from vector index to matrix indices.

Parameters
  • vector_idx (int) – Vector index.

  • matrix_size (int) – Size along one axis of the square matrix to output indices for.

Returns

Row index, column index.

Return type

(int, int)

like_cl_gauss.mvg_logpdf_fixedcov(x, mean, inv_cov)

Log-pdf of the multivariate Gaussian where the determinant and inverse of the covariance matrix are precomputed and fixed. Note that this neglects the additive constant: -0.5 * (len(x) * log(2 * pi) + log_det_cov), because it is irrelevant when comparing pdf values with a fixed covariance, but it means that this is not the normalised pdf.

Parameters
  • x (1D numpy array) – Vector value at which to evaluate the pdf.

  • mean (1D numpy array) – Mean vector of the multivariate Gaussian distribution.

  • inv_cov (2D numpy array) – Inverted covariance matrix.

Returns

Log-pdf value.

Return type

float

like_cl_gauss.setup(n_zbin, obs_pos_pos_dir, obs_she_she_dir, obs_pos_she_dir, pos_nl_path, she_nl_path, noise_ell_path, fid_pos_pos_dir, fid_she_she_dir, fid_pos_she_dir, lmax, leff_path=None)

Load and precompute everything that is fixed throughout parameter space. This should be called once per analysis, prior to any calls to execute.

Parameters
  • n_zbin (int) – Number of redshift bins. It will be assumed that there is one position field and one shear field per redshift bin.

  • obs_pos_pos_dir (str) – Path to the directory containing the observed position-position power spectra.

  • obs_she_she_dir (str) – Path to the directory containing the observed shear-shear power spectra.

  • obs_pos_she_dir (str) – Path to the directory containing the observed position-shear power spectra.

  • pos_nl_path (str) – Path to the position noise power spectrum.

  • she_nl_path (str) – Path to the shear noise power spectrum.

  • noise_ell_path (str) – Path to the file containing the ells for the noise power spectra.

  • fid_pos_pos_dir (str) – Path to the directory containing the fiducial theory position-position power spectra, used for the covariance.

  • fid_she_she_dir (str) – Path to the directory containing the fiducial theory shear-shear power spectra.

  • fid_pos_she_dir (str) – Path to the directory containing the fiducial theory position-shear power spectra.

  • lmax (int) – Maximum l to use in the likelihood.

  • leff_path (str, optional) – Path to ell-ell_effective mapping, to replace each l with its corresponding l_eff when calculating the covariance.

Returns

Config dictionary to pass to execute.

Return type

dict

like_cl_gauss.vector_index(row_idx, col_idx, matrix_size)

Convert from matrix indices to vector index.

Parameters
  • row_idx (int) – Row index for matrix.

  • col_idx (int) – Column index for matrix.

  • matrix_size (int) – Size along one axis of the square matrix that input indices are for.

Returns

Vector index corresponding to the input matrix indices.

Return type

int