gaussian_mixture likelihood
A simple (multi-modal if required) Gaussian mixture likelihood. The pdf is normalized to 1 when integrated over an infinite domain, regardless of the number of modes.
Note
For a simple single-mode Gaussian likelihood, you can use the simpler gaussian likelihood instead, which supports both normalized (default) and unnormalized options via the normalized parameter. See gaussian likelihood for details.
Usage
The mean and covariance matrix for one or more modes must be specified with the options means and covmats respectively. The dimensionality of the likelihood and the number of modes are guessed from this options (if they are consistent to each other).
The following example defines 3 modes in 2 dimensions, and expects two parameters whose
names start with test_ and must be defined in the params block:
likelihood:
gaussian_mixture:
input_params_prefix: test_
means: [ [0.1,0.1],
[0.3,0.3],
[0.4,0.5] ]
covs: [ [[0.01, 0],
[0, 0.05]],
[[0.02, 0.003],
[0.003, 0.01]],
[[0.01, 0],
[0, 0.01]] ]
The option input_params_prefix fixes the parameters that will be understood by this likelihood: it is a special kind of likelihood that can have any number of non-predefined parameters, as long as they start with this prefix. If this prefix is not defined (or defined to an empty string), the likelihood will understand all parameter as theirs. The number of parameters taken as input must match the dimensionality defined by the means and covariance matrices.
Derived parameters can be tracked, as many as sampled parameters times the number of modes,
and they represent the standardized parameters of each of the modes, i.e. those distributed
as \(\mathcal{N}(0,I)\) around each mode (notice that if a mode is close to the
boundary of the prior, you should not expect to recover a unit covariance matrix from the
sample). To track them, add the option derived: True, and they will be identified by a prefix defined by output_params_prefix.
A delay (in seconds) in the likelihood evaluation can be specified with the keyword
delay.
Note
This module also provides functions to generate random means and covariances – see automatic documentation below.
Note
If you want to use a Gaussian likelihood with particular input names, you can specify them explicitly, e.g.:
likelihood:
gaussian_mixture:
means: [[1.04103e-2, 0.02223, 0.1192]]
covs: [[6.8552146e-16, 1.4486860e-12, -1.4105674e-11],
[1.4486860e-12, 2.1344167e-08, -1.1534501e-07],
[-1.4105674e-11, -1.1534501e-07, 1.6977630e-06]]
input_params: ['thetastar', 'ombh2', 'omch2']
output_params: []
The default option values for this likelihood are
# Gaussian mixtures likelihood, normalized
# Means and covmats
means:
covs:
# Weights of the components (default: equal weights)
weights:
# Prefix of parameters names
input_params_prefix: ""
output_params_prefix: ""
# Use derived standardized parameters for each component
derived: False
# Delay in likelihood evaluation
delay: 0 # seconds
Gaussian mixture likelihood class
- class likelihoods.gaussian_mixture.GaussianMixture(info=mappingproxy({}), name=None, timing=None, packages_path=None, initialize=True, standalone=True)
Gaussian likelihood.
- d()
Dimension of the input vector.
- initialize_with_params()
Initializes the gaussian distributions.
- logp(**params_values)
Computes the log-likelihood for a given set of parameters.
Generating random means and covariance matrices
- likelihoods.gaussian_mixture.random_mean(ranges, n_modes=1, mpi_warn=True, random_state=None)
Returns a uniformly sampled point (as an array) within a list of bounds
ranges.The output of this function can be used directly as the value of the option
meanof thelikelihoods.gaussian.If
n_modes>1, returns an array of such points.
- likelihoods.gaussian_mixture.random_cov(ranges, O_std_min=0.01, O_std_max=1, n_modes=1, mpi_warn=True, random_state=None)
Returns a random covariance matrix, with standard deviations sampled log-uniformly from the length of the parameter ranges times
O_std_minandO_std_max, and uniformly sampled correlation coefficients betweenrho_minandrho_max.The output of this function can be used directly as the value of the option
covof thelikelihoods.gaussian.If
n_modes>1, returns a list of such matrices.
- likelihoods.gaussian_mixture.info_random_gaussian_mixture(ranges, n_modes=1, input_params_prefix='', output_params_prefix='', O_std_min=0.01, O_std_max=1, derived=False, mpi_aware=True, random_state=None, add_ref=False)
Wrapper around
random_meanandrandom_covto generate the likelihood and parameter info for a random Gaussian.If
mpi_aware=True, it draws the random stuff only once, and communicates it to the rest of the MPI processes.If
add_ref=True(default: False) adds a reference pdf for the input parameters, provided that the gaussian mixture is unimodal (otherwise raisesValueError).