Likelihood (mesmer.likelihood
)¶
This module contains the main likelihood object of the package.
mesmer.likelihood.LogProb
. This object is initialized by
providing a set of observed data and its covariance, and specifying
a model.
-
class
mesmer.likelihood.
LogProb
(data=None, covariance=None, frequencies=None, model=None)[source] [edit on github]¶ Bases:
object
Class calculating the marginalize posterior of spectral parameters given some observed data, its covariance, and a model for the emission of different components. This class links together the functions required to calculate the terms in Equation (A7) of 1608.00551.
The setup of this class requires the observed multifrequency sky maps, their pixel covariance (assumed diagonal in pixel space), the SED matrix (instance of
mesmer.FMatrix
), a dictionary containing the fixed parameter and their values, and a set of priors, which tell the likelihood which parameters are to be let vary.- Parameters
- data: ndarray
Array of shape (Nfreq, Npol, Npix) containing the observed multi-frequency data.
- covariance: ndarray
Array of shape (Nfreq, Npol, Npix) containing the pixel covariance of the array
data
.- fmatrix: object, :class:`mesmer.FMatrix`
Instance of
mesmer.FMatrix
that defines the component scaling in the fitted sky model.- fixed_parameters: dict
Dictionary, where key, value pairs correspond to parameter names and values to be fixed.
- priors: dict
Dictionary, where key, value pairs correpsond to which parameters are allowed to vary, and the corresponding mean and standard deviation of the Gaussian prior.
-
get_amplitdue_covariance
(theta, component=None)[source] [edit on github]¶ Convenience function to return the component covariances,
N_T_inv
, for a given set of spectral parameters.
-
get_amplitude_expectation
(theta, component=None)[source] [edit on github]¶ Convenience function to return the component-separated expected amplitudes,
T_bar
, taking care of the relevant reshaping.
-
load_data_from_hdf5
(fpath, mc=0)[source] [edit on github]¶ Method to instantiate data attributes using data saved in an HDF5 archive.
- Parameters
- fpath: str, Path
Path to the hdf5 archive.
- record: str
Record in which the data is stored. This could be the name of the group in which the datasets are saved.
-
classmethod
load_data_from_hdf5_batch
(fpath, model=None)[source] [edit on github]¶ Method to instantiate data attrib utes using data saved in an HDF5 archive. Note that a simpler structure for this method would place the for loop within a single opening of the hdf5 file. However, this hogs the resource, and we want to be able to write to this file from other processes.
- Parameters
- fpath: str, Path
Path to the hdf5 archive.
- model: Path (optional, default=None)
If specified, this is a path to a yaml file containing an SED model specification.
- Returns
mesmer.likelihood.LogProb
Instantiated
mesmer.likelihood.LogProb
object.
-
classmethod
load_model_from_yaml
(fpath)[source] [edit on github]¶ Method to load a model configuration from a
yaml
file.
-
model_setup
(model)[source] [edit on github]¶ Function to parse the model definition dictionary.
The first level of the dictionary has keys corresponding to the different components, and must match one of the functions in
mesmer.seds
. The values of the keys are dictionaries withfixed
andvaried
keywords. These contain further dictionaries with fixed parameter name / value pairs, and free parameter prior name / pairs.- Parameters
- model: dict
Dictionary defining model.
-
theta_0
(npoints=None, seed=7837)[source] [edit on github]¶ Function to generate a starting guess for optimization or sampling by drawing a random point from the prior.
- Parameters
- npoints: int (optional, default=None)
If npoints is not None, function returns an array of draws from the prior of dimension (npoints, ndim). This can be useful for initializing a set of optimization runs, or samplers.
- seed: int (optional, default=7837)
Seed for the PRNG key used by
jax
.jax
has a subtly different approach to random number generation to numpy. Worth reading about this before setting this number.
- Returns
- ndarray
Array of length the number of free parameters.