firecrown.likelihood.gaussfamily ================================ .. py:module:: firecrown.likelihood.gaussfamily .. autoapi-nested-parse:: Support for the family of Gaussian likelihoods. Attributes ---------- .. autoapisummary:: firecrown.likelihood.gaussfamily.T firecrown.likelihood.gaussfamily.P Classes ------- .. autoapisummary:: firecrown.likelihood.gaussfamily.State firecrown.likelihood.gaussfamily.GaussFamily Functions --------- .. autoapisummary:: firecrown.likelihood.gaussfamily.enforce_states Module Contents --------------- .. py:class:: State Bases: :py:obj:`enum.Enum` .. autoapi-inheritance-diagram:: firecrown.likelihood.gaussfamily.State :parts: 1 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. .. py:attribute:: INITIALIZED :value: 1 .. py:attribute:: READY :value: 2 .. py:attribute:: UPDATED :value: 3 .. py:attribute:: COMPUTED :value: 4 .. py:data:: T .. py:data:: P .. py:function:: enforce_states(*, initial, terminal = None, failure_message) 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. :param initial: The initial states allowable for the wrapped method :param terminal: The terminal state ensured for the wrapped method. None indicates no state change happens. :param failure_message: The failure message for the AssertionError raised :return: The wrapped method .. py:class:: GaussFamily(statistics) Bases: :py:obj:`firecrown.likelihood.likelihood.Likelihood` .. autoapi-inheritance-diagram:: firecrown.likelihood.gaussfamily.GaussFamily :parts: 1 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, :meth:`read` must be called before any other method in the interface. 2. after :meth:`read` has been called it is legal to call :meth:`get_data_vector`, or to call :meth:`update`. 3. after :meth:`update` is called it is then legal to call :meth:`calculate_loglike` or :meth:`get_data_vector`, or to reset the object (returning to the pre-update state) by calling :meth:`reset`. It is also legal to call :meth:`compute_theory_vector`. 4. after :meth:`compute_theory_vector` is called it is legal to call :meth:`get_theory_vector` to retrieve the already-calculated theory vector. This state machine behavior is enforced through the use of the decorator :meth:`enforce_states`, above. .. py:attribute:: state :type: State .. py:attribute:: statistics :type: firecrown.updatable.UpdatableCollection[firecrown.likelihood.statistic.GuardedStatistic] .. py:attribute:: cov :type: None | numpy.typing.NDArray[numpy.float64] :value: None .. py:attribute:: cholesky :type: None | numpy.typing.NDArray[numpy.float64] :value: None .. py:attribute:: inv_cov :type: None | numpy.typing.NDArray[numpy.float64] :value: None .. py:attribute:: cov_index_map :type: None | dict[int, int] :value: None .. py:attribute:: theory_vector :type: None | numpy.typing.NDArray[numpy.double] :value: None .. py:attribute:: data_vector :type: None | numpy.typing.NDArray[numpy.double] :value: None .. py:method:: create_ready(statistics, covariance) :classmethod: Create a GaussFamily object in the READY state. :param statistics: A list of statistics to be include in chisquared calculations :param covariance: The covariance matrix of the statistics :return: A ready GaussFamily object .. py:method:: read(sacc_data) Read the covariance matrix for this likelihood from the SACC file. :param sacc_data: The SACC data object to be read .. py:method:: get_cov(statistic = None) Gets the current covariance matrix. :param statistic: The statistic for which the sub-covariance matrix should be returned. If not specified, return the covariance of all statistics. :return: The covariance matrix (or portion thereof) .. py:method:: get_data_vector() Get the data vector from all statistics in the right order. :return: The data vector .. py:method:: compute_theory_vector(tools) Computes the theory vector using the current instance of pyccl.Cosmology. :param tools: Current ModelingTools object :return: The computed theory vector .. py:method:: get_theory_vector() Get the already-computed theory vector from all statistics. :return: The theory vector, with all statistics in the right order .. py:method:: compute(tools) Calculate and return both the data and theory vectors. This method is deprecated and will be removed in a future version of Firecrown. :param tools: the ModelingTools to be used in the calculation of the theory vector :return: a tuple containing the data vector and the theory vector .. py:method:: compute_chisq(tools) Calculate and return the chi-squared for the given cosmology. :param tools: the ModelingTools to be used in the calculation of the theory vector :return: the chi-squared .. py:method:: get_sacc_indices(statistic = None) 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. :param statistics: The statistic or list of statistics for which the SACC indices are desired :return: The SACC indices .. py:method:: make_realization(sacc_data, add_noise = True, strict = True) Create a new realization of the model. :param sacc_data: The SACC data object containing the covariance matrix to be read :param add_noise: If True, add noise to the realization. :param strict: If True, check that the indices of the realization cover all the indices of the SACC data object. :return: The SACC data object containing the new realization