# Cosmological theory codes and likelihoods¶

Models in Cosmology are usually split in two: $$\mathcal{M}=\mathcal{T}+\mathcal{E}$$, where

• $$\mathcal{T}$$, the theoretical model, is used to compute observable quantities $$\mathcal{O}$$
• $$\mathcal{E}$$, the experimental model, accounts for instrumental errors, foregrounds… when comparing the theoretical observable with some data $$\mathcal{D}$$.

In practice the theoretical model is encapsulated in a theory code (CLASS, CAMB…) and the experimental model in a likelihood, which gives the probability of the data being a realization of the given observable in the context of the experiment:

$\mathcal{L}\left[\mathcal{D}\,|\,\mathcal{M}\right] = \mathcal{L}\left[\mathcal{D}\,|\,\mathcal{O},\mathcal{E}\right]$

Each iteration of a sampler reproduces the model using the following steps:

1. A new set of theory+experimental parameters is proposed by the sampler.
2. The theory parameters are passed to the theory code, which computes one or more observables.
3. The experimental parameters are passed to each of the likelihoods, which in turn ask the theory code for the current value of the observables they need, and use all of that to compute a log-probability of the data.

cobaya wraps the most popular cosmological codes under a single interface, documented below. The codes themselves are documented in the next sections, followed by the internal likelihoods included in cobaya.

## Cosmological theory code¶

class theories._cosmo._cosmo(info_theory, modules=None, timing=None)
needs(**requirements)

Specifies the quantities that each likelihood needs from the Cosmology code.

Typical requisites in Cosmology (as keywords, case insensitive):

• Cl={...}: CMB lensed power spectra, as a dictionary {spectrum:l_max}, where the possible spectra are combinations of “t”, “e”, “b” and “p” (lensing potential). Get with get_Cl().
• [BETA: CAMB only; notation may change!] source_Cl={...}: $$C_\ell$$ of given sources with given windows, e.g.: source_name: {"function": "spline"|"gaussian", [source_args]; for now, [source_args] follow the notation of CAMBSources. If can also take lmax: [int], limber: True if Limber approximation desired, and non_linear: True if non-linear contributions requested. Get with get_source_Cl().
• Pk_interpolator={...}: Matter power spectrum interpolator in $$(z, k)$$. Takes "z": [list_of_evaluated_redshifts], "k_max": [k_max], "extrap_kmax": [max_k_max_extrapolated], "nonlinear": [True|False], "vars_pairs": [["delta_tot", "delta_tot"], ["Weyl", "Weyl"], [...]]}.
• H={'z': [z_1, ...], 'units': '1/Mpc' or 'km/s/Mpc'}: Hubble rate at the redshifts requested, in the given units. Get it with get_H().
• angular_diameter_distance={'z': [z_1, ...]}: Physical angular diameter distance to the redshifts requested. Get it with get_angular_diameter_distance().
• comoving_radial_distance={'z': [z_1, ...]}: Comoving radial distance from us to the redshifts requested. Get it with get_comoving_radial_distance().
• fsigma8={'z': [z_1, ...]}: Structure growth rate $$f\sigma_8$$ at the redshifts requested. Get it with get_fsigma8().
• k_max=[...]: Fixes the maximum comoving wavenumber considered.
• Other derived parameters that are not included in the input but whose value the likelihood may need.
requested()

Returns the full set of cosmological products and parameters requested by the likelihoods.

get_param(p)

Interface function for likelihoods to get sampled and derived parameters.

Always use this one; don’t try to access theory code attributes directly!

get_Cl(ell_factor=False, units='muK2')

Returns a dictionary of lensed CMB power spectra and the lensing potential pp power spectrum.

Set the units with the keyword units='1'|'muK2'|'K2' (default: ‘muK2’, except for the lensing potential power spectrum, which is always unitless).

If ell_factor=True (default: False), multiplies the spectra by $$\ell(\ell+1)/(2\pi)$$ (or by $$\ell^2(\ell+1)^2/(2\pi)$$ in the case of the lensing potential pp spectrum).

get_H(z, units='km/s/Mpc')

Returns the Hubble rate at the given redshifts.

The redshifts must be a subset of those requested when needs() was called.

The available units are km/s/Mpc (i.e. c*H(Mpc^-1)) and 1/Mpc.

get_angular_diameter_distance(z)

Returns the physical angular diameter distance to the given redshifts.

The redshifts must be a subset of those requested when needs() was called.

get_Pk_interpolator(z)

Returns a (dict of) power spectrum interpolator(s) PowerSpectrumInterpolator.

get_source_Cl()

Returns a dict of power spectra of for the computed sources, with keys a tuple of sources ([source1], [source2]), and an additional key ell containing the multipoles.

get_fsigma8(z)

Structure growth rate $$f\sigma_8$$, as defined in eq. 33 of Planck 2015 results. XIII. Cosmological parameters, at the given redshifts.

The redshifts must be a subset of those requested when needs() was called.

get_auto_covmat(params_info, likes_info)

Tries to get match to a database of existing covariance matrix files for the current model and data.

params_info should contain preferably the slow parameters only.

class theories._cosmo.PowerSpectrumInterpolator(z, k, P_or_logP, extrap_kmax=None, logk=False, logP=False)

2D spline interpolation object (scipy.interpolate.RectBivariateSpline) to evaluate matter power spectrum as function of z and k.

This class is adapted from CAMB’s own P(k) interpolator, by Antony Lewis; it’s mostly interface-compatible with the original.

Parameters: z – values of z for which the power spectrum was evaluated. k – values of k for which the power spectrum was evaluated. P_or_logP – Values of the power spectrum (or log-values, if logP=True). logk – if True (default: False), assumes that k’s are log-spaced. logP – if True (default: False), log of power spectrum are given and used for the underlying interpolator. extrap_kmax – if set, use power law extrapolation beyond kmax up to extrap_kmax; useful for tails of integrals.
P(z, k, grid=None)

Get the power spectrum at (z,k).

logP(z, k, grid=None)

Get the log power spectrum at (z,k).