firecrown.likelihood.gaussfamily
Support for the family of Gaussian likelihoods.
Attributes
Classes
The states used in GaussFamily. |
|
GaussFamily is the base class for likelihoods based on a chi-squared calculation. |
Functions
|
This decorator wraps a method, and enforces state machine behavior. |
Module Contents
- class firecrown.likelihood.gaussfamily.State(*args, **kwds)[source]
Bases:
enum.Enum
The states used in GaussFamily.
GaussFamily and all subclasses enforce a statemachine 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:
- Returns:
The wrapped method
- Return type:
Callable[[Callable[P, T]], Callable[P, T]]
- class firecrown.likelihood.gaussfamily.GaussFamily(statistics)[source]
Bases:
firecrown.likelihood.likelihood.Likelihood
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.
after a new object is created,
read()must be called before any other method in the interfaqce.after
read()has been called it is legal to callget_data_vector(), or to callupdate().after
update()is called it is then legal to callcalculate_loglike()orget_data_vector(), or to reset the object (returning to the pre-update state) by callingreset(). It is also legal to callcompute_theory_vector().after
compute_theory_vector()is called it is legal to callget_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 (Sequence[firecrown.likelihood.statistic.Statistic])
- 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 (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:
- 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 dprecated 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:
statistics – The statistic or list of statistics for which the SACC indices are desired
statistic (firecrown.likelihood.statistic.Statistic | list[firecrown.likelihood.statistic.Statistic] | None)
- 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