Cosmological likelihoods (likelihoods
)¶
Construct likelihoods from Spherical Fourier coefficients and Cartesian power spectrum multipoles of random fields for cosmological parameter inference.
Probability distributions¶
|
Compute the complex normal probability density function or its natural logarithm given the zero-centred data vector and its covariance matrix. |
|
Compute the multivariate normal probability density function or its natural logarithm given the data vector, its mean vector and covariance matrix. |
|
Compute the multivariate modified Student probability density function or its natural logarithm given the data vector, its mean vector and covariance matrix. |
Likelihood inference¶
|
Compute the parametrised covariance matrix of spherical Fourier coefficients. |
|
Compute the parametrised mean and covariance of Cartesian power spectrum multipoles. |
|
Construct the logarithmic likelihood function from cosmological data. |
- harmonia.reader.likelihoods.chi_square(data_vector, covariance_matrix)[source]¶
Calculate chi-square from zero-centred data vector and its covariance matrix.
- Parameters:
data_vector (complex, array_like) – Zero-centred data vector.
covariance_matrix (complex, array_like) – Covariance matrix.
- Returns:
chi_sq – Chi-square value.
- Return type:
float
numpy.ndarray
- harmonia.reader.likelihoods.complex_normal_pdf(data_vector, covariance_matrix, ret_log=True, downscale=None)[source]¶
Compute the complex normal probability density function or its natural logarithm given the zero-centred data vector and its covariance matrix.
- Parameters:
data_vector (complex, array_like) – Zero-centred data vector.
covariance_matrix (complex, array_like) – Covariance matrix.
ret_log (bool, optional) – If True (default), return logarithmic probability density.
downscale (float or None, optional) – If not None (default), the data vector and covariance matrix are simultaneous downscaled to avoid numerical issue.
- Returns:
(Logarithmic) probability density.
- Return type:
float, array_like
- harmonia.reader.likelihoods.multivariate_normal_pdf(data_vector, expectation_vector, covariance_matrix, ret_log=True)[source]¶
Compute the multivariate normal probability density function or its natural logarithm given the data vector, its mean vector and covariance matrix.
- Parameters:
data_vector (float, array_like) – Data vector.
expectation_vector (float, array_like) – Mean vector.
covariance_matrix (float, array_like) – Covariance matrix.
ret_log (bool, optional) – If True (default), return logarithmic probability density.
- Returns:
density – Logarithmic probability density value.
- Return type:
float, array_like
- harmonia.reader.likelihoods.modified_student_pdf(data_vector, expectation_vector, covariance_matrix, degree, ret_log=True)[source]¶
Compute the multivariate modified Student probability density function or its natural logarithm given the data vector, its mean vector and covariance matrix.
- Parameters:
data_vector (float, array_like) – Data vector.
expectation_vector (float, array_like) – Mean vector.
covariance_matrix (float, array_like) – Covariance matrix.
degree (int) – The degree number. This could be the number of empirical covariance matrices used to obtain the estimated covariance_matrix.
ret_log (bool, optional) – If True (default), return logarithmic probability density.
- Returns:
(Logarithmic) probability density value.
- Return type:
float, array_like
- harmonia.reader.likelihoods.spherical_covariance(pivot, spherical_model, **kwargs)[source]¶
Compute the parametrised covariance matrix of spherical Fourier coefficients.
- Parameters:
pivot ({‘natural’, ‘spectral’}) – Pivot order for vectorisation.
spherical_model (
SphericalCorrelator
) – Spherical correlator base model.**kwargs – Parameters (other than pivot) to be passed to
correlator_matrix()
of spherical_correlator.
- Returns:
covariance_matrix – Covariance matrix.
- Return type:
complex
numpy.ndarray
See also
- harmonia.reader.likelihoods.cartesian_moments(pivot, orders, cartesian_model, covariance_estimator=None, mode_counts=None, **kwargs)[source]¶
Compute the parametrised mean and covariance of Cartesian power spectrum multipoles.
- Parameters:
pivot ({‘order’, ‘wavenumber’}) – Pivot order for vectorisation.
orders (list of int) – Orders of the power spectrum multipoles.
cartesian_model (
CartesianMultipoles
) – Cartesian power multipoles base model.covariance_estimator (
CovarianceEstimator
or None, optional) – Cartesian power multipole covariance estimator. Itswavenumbers
must match wavenumbers associated with cartesian_model. If None, no correlation between power spectrum multipoles is assumed but mode_counts must be provided for calculating the power spectrum variance.mode_counts (int, array_like or None, optional) – Number of independent modes for each power spectrum measurement (default is None) used to calculate the power spectrum variance. Ignored if covariance_estimator is provided.
**kwargs – Parameters (other than orders) to be passed to
convolved_power_multipoles()
of cartesian_model.
- Returns:
expectation (float
numpy.ndarray
) – Power spectrum expectation at the specified wavenumbers.covariance (float
numpy.ndarray
) – Power spectrum variance at the specified wavenumbers.
- class harmonia.reader.likelihoods.LogLikelihood(spherical_data=None, cartesian_data=None, covariance_estimator=None, mode_counts=None, base_spherical_model=None, base_cartesian_model=None, spherical_pivot='natural', cartesian_pivot='order', nbar=None, contrast=None, tracer_p=1.0, comm=None)[source]¶
Construct the logarithmic likelihood function from cosmological data.
- Parameters:
spherical_data (
SphericalArray
or None, optional) – Spherical Fourier coefficient data (default is None).cartesian_data (
CartesianArray
or None, optional) – Spherical Fourier coefficient data (default is None).covariance_estimator (
CovarianceEstimator
or None, optional) – Cartesian multipole covariance estimator (default is None).mode_counts (int, array_like or None, optional) – Number of independent modes for each Cartesian data point (default is None) as an alternative to covariance_estimator. Ignored if covariance_estimator is provided.
base_spherical_model (
SphericalCorrelator
or None, optional) – Baseline spherical correlator model (default is None).base_cartesian_model (
CartesianMultipoles
or None, optional) – Baseline Cartesian multipole model (default is None).spherical_pivot ({‘natural’, ‘spectral’}, optional) – Pivot order for spherical map data vectorisation (default is ‘natural’).
cartesian_pivot ({‘order’, ‘wavenumber’}, optional) – Pivot order for Cartesian map data vectorisation (default is ‘order’).
nbar (float or None, optional) – Mean particle number density (in cubic \(h\)/Mpc). If None (default), shot noise is neglected.
contrast (float or None, optional) – If not None (default), this adds additional shot noise level
1 / (contrast * nbar)
due to a FKP-style random catalogue.tracer_p (float, optional) – Tracer-dependent parameter for bias modulation by f_nl (default is 1.).
comm (
mpi4py.MPI.Comm
or None, optional) – MPI communicator (default is None).
- Variables:
attrs (dict) – Directory holding input parameters not corresponding to any of the following attributes.
spherical_data (
SphericalArray
or None) – Spherical Fourier coefficient data.cartesian_data (
CartesianArray
or None) – Spherical Fourier coefficient data.covariance_estimator (
CovarianceEstimator
or None) – Cartesian multipole covariance estimator.base_spherical_model (
SphericalCorrelator
or None) – Baseline spherical correlator model.base_cartesian_model (
CartesianMultipoles
or None) – Baseline Cartesian multipole model.
- spherical_map_likelihood(b_1, f_nl, exclude_degrees=(), compression_matrix=None, **kwargs)[source]¶
Evaluate the spherical map logarithmic likelihood.
- Parameters:
b_1 (float) – Scale-independent linear bias.
f_nl (float or None) – Local primordial non-Gaussianity.
exclude_degrees (tuple of int, optional) – If not empty (default), modes whose spherical degree match one of its elements are removed from the likelihood.
compression_matrix (
numpy.ndarray
or None, optional) – If not None (default), both the data vector and the model covariance matrix are processed for data compression. This must be compatible with exclude_degrees, i.e. it accounts for elements removed from the data vector and covariance matrix by exclude_degrees.**kwargs – Additional parameters to be passed to
correlator_matrix()
ofbase_spherical_model
.
- Returns:
log_likelihood – Logarithmic likelihood.
- Return type:
- cartesian_map_likelihood(b_1, f_nl, orders=None, num_samples=None, **kwargs)[source]¶
Evaluate the Cartesian map logarithmic likelihood.
- Parameters:
b_1 (float) – Scale-independent linear bias of the tracer particles.
f_nl (float or None) – Local primordial non-Gaussianity.
orders (list of int or None, optional) – Orders of the power spectrum multipoles. If None (default), only the monopole is used.
num_samples (int or None, optional) – If None (default), the normal distribution is used without correction for covariance estimation uncertainty; otherwise it is passed as degree to
modified_student_pdf()
for covariance estimation uncertainty correction [1].**kwargs – Additional parameters to be passed to
convolved_power_multipoles()
ofbase_cartesian_model
.
- Returns:
log_likelihood – Logarithmic likelihood.
- Return type: