firecrown.likelihood.gaussfamily

Support for the family of Gaussian likelihoods.

Attributes

T

P

Classes

State

The states used in GaussFamily.

GaussFamily

GaussFamily is the base class for likelihoods based on a chi-squared calculation.

Functions

enforce_states(*, initial[, terminal])

This decorator wraps a method, and enforces state machine behavior.

Module Contents

class firecrown.likelihood.gaussfamily.State[source]

Bases: enum.Enum

Inheritance diagram of firecrown.likelihood.gaussfamily.State

The states used in GaussFamily.

GaussFamily and all subclasses enforce a state machine behavior based on these states to ensure that the necessary initialization and setup is done in the correct order.

INITIALIZED = 1
READY = 2
UPDATED = 3
COMPUTED = 4
firecrown.likelihood.gaussfamily.T
firecrown.likelihood.gaussfamily.P
firecrown.likelihood.gaussfamily.enforce_states(*, initial, terminal=None, failure_message)[source]

This decorator wraps a method, and enforces state machine behavior.

If the object is not in one of the states in initial, an AssertionError is raised with the given failure_message. If terminal is None the state of the object is not modified. If terminal is not None and the call to the wrapped method returns normally the state of the object is set to terminal.

Parameters:
  • initial (State | list[State]) – The initial states allowable for the wrapped method

  • terminal (None | State) – The terminal state ensured for the wrapped method. None indicates no state change happens.

  • failure_message (str) – The failure message for the AssertionError raised

Returns:

The wrapped method

Return type:

collections.abc.Callable[[collections.abc.Callable[P, T]], collections.abc.Callable[P, T]]

class firecrown.likelihood.gaussfamily.GaussFamily(statistics)[source]

Bases: firecrown.likelihood.likelihood.Likelihood

Inheritance diagram of firecrown.likelihood.gaussfamily.GaussFamily

GaussFamily is the base class for likelihoods based on a chi-squared calculation.

It provides an implementation of Likelihood.compute_chisq. Derived classes must implement the abstract method compute_loglike, which is inherited from Likelihood.

GaussFamily (and all classes that inherit from it) must abide by the the following rules regarding the order of calling of methods.

  1. after a new object is created, read() must be called before any other method in the interface.

  2. after read() has been called it is legal to call get_data_vector(), or to call update().

  3. after update() is called it is then legal to call calculate_loglike() or get_data_vector(), or to reset the object (returning to the pre-update state) by calling reset(). It is also legal to call compute_theory_vector().

  4. after compute_theory_vector() is called it is legal to call get_theory_vector() to retrieve the already-calculated theory vector.

This state machine behavior is enforced through the use of the decorator enforce_states(), above.

Parameters:

statistics (collections.abc.Sequence[firecrown.likelihood.statistic.Statistic])

state: State
statistics: firecrown.updatable.UpdatableCollection[firecrown.likelihood.statistic.GuardedStatistic]
cov: None | numpy.typing.NDArray[numpy.float64] = None
cholesky: None | numpy.typing.NDArray[numpy.float64] = None
inv_cov: None | numpy.typing.NDArray[numpy.float64] = None
cov_index_map: None | dict[int, int] = None
theory_vector: None | numpy.typing.NDArray[numpy.double] = None
data_vector: None | numpy.typing.NDArray[numpy.double] = None
classmethod create_ready(statistics, covariance)[source]

Create a GaussFamily object in the READY state.

Parameters:
  • statistics (collections.abc.Sequence[firecrown.likelihood.statistic.Statistic]) – A list of statistics to be include in chisquared calculations

  • covariance (numpy.typing.NDArray[numpy.float64]) – The covariance matrix of the statistics

Returns:

A ready GaussFamily object

Return type:

GaussFamily

read(sacc_data)[source]

Read the covariance matrix for this likelihood from the SACC file.

Parameters:

sacc_data (sacc.Sacc) – The SACC data object to be read

Return type:

None

get_cov(statistic=None)[source]

Gets the current covariance matrix.

Parameters:

statistic (firecrown.likelihood.statistic.Statistic | list[firecrown.likelihood.statistic.Statistic] | None) – The statistic for which the sub-covariance matrix should be returned. If not specified, return the covariance of all statistics.

Returns:

The covariance matrix (or portion thereof)

Return type:

numpy.typing.NDArray[numpy.float64]

get_data_vector()[source]

Get the data vector from all statistics in the right order.

Returns:

The data vector

Return type:

numpy.typing.NDArray[numpy.float64]

compute_theory_vector(tools)[source]

Computes the theory vector using the current instance of pyccl.Cosmology.

Parameters:

tools (firecrown.modeling_tools.ModelingTools) – Current ModelingTools object

Returns:

The computed theory vector

Return type:

numpy.typing.NDArray[numpy.float64]

get_theory_vector()[source]

Get the already-computed theory vector from all statistics.

Returns:

The theory vector, with all statistics in the right order

Return type:

numpy.typing.NDArray[numpy.float64]

compute(tools)[source]

Calculate and return both the data and theory vectors.

This method is deprecated and will be removed in a future version of Firecrown.

Parameters:

tools (firecrown.modeling_tools.ModelingTools) – the ModelingTools to be used in the calculation of the theory vector

Returns:

a tuple containing the data vector and the theory vector

Return type:

tuple[numpy.typing.NDArray[numpy.float64], numpy.typing.NDArray[numpy.float64]]

compute_chisq(tools)[source]

Calculate and return the chi-squared for the given cosmology.

Parameters:

tools (firecrown.modeling_tools.ModelingTools) – the ModelingTools to be used in the calculation of the theory vector

Returns:

the chi-squared

Return type:

float

get_sacc_indices(statistic=None)[source]

Get the SACC indices of the statistic or list of statistics.

If no statistic is given, get the indices of all statistics of the likelihood.

Parameters:
Returns:

The SACC indices

Return type:

numpy.typing.NDArray[numpy.int64]

make_realization(sacc_data, add_noise=True, strict=True)[source]

Create a new realization of the model.

Parameters:
  • sacc_data (sacc.Sacc) – The SACC data object containing the covariance matrix to be read

  • add_noise (bool) – If True, add noise to the realization.

  • strict (bool) – If True, check that the indices of the realization cover all the indices of the SACC data object.

Returns:

The SACC data object containing the new realization

Return type:

sacc.Sacc