Likelihood#

class cosmicjellyfish.likelihood.base.Likelihood(*, cosmo_data, cosmo_theory=None, leg_flag='wedges')[source]#

Bases: ABC

Common interface for likelihood evaluations used in Cosmicjellyfish.

This abstract base class defines the core interface for likelihood calculations in Cosmicjellyfish. It provides methods for computing data representations, theory predictions, and chi-squared values, as well as utilities for parameter handling and running Nautilus samplers.

abstract compute_data()[source]#

Compute and return the observed data representation.

This method should be implemented by subclasses to return the data in the appropriate format (e.g., wedges or multipoles) for likelihood calculations.

Return type:

Any

Returns:

The observed data representation

abstract compute_theory(param_dict)[source]#

Compute and return the theory prediction.

This method should be implemented by subclasses to return the theory prediction in the same representation as the observed data.

Parameters:

param_dict (Dict[str, Any]) – Dictionary of cosmological parameters

Return type:

Any

Returns:

The theory prediction in the same format as the observed data

abstract compute_chi2(theory_obs)[source]#

Compute and return the chi-squared value.

This method should be implemented by subclasses to compute the chi-squared value between the observed data and theory prediction.

Parameters:

theory_obs (Any) – Theory prediction in the same format as observed data

Return type:

float

Returns:

The chi-squared value

build_param_dict(*, param_vec=None, param_dict=None, prior=None)[source]#

Create a parameter dictionary from vector inputs when needed.

This method converts a parameter vector to a dictionary using the prior information, or returns the provided parameter dictionary directly.

Parameters:
  • param_vec (Optional[Iterable[float]], default: None) – Optional iterable of parameter values

  • param_dict (Optional[Dict[str, Any]], default: None) – Optional dictionary of parameters

  • prior (Optional[Any], default: None) – Optional prior information for parameter mapping

Return type:

Dict[str, Any]

Returns:

Dictionary of parameters

Raises:
  • ValueError – If neither param_dict nor (param_vec and prior) are provided

  • TypeError – If param_vec is not an indexable iterable

  • AttributeError – If prior object doesn’t expose an ordered ‘keys’ attribute

loglike(param_vec=None, *, param_dict=None, prior=None)[source]#

Compute the log-likelihood value.

This method computes the log-likelihood value (-0.5 * χ²) for the supplied parameters. It can accept either a parameter vector or a parameter dictionary.

Parameters:
  • param_vec (Optional[Iterable[float]], default: None) – Optional iterable of parameter values

  • param_dict (Optional[Dict[str, Any]], default: None) – Optional dictionary of parameters

  • prior (Optional[Any], default: None) – Optional prior information for parameter mapping

Return type:

float

Returns:

The log-likelihood value (-0.5 * χ²)