lilit package
# Welcome to LiLit!
A Python package encoding the likelihood for LiteBIRD.
LiLit provides forecasting likelihoods for LiteBIRD, implemented to be used in a Cobaya context. This package aims to ease the creation of a common framework among different LiteBIRD researchers.
Submodules
lilit.functions module
- lilit.functions.get_chi_exact(N, data, coba, lmin, lmax, fsky, bins)[source]
Computes proper chi-square term for the exact likelihood case.
- Parameters:
N (int) – Number of fields.
data (ndarray) – The covariance matrix of the data.
coba (ndarray) – The covariance matrix on the MCMC step.
lmin (int) – The minimum multipole to consider.
lmax (int) – The maximum multipole to consider.
fsky (float) – The fraction of the sky if a unique number is provided. Otherwise, it is the geometrical mean of the fraction of the sky for each field pair. In other words an effective fraction of the sky.
- lilit.functions.get_chi_gaussian(N, data, coba, mask, inverse_covariance, lmin, lmax, bins)[source]
Computes proper chi-square term for the Gaussian likelihood case.
- Parameters:
N (int) – Number of fields.
data (ndarray) – The covariance matrix of the data.
coba (ndarray) – The covariance matrix on the MCMC step.
mask (ndarray) – Mask corresponding to both excluded probes and excluded multipole ranges.
inverse_covariance (list(ndarray)) – Inverse of the covaraince matrices for each multipole.
lmin (int) – The minimum multipole to consider.
lmax (int) – The maximum multipole to consider.
Computes proper chi-square term for the Gaussian likelihood case.
- Parameters:
data (ndarray) – The covariance matrix of the data.
coba (ndarray) – The covariance matrix on the MCMC step.
inverse_covariance (list(ndarray)) – Inverse of the covaraince matrices for each multipole.
- lilit.functions.get_chi_HL(data, coba, fidu, offset, inverse_covariance, bins)[source]
Computes proper chi-square term for the Hamimeche & Lewis likelihood case.
- Parameters:
data (ndarray) – The covariance matrix of the data.
coba (ndarray) – The covariance matrix on the MCMC step.
inverse_covariance (list(ndarray)) – Inverse of the covaraince matrices for each multipole.
- lilit.functions.get_chi_LoLLiPoP(data, coba, fidu, offset, inverse_covariance, bins)[source]
Computes proper chi-square term for the Hamimeche & Lewis likelihood case.
- Parameters:
data (ndarray) – The covariance matrix of the data.
coba (ndarray) – The covariance matrix on the MCMC step.
inverse_covariance (list(ndarray)) – Inverse of the covaraince matrices for each multipole.
- lilit.functions.get_keys(fields, *, debug=False)[source]
Extracts the keys that has to be used as a function of the requested fields. These will be the usual 2-points, e.g., tt, te, ee, etc.
- lilit.functions.get_Gauss_keys(n, keys, *, debug=False)[source]
Find the proper dictionary keys for the requested fields.
Extracts the keys that has to be used as a function of the requested fields for the Gaussian likelihood. Indeed, the Gaussian likelihood is computed using 4-points, so the keys are different. E.g., there will be keys such as tttt, ttee, tete, etc.
- lilit.functions.get_reduced_covariances(covariance, lmin, lmax)[source]
Reduce the dimension of the covariance matrices given that they might be singular for some multipole ranges.
- lilit.functions.get_reduced_data_vectors(N, covariance, mask, lmin, lmax)[source]
Reduce the dimension of the data vectors given that some probe might not be defined in some multipole ranges or it might be excluded by the user.
- lilit.functions.cov_filling(fields, excluded_probes, absolute_lmin, absolute_lmax, cov_dict, lmins={}, lmaxs={})[source]
Fill covariance matrix with appropriate spectra.
Computes the covariance matrix once given a dictionary. Returns the covariance matrix of the considered fields, in a shape equal to (num_fields x num_fields x lmax). Note that if more than one lmax, or lmin, is specified, there will be null values in the matrices, making them singular. This will be handled in another method.
- Parameters:
fields (list) – The list of fields to consider.
excluded_probes (list) – The list of probes to exclude.
absolute_lmin (int) – The minimum multipole to consider.
absolute_lmax (int) – The maximum multipole to consider.
cov_dict (dict) – The input dictionary of spectra.
lmins (dict) – The dictionary of minimum multipole to consider for each field pair.
lmaxs (dict) – The dictionary of maximum multipole to consider for each field pair.
- lilit.functions.find_spectrum(lmin, lmax, input_dict, key)[source]
Find a spectrum in a given dictionary.
Returns the corresponding power sepctrum for a given key. If the key is not found, it will try to find the reverse key. Otherwise it will fill the array with zeros.
- lilit.functions.sigma(n, lmin, lmax, gauss_keys, fiduDICT, noiseDICT, fsky=None, fskies={})[source]
Define the covariance matrix for the Gaussian case.
In case of Gaussian likelihood, this returns the covariance matrix needed for the computation of the chi2. Note that the inversion is done in a separate funciton.
- Parameters:
n (int) – Number of fields.
lmin (int) – The minimum multipole to consider.
lmax (int) – The maximum multipole to consider.
keys (dict) – Keys for the covariance elements.
fiduDICT (dict) – Dictionary with the fiducial spectra.
noiseDICT (dict) – Dictionary with the noise spectra.
fsky (float, optional) – The fraction of sky to consider. If not specified, it means that the fraction of sky is different for each field pair.
fskies (dict, optional) – The dictionary of fraction of sky to consider for each field pair.
- lilit.functions.inv_sigma(lmin, lmax, masked_sigma)[source]
Invert the covariance matrix of the Gaussian case.
Inverts the previously calculated sigma ndarray. Note that some elements may be null, thus the covariance may be singular. If so, this also reduces the dimension of the matrix by deleting the corresponding row and column.
- lilit.functions.CAMBres2dict(camb_results, probes)[source]
Takes the CAMB result product from get_cmb_power_spectra and convert it to a dictionary with the proper keys.
- Parameters:
camb_results (CAMBdata) – CAMB result product from the method get_cmb_power_spectra.
probes (dict) – Keys for the spectra dictionary we want to save.
lilit.likelihood module
- class lilit.likelihood.LiLit(name=None, fields=None, lmin=2, lmax=None, like='exact', cl_file=None, nl_file=None, bias_file=None, fidu_guess_file=None, offset_file=None, external_covariance=None, experiment=None, nside=None, r=None, nt=None, pivot_t=0.01, fsky=1, excluded_probes=None, want_binning=False, debug=None)[source]
Bases:
LikelihoodClass defining the Likelihood for LiteBIRD (LiLit).
Within LiLit, the most relevant study cases of LiteBIRD (T, E, B) are already tested and working. So, if you need to work with those, you should not need to look into the actual definition of the likelihood function, since you can promptly start running your MCMCs. Despite this, you should provide to the likelihood some file where to find the proper LiteBIRD noise power spectra, given that LiLit is implementing a simple inverse noise weighting just as a place-holder for something more realistic. As regards lensing, LiLit will need you to pass the reconstruction noise, since its computation is not coded, thus there is no place-holder for lensing.
- Parameters:
name (str) – The name for the likelihood, used in the output. It is necessary to pass it to LiLit. (default: None).
fields (list) – List of fields in the data file (default: None).
lmin (int or list) – Minimum multipole to consider (default: 2).
lmax (int or list) – Maximum multipole to consider (default: None).
like_approx (str, optional) – Type of likelihood to use (default: “exact”). Currently supports “exact” and “gaussian”, soon “correlated_gaussian”.
cl_file (str, dict, optional) – Path to Cl file or dictionary of fiducial spectra (default: None).
nl_file (str, dict, optional) – Path to noise file or dictionary of noise spectra (default: None).
bias_file (str, dict, optional) – Path to bias file or dictionary of bias spectra (default: None).
experiment (str, optional) – Name of experiment (default: None).
nside (int, optional) – Nside of the map (default: None).
r (float, optional) – Tensor-to-scalar ratio (default: None).
nt (float, optional) – Tensor spectral tilt (default: None).
pivot_t (float, optional) – Pivot scale of the tensor primordial power spectrum (default: 0.01).
excluded_probes (list, optional) – List of probes to exclude (default: None).
debug (bool, optional) – If True, produces more verbose output (default: None).
- inverse_covariance
List of covariances for the Gaussian likelihood case, one for each multipole.
- Type:
- fiduCOV
Fiducial covariance matrix obtained from the corresponding dictionary.
- Type:
np.ndarray
- noiseCOV
Noise covariance matrix obtained from the corresponding dictionary.
- Type:
np.ndarray
- cobaCOV
Cobaya covariance matrix obtained from the corresponding dictionary.
- Type:
np.ndarray
- data
Data vector obtained by summing fiduCOV + noiseCOV + biasCOV.
- Type:
np.ndarray
- coba
Cobaya vector obtained by summing cobaCOV + noiseCOV.
- Type:
np.ndarray
- __init__(name=None, fields=None, lmin=2, lmax=None, like='exact', cl_file=None, nl_file=None, bias_file=None, fidu_guess_file=None, offset_file=None, external_covariance=None, experiment=None, nside=None, r=None, nt=None, pivot_t=0.01, fsky=1, excluded_probes=None, want_binning=False, debug=None)[source]
- check_supported_approximations()[source]
Check that the requested likelihood approximation is actually supported.
Note: the correlated Gaussian is supported for a single field, not multiple ones.
- set_lmin(lmin)[source]
Take lmin parameter and set the corresponding attributes.
This handles automatically the case of a single value or a list of values. Note that the lmin for the cross-correlations is set to the geometrical mean of the lmin of the two fields when the likelihood approximation is not exact. This approximation has been tested and found to be accurate, at least assuming that the two masks of the two considered multipoles are very overlapped. On the other hand, lmin is set to the maximum of the two other probes for the exact likelihood. Indeed, the geometrical mean causes some issues in this case.
- set_lmax(lmax)[source]
Take lmax parameter and set the corresponding attributes.
This handles automatically the case of a single value or a list of values. Note that the lmax for the cross-correlations is set to the geometrical mean of the lmax of the two fields when the likelihood approximation is not exact. This approximation has been tested and found to be accurate, at least assuming that the two masks of the two considered multipoles are very overlapped. On the other hand, lmax is set to the minimum of the two other probes for the exact likelihood. Indeed, the geometrical mean causes some issues in this case.
- set_fsky(fsky)[source]
Take fsky parameter and set the corresponding attributes.
This handles automatically the case of a single value or a list of values. Note that the fsky for the cross-correlations is set to the geometrical mean of the fsky of the two fields. This approximation has been tested and found to be accurate, at least assuming that the two masks of the two considered multipoles are very overlapped.
- get_fiducial_spectra()[source]
Produce fiducial spectra or read the input ones.
If the user has not provided a Cl file, this function will produce the fiducial power spectra starting from the CAMB inifile for Planck2018. The extra keywords defined will maximize the accordance between the fiducial Cls and the ones obtained from Cobaya. If B-modes are requested, the tensor-to-scalar ratio and the spectral tilt will be set to the requested values. Note that if you do not provide a tilt, this will follow the standard single-field consistency relation. If instead you provide a custom file, stores that.
- get_noise_spectra()[source]
Produce noise power spectra or read the input ones.
If the user has not provided a noise file, this function will produce the noise power spectra for a given experiment with inverse noise weighting of white noise in each channel (TT, EE, BB). Note that you may want to have a look at the procedure since it is merely a place-holder. Indeed, you should provide a more realistic file from which to read the noise spectra, given that inverse noise weighting severely underestimates the amount of noise. If instead you provide the proper custom file, this method stores that.
- get_bias_spectra()[source]
Store the input spectra for the bias.
The bias spectra stored here will be add to the fiducial power spectra, but not to the ones prodeced by Cobaya. In this way, one can study the case in which something is causing a bias in the spectra reconstruction (e.g. foregrounds, systematics and such).
- get_fidu_guess_spectra()[source]
Store the input spectra for a fiducial guess on the spectrum of data.
The bias spectra stored here will be add to the fiducial power spectra, but not to the ones prodeced by Cobaya. In this way, one can study the case in which something is causing a bias in the spectra reconstruction (e.g. foregrounds, systematics and such).
- get_offset_spectra()[source]
Store the input spectra for the offset (H&L approximation).
The bias spectra stored here will be add to the fiducial power spectra, but not to the ones prodeced by Cobaya. In this way, one can study the case in which something is causing a bias in the spectra reconstruction (e.g. foregrounds, systematics and such).
lilit.core.chi_square module
Chi-square calculations for LiLit likelihood computations.
This module provides a unified interface for different chi-square calculation methods used in cosmological likelihood analysis, including exact, Gaussian, Hamimeche & Lewis, and LoLLiPoP approximations.
- class lilit.core.chi_square.ChiSquareCalculator[source]
Bases:
objectUnified interface for chi-square calculations in likelihood analysis.
This class provides a factory pattern for different chi-square calculation methods, making it easy to switch between approximations and maintain consistent interfaces.
- static calculate(method, data, coba, **kwargs)[source]
Calculate chi-square using the specified method.
- Parameters:
method (ChiSquareMethod or str) – The chi-square calculation method to use.
data (ndarray) – The covariance matrix of the data.
coba (ndarray) – The covariance matrix on the MCMC step.
**kwargs – Method-specific parameters.
- Returns:
Chi-square values, format depends on method.
- Return type:
ndarray | list
- Raises:
ValueError – If method is not supported or required parameters are missing.
- class lilit.core.chi_square.ChiSquareMethod(value)[source]
Bases:
EnumAvailable chi-square calculation methods.
- EXACT = 'exact'
- GAUSSIAN = 'gaussian'
- CORRELATED_GAUSSIAN = 'correlated_gaussian'
- HAMIMECHE_LEWIS = 'hl'
- LOLLIPOP = 'lollipop'
- lilit.core.chi_square.get_chi_exact(N, data, coba, lmin, lmax, fsky)[source]
Legacy wrapper for exact chi-square calculation.
- Return type:
- lilit.core.chi_square.get_chi_gaussian(N, data, coba, mask, inverse_covariance, lmin, lmax)[source]
Legacy wrapper for Gaussian chi-square calculation.
Legacy wrapper for correlated Gaussian chi-square calculation.
- Return type: