imagine.likelihoods package

Submodules

imagine.likelihoods.ensemble_likelihood module

class imagine.likelihoods.ensemble_likelihood.EnsembleLikelihood(measurement_dict, covariance_dict=None, mask_dict=None, cov_func=None, use_trace_approximation=False, **kwargs)[source]

Bases: imagine.likelihoods.likelihood.Likelihood

Computes the likelihood accounting for the effects of stochastic fields

This is done by estimating the covariance associated the stochastic fields from an ensemble of simulations.

Parameters:
  • measurement_dict (imagine.observables.observable_dict.Measurements) – Measurements
  • covariance_dict (imagine.observables.observable_dict.Covariances) – The covariances associated with the measurements. If the keyword argument is absent, the covariances will be read from the attribute measurement_dict.cov.
  • mask_dict (imagine.observables.observable_dict.Masks) – Masks which will be applied to the Measurements, Covariances and Simulations, before computing the likelihood
  • cov_func (func) – A function which takes a (Nens, Ndata) data array (potentially MPI distributed) and returns a tuple comprising the mean and an estimated covariance matrix. If absent, imagine.tools.covariance_estimator.oas_mcov() will be used.
  • use_trace_approximation (bool) – If True, the determinant of the combined covariance matrix is approximated using \(\ln(|A+B)\approx \text{tr}\left[\ln\left(A+C\right)\right]\) (NB this assumes that the observed data covariance is diagonal). Otherwise (default), the determinant is calculated directly from the covariance matrix from the simulations.
call(simulations_dict)[source]

EnsembleLikelihood class call function

Parameters:simulations_dict (imagine.observables.observable_dict.Simulations) – Simulations object
Returns:likelicache – log-likelihood value (copied to all nodes)
Return type:float
class imagine.likelihoods.ensemble_likelihood.EnsembleLikelihoodDiagonal(measurement_dict, covariance_dict=None, mask_dict=None, **kwargs)[source]

Bases: imagine.likelihoods.likelihood.Likelihood

As EnsembleLikelihood but assuming that the covariance matrix is diagonal and well described by the sample variance. Likewise, only considers the diagonal of the observational covariance matrix.

Parameters:
  • measurement_dict (imagine.observables.observable_dict.Measurements) – Measurements
  • covariance_dict (imagine.observables.observable_dict.Covariances) – The covariances associated with the measurements. If the keyword argument is absent, the covariances will be read from the attribute measurement_dict.cov.
  • mask_dict (imagine.observables.observable_dict.Masks) – Masks which will be applied to the Measurements, Covariances and Simulations, before computing the likelihood
call(simulations_dict)[source]

EnsembleLikelihood class call function

Parameters:simulations_dict (imagine.observables.observable_dict.Simulations) – Simulations object
Returns:likelicache – log-likelihood value (copied to all nodes)
Return type:float

imagine.likelihoods.likelihood module

Likelihood class defines likelihood posterior function to be used in Bayesian analysis

member fuctions:

__init__

requires Measurements object Covariances object (optional) Masks object (optional)

call

running LOG-likelihood calculation requires ObservableDict object
class imagine.likelihoods.likelihood.Likelihood(measurement_dict, covariance_dict=None, mask_dict=None, compute_dispersion=False, n_bootstrap=150)[source]

Bases: imagine.tools.class_tools.BaseClass

Base class that defines likelihood posterior function to be used in Bayesian analysis

Parameters:
  • measurement_dict (imagine.observables.observable_dict.Measurements) – A Measurements dictionary containing observational data.
  • covariance_dict (imagine.observables.observable_dict.Covariances) – A Covariances dictionary containing observed covariance data. If set to None (the usual case), the Likelihood will try to find the Covariances in the cov attribute of the supplied measurement_dict.
  • mask_dict (imagine.observables.observable_dict.Masks) – A Masks dictionary which should be applied to the measured and simulated data.
  • compute_dispersion (bool) – If True, calling the Likelihood object will return the likelihood value and the dispersion estimated by bootstrapping the simulations object and computing the sample standard deviation. If False (default), only the likelihood value is returned.
  • n_bootstrap (int) – Number of resamples used in the bootstrapping of the simulations if compute_dispersion is set to True.
__call__(observable_dict, **kwargs)[source]

Call self as a function.

call(observable_dict)[source]
Parameters:
  • observable_dict (imagine.observables.observable_dict)
  • variables
covariance_dict

Covariances dictionary associated with this object

NB If a mask is used, only the masked version is stored

mask_dict

Masks dictionary associated with this object

measurement_dict

Measurements dictionary associated with this object

NB If a mask is used, only the masked version is stored

imagine.likelihoods.simple_likelihood module

class imagine.likelihoods.simple_likelihood.SimpleLikelihood(measurement_dict, covariance_dict=None, mask_dict=None, compute_dispersion=False, n_bootstrap=150)[source]

Bases: imagine.likelihoods.likelihood.Likelihood

A simple Likelihood class

Parameters:
  • measurement_dict (imagine.observables.observable_dict.Measurements) – Measurements
  • covariance_dict (imagine.observables.observable_dict.Covariances) – Covariances
  • mask_dict (imagine.observables.observable_dict.Masks) – Masks
call(simulations_dict)[source]

SimpleLikelihood object call function

Parameters:simulations_dict (imagine.observables.observable_dict.Simulations) – Simulations object
Returns:likelicache – log-likelihood value (copied to all nodes)
Return type:float

Module contents

class imagine.likelihoods.EnsembleLikelihood(measurement_dict, covariance_dict=None, mask_dict=None, cov_func=None, use_trace_approximation=False, **kwargs)[source]

Bases: imagine.likelihoods.likelihood.Likelihood

Computes the likelihood accounting for the effects of stochastic fields

This is done by estimating the covariance associated the stochastic fields from an ensemble of simulations.

Parameters:
  • measurement_dict (imagine.observables.observable_dict.Measurements) – Measurements
  • covariance_dict (imagine.observables.observable_dict.Covariances) – The covariances associated with the measurements. If the keyword argument is absent, the covariances will be read from the attribute measurement_dict.cov.
  • mask_dict (imagine.observables.observable_dict.Masks) – Masks which will be applied to the Measurements, Covariances and Simulations, before computing the likelihood
  • cov_func (func) – A function which takes a (Nens, Ndata) data array (potentially MPI distributed) and returns a tuple comprising the mean and an estimated covariance matrix. If absent, imagine.tools.covariance_estimator.oas_mcov() will be used.
  • use_trace_approximation (bool) – If True, the determinant of the combined covariance matrix is approximated using \(\ln(|A+B)\approx \text{tr}\left[\ln\left(A+C\right)\right]\) (NB this assumes that the observed data covariance is diagonal). Otherwise (default), the determinant is calculated directly from the covariance matrix from the simulations.
call(simulations_dict)[source]

EnsembleLikelihood class call function

Parameters:simulations_dict (imagine.observables.observable_dict.Simulations) – Simulations object
Returns:likelicache – log-likelihood value (copied to all nodes)
Return type:float
class imagine.likelihoods.EnsembleLikelihoodDiagonal(measurement_dict, covariance_dict=None, mask_dict=None, **kwargs)[source]

Bases: imagine.likelihoods.likelihood.Likelihood

As EnsembleLikelihood but assuming that the covariance matrix is diagonal and well described by the sample variance. Likewise, only considers the diagonal of the observational covariance matrix.

Parameters:
  • measurement_dict (imagine.observables.observable_dict.Measurements) – Measurements
  • covariance_dict (imagine.observables.observable_dict.Covariances) – The covariances associated with the measurements. If the keyword argument is absent, the covariances will be read from the attribute measurement_dict.cov.
  • mask_dict (imagine.observables.observable_dict.Masks) – Masks which will be applied to the Measurements, Covariances and Simulations, before computing the likelihood
call(simulations_dict)[source]

EnsembleLikelihood class call function

Parameters:simulations_dict (imagine.observables.observable_dict.Simulations) – Simulations object
Returns:likelicache – log-likelihood value (copied to all nodes)
Return type:float
class imagine.likelihoods.Likelihood(measurement_dict, covariance_dict=None, mask_dict=None, compute_dispersion=False, n_bootstrap=150)[source]

Bases: imagine.tools.class_tools.BaseClass

Base class that defines likelihood posterior function to be used in Bayesian analysis

Parameters:
  • measurement_dict (imagine.observables.observable_dict.Measurements) – A Measurements dictionary containing observational data.
  • covariance_dict (imagine.observables.observable_dict.Covariances) – A Covariances dictionary containing observed covariance data. If set to None (the usual case), the Likelihood will try to find the Covariances in the cov attribute of the supplied measurement_dict.
  • mask_dict (imagine.observables.observable_dict.Masks) – A Masks dictionary which should be applied to the measured and simulated data.
  • compute_dispersion (bool) – If True, calling the Likelihood object will return the likelihood value and the dispersion estimated by bootstrapping the simulations object and computing the sample standard deviation. If False (default), only the likelihood value is returned.
  • n_bootstrap (int) – Number of resamples used in the bootstrapping of the simulations if compute_dispersion is set to True.
__call__(observable_dict, **kwargs)[source]

Call self as a function.

call(observable_dict)[source]
Parameters:
  • observable_dict (imagine.observables.observable_dict)
  • variables
covariance_dict

Covariances dictionary associated with this object

NB If a mask is used, only the masked version is stored

mask_dict

Masks dictionary associated with this object

measurement_dict

Measurements dictionary associated with this object

NB If a mask is used, only the masked version is stored

class imagine.likelihoods.SimpleLikelihood(measurement_dict, covariance_dict=None, mask_dict=None, compute_dispersion=False, n_bootstrap=150)[source]

Bases: imagine.likelihoods.likelihood.Likelihood

A simple Likelihood class

Parameters:
  • measurement_dict (imagine.observables.observable_dict.Measurements) – Measurements
  • covariance_dict (imagine.observables.observable_dict.Covariances) – Covariances
  • mask_dict (imagine.observables.observable_dict.Masks) – Masks
call(simulations_dict)[source]

SimpleLikelihood object call function

Parameters:simulations_dict (imagine.observables.observable_dict.Simulations) – Simulations object
Returns:likelicache – log-likelihood value (copied to all nodes)
Return type:float