pybird.likelihood module

class pybird.likelihood.Likelihood(config, verbose=True)[source]

Bases: object

EFT Likelihood for cosmological parameter inference.

This class implements the likelihood calculation for the Effective Field Theory of Large Scale Structure, handling multiple sky patches with correlated priors. It supports both marginalized and non-marginalized approaches for EFT nuisance parameters, and can incorporate BAO reconstruction, loop priors, and various optimization techniques.

c

Master configuration dictionary.

Type:

dict

io

I/O handler for reading and writing data.

Type:

ReadWrite

c_sky

List of configuration dictionaries for each sky patch.

Type:

list

d_sky

List of data dictionaries for each sky patch.

Type:

list

nsky

Number of sky patches.

Type:

int

m_sky

List of data masks for each sky patch.

Type:

list

y_sky

List of data vectors for each sky patch.

Type:

list

p_sky

List of precision matrices for each sky patch.

Type:

list

y_all

Concatenated data vector across all sky patches.

Type:

ndarray

p_all

Block-diagonal precision matrix combining all sky patches.

Type:

ndarray

correlator_sky

List of PyBird correlator engines for each sky patch.

Type:

list

alpha_sky

List of BAO reconstruction alphas if enabled.

Type:

list

out

List of output dictionaries for each sky patch.

Type:

list

Tng_k_cache

Cache for model power spectra per sky patch.

Type:

list

b_name

Names of all EFT parameters.

Type:

list

bg_name

Names of Gaussian-marginalized EFT parameters.

Type:

list

bg_prior_mean

Prior means for marginalized parameters.

Type:

ndarray

bg_prior_sigma

Prior widths for marginalized parameters.

Type:

ndarray

bng_name

Names of non-marginalized Gaussian EFT parameters.

Type:

list

bng_prior_mean

Prior means for non-marginalized Gaussian parameters.

Type:

ndarray

bng_prior_sigma

Prior widths for non-marginalized Gaussian parameters.

Type:

ndarray

bnlog_name

Names of log-normal EFT parameters.

Type:

list

bnlog_prior_mean

Prior means for log-normal parameters.

Type:

ndarray

bnlog_prior_sigma

Prior widths for log-normal parameters.

Type:

ndarray

Ng

Number of marginalized parameters.

Type:

int

marg_lkl

Whether to use marginalized likelihood.

Type:

bool

F2_bg_prior_matrix

Prior precision matrix for marginalized parameters.

Type:

ndarray

F1_bg_prior_mean

Prior mean vector for marginalized parameters.

Type:

ndarray

chi2_bg_prior_mean

Prior chi-squared contribution.

Type:

float

prior_inv_corr_matrix

Inverse correlation matrix for correlated skies.

Type:

ndarray

class_settings

Settings for Boltzmann solver.

Type:

dict

kin

k-values for Boltzmann solver input.

Type:

ndarray

optipath_chi2

Optimized einsum path for non-marginalized chi-squared.

Type:

list

optipath_F2

Optimized einsum path for F2 matrix in marginalization.

Type:

list

optipath_F1

Optimized einsum path for F1 vector in marginalization.

Type:

list

optipath_bg

Optimized einsum path for marginalized parameter calculation.

Type:

list

set_data()[source]

Set up data vectors and precision matrices from input data.

set_config()[source]

Set configuration options with defaults.

set_class_settings()[source]

Configure CLASS or other Boltzmann solver settings.

set_eft_parameters()[source]

Set up EFT parameter priors and correlations.

set_boost()[source]

Set optimized einsum paths for likelihood calculations.

set_model_cache()[source]

Cache model power spectra for re-use or diagnostics.

get_chi2_marg()[source]

Compute chi-squared with analytical marginalization over linear parameters.

get_chi2_non_marg()[source]

Compute standard non-marginalized chi-squared.

get_chi2_for_hessian()[source]

Compute chi-squared specifically for Hessian calculation.

get_prior()[source]

Compute log-prior for non-marginalized EFT parameters.

get_alpha_bao_rec()[source]

Calculate alpha parameters for BAO reconstruction.

set_bao_rec()[source]

Add BAO reconstruction alphas to theory vector.

get_loop()[source]

Calculate loop corrections and create appropriate precision matrix.

loglkl()[source]

Main method to compute log-likelihood for given parameters.

get_eft_parameters()[source]

Retrieve current values of all EFT parameters.

set_out()[source]

Store output results for writing.

write()[source]

Write results to output files using io handler.

set_data()[source]
set_config(verbose=True)[source]
set_class_settings()[source]
set_eft_parameters()[source]
set_boost()[source]
get_chi2_marg(Tng_k, Tg_bk, P)[source]
get_chi2_non_marg(T_k, P, T_k_2=None)[source]

Standard non-marginalized chi2

get_chi2_for_hessian(T_k, P, T_k_2=None, hessian_type='H')[source]
get_prior(b_sky)[source]

Prior

get_alpha_bao_rec(class_engine, i_sky=0)[source]
set_bao_rec(alphas, Tng_k, Tg_bk=None)[source]
get_loop(b_sky, sky='sky', i_sky=0, marg=False)[source]
loglkl(free_b, free_b_name, cosmo_engine=None, cosmo_module='class', need_cosmo_update=True, cosmo_dict=None, hessian_type=None)[source]

Compute the log-likelihood for a given set of EFT parameters.

This method is the core function that calculates the log-likelihood given a set of EFT parameters while handling cosmological dependencies. It reconstructs theory predictions, calculates chi-squared values (marginalized or non-marginalized), and computes prior contributions.

Parameters:
  • free_b (ndarray) – Array of free EFT parameters, potentially including rs_marg parameter at the beginning followed by parameters for each sky patch.

  • free_b_name (list) – List of names corresponding to free_b parameters.

  • cosmo_engine (object, optional) – Boltzmann solver instance (CLASS, CPJ, or Symbolic). Defaults to None.

  • cosmo_module (str, optional) – Type of cosmology calculation (‘class’, ‘taylor’, etc.). Defaults to ‘class’.

  • need_cosmo_update (bool, optional) – Whether to update cosmological quantities. Defaults to True.

  • cosmo_dict (dict, optional) – Dictionary of precomputed cosmological quantities. Defaults to None.

  • hessian_type (str, optional) – Type of Hessian calculation (‘H’, ‘F’, or ‘FH’). Defaults to None.

Returns:

Log-likelihood value (including priors).

Return type:

float

Notes

  • The free_b array is reshaped into per-sky parameters after extracting any global parameters like alpha_rs if with_rs_marg is True.

  • For marginalized likelihood, parameters specified in bg_name are analytically marginalized over using Gaussian priors.

  • When get_maxlkl is True, the marginalized parameters are calculated and stored.

  • BAO reconstruction alphas are included if with_bao_rec is True.

  • Loop corrections are included if with_loop_prior is True.

get_eft_parameters()[source]
set_model_cache()[source]
set_out(y_arr, chi2, eft_parameters, M=None, i_sky=0)[source]
write()[source]
pybird.likelihood.get_corr(N=1, eps_12=0.1, eps_13=0.2)[source]