imagine.priors package

Submodules

imagine.priors.basic_priors module

class imagine.priors.basic_priors.FlatPrior(xmin, xmax, unit=None, wrapped=False)[source]

Bases: imagine.priors.prior.Prior

Prior distribution where any parameter values within the valid interval have the same prior probability.

Parameters:
  • xmin, xmax (float) – A pair of points representing, respectively, the minimum/maximum parameter values to be considered.
  • unit (astropy.units.Unit, optional) – If present, sets the units used for this parameter. If absent, this is inferred from xmin and xmax.
  • wrapped (bool) – Specify whether the parameter is periodic (i.e. the range is supposed to “wrap-around”).
__call__(cube)[source]

The “prior mapping”, i.e. returns the value of the inverse of the CDF at point(s) x.

class imagine.priors.basic_priors.GaussianPrior(mu=None, sigma=None, xmin=None, xmax=None, unit=None, wrapped=False, **kwargs)[source]

Bases: imagine.priors.prior.ScipyPrior

Normal prior distribution.

This can operate either as a regular Gaussian distribution (defined from -infinity to infinity) or, if xmin and xmax values are set, as a trucated Gaussian distribution.

Parameters:
  • mu (float) – The position of the mode (mean, if the truncation is symmetric) of the Gaussian
  • sigma (float) – Width of the distribution (standard deviation, if there was no tuncation)
  • xmin, xmax (float) – A pair of points representing, respectively, the minimum/maximum parameter values to be considered (i.e. the truncation interval). If these are not provided (or set to None), the prior range is assumed to run from -infinity to infinity
  • unit (astropy.units.Unit, optional) – If present, sets the units used for this parameter. If absent, this is inferred from mu and sigma.
  • wrapped (bool) – Specify whether the parameter is periodic (i.e. the range is supposed to “wrap-around”).

imagine.priors.prior module

class imagine.priors.prior.Prior(xmin=None, xmax=None, wrapped=False, unit=None, pdf_npoints=1500)[source]

Bases: imagine.tools.class_tools.BaseClass

This is the base class which can be used to include a new type of prior to the IMAGINE pipeline. If you are willing to use a distribution from scipy, please look at ScipyPrior. If you want to construct a prior from a sample, see CustomPrior.

__call__(x)[source]

The “prior mapping”, i.e. returns the value of the inverse of the CDF at point(s) x.

pdf(x)[source]

Probability density function (PDF) associated with this prior.

cdf

Cumulative distribution function (CDF) associated with this prior.

inv_cdf
scipy_distr

Constructs a scipy distribution based on an IMAGINE prior

class imagine.priors.prior.ScipyPrior(distr, *args, loc=0.0, scale=1.0, xmin=None, xmax=None, unit=None, wrapped=False, pdf_npoints=1500, **kwargs)[source]

Bases: imagine.priors.prior.Prior

Constructs a prior from a continuous distribution defined in scipy.stats.

Parameters:
  • distr (scipy.stats.rv_continuous) – A distribution function expressed as an instance of scipy.stats.rv_continuous.
  • *args – Any positional arguments required by the function selected in distr (e.g for scipy. .chi2, one needs to supply the number of degrees of freedom, df)
  • loc (float) – Same meaning as in scipy.stats.rv_continuous: sets the centre of the distribution (generally, the mean or mode).
  • scale (float) – Same meaning as in scipy.stats.rv_continuous: sets the width of the distribution (e.g. the standard deviation in the normal case).
  • xmin, xmax (float) – A pair of points representing, respectively, the minimum/maximum parameter values to be considered (note that this will truncate the original scipy distribution provided). If these are not provided (or set to None), the prior range is assumed to run from -infinity to infinity (in this case, unit must be provided).
  • unit (astropy.units.Unit) – If present, sets the units used for this parameter. If absent, this is inferred from xmin and xmax.
  • wrapped (bool) – Specify whether the parameter is periodic (i.e. the range is supposed to “wrap-around”).
class imagine.priors.prior.CustomPrior(samples=None, pdf_fun=None, xmin=None, xmax=None, unit=None, wrapped=False, bw_method=None, pdf_npoints=1500, samples_ref=True)[source]

Bases: imagine.priors.prior.Prior

Allows constructing a prior from a pre-existing sampling of the parameter space or a known probability density function (PDF).

Parameters:
  • samples (array_like) – Array containing a sample of the prior distribution one wants to use. Note: this will use scipy.stats.gaussian_kde to compute the probability density function (PDF) through kernel density estimate using Gaussian kernels.
  • pdf_fun (function) – A Python function containing the PDF for this prior. Note that the function must be able to operate on Quantity object if the parameter is not dimensionless.
  • xmin, xmax (float) – A pair of points representing, respectively, the minimum/maximum parameter values to be considered. If not provided (or set to None), the smallest/largest value in the sample minus/plus one standard deviation will be used.
  • unit (astropy.units.Unit) – If present, sets the units used for this parameter. If absent, this is inferred from xmin and xmax.
  • wrapped (bool) – Specify whether the parameter is periodic (i.e. the range is supposed to “wrap-around”).
  • bw_method (scalar or str) – Used by scipy.stats.gaussian_kde to select the bandwidth employed to estimate the PDF from provided samples. Can be a number, if using fixed bandwidth, or strings ‘scott’ or ‘silverman’ if these rules are to be selected.
  • pdf_npoints (int) – Number of points used to evaluate pdf_fun or the KDE constructed from the samples.
  • samples_ref (bool) – If True (default), a reference to the samples is stored, allowing prior correlations to be computed by the Pipeline.

Module contents

class imagine.priors.FlatPrior(xmin, xmax, unit=None, wrapped=False)[source]

Bases: imagine.priors.prior.Prior

Prior distribution where any parameter values within the valid interval have the same prior probability.

Parameters:
  • xmin, xmax (float) – A pair of points representing, respectively, the minimum/maximum parameter values to be considered.
  • unit (astropy.units.Unit, optional) – If present, sets the units used for this parameter. If absent, this is inferred from xmin and xmax.
  • wrapped (bool) – Specify whether the parameter is periodic (i.e. the range is supposed to “wrap-around”).
__call__(cube)[source]

The “prior mapping”, i.e. returns the value of the inverse of the CDF at point(s) x.

class imagine.priors.GaussianPrior(mu=None, sigma=None, xmin=None, xmax=None, unit=None, wrapped=False, **kwargs)[source]

Bases: imagine.priors.prior.ScipyPrior

Normal prior distribution.

This can operate either as a regular Gaussian distribution (defined from -infinity to infinity) or, if xmin and xmax values are set, as a trucated Gaussian distribution.

Parameters:
  • mu (float) – The position of the mode (mean, if the truncation is symmetric) of the Gaussian
  • sigma (float) – Width of the distribution (standard deviation, if there was no tuncation)
  • xmin, xmax (float) – A pair of points representing, respectively, the minimum/maximum parameter values to be considered (i.e. the truncation interval). If these are not provided (or set to None), the prior range is assumed to run from -infinity to infinity
  • unit (astropy.units.Unit, optional) – If present, sets the units used for this parameter. If absent, this is inferred from mu and sigma.
  • wrapped (bool) – Specify whether the parameter is periodic (i.e. the range is supposed to “wrap-around”).
class imagine.priors.Prior(xmin=None, xmax=None, wrapped=False, unit=None, pdf_npoints=1500)[source]

Bases: imagine.tools.class_tools.BaseClass

This is the base class which can be used to include a new type of prior to the IMAGINE pipeline. If you are willing to use a distribution from scipy, please look at ScipyPrior. If you want to construct a prior from a sample, see CustomPrior.

__call__(x)[source]

The “prior mapping”, i.e. returns the value of the inverse of the CDF at point(s) x.

pdf(x)[source]

Probability density function (PDF) associated with this prior.

cdf

Cumulative distribution function (CDF) associated with this prior.

inv_cdf
scipy_distr

Constructs a scipy distribution based on an IMAGINE prior

class imagine.priors.ScipyPrior(distr, *args, loc=0.0, scale=1.0, xmin=None, xmax=None, unit=None, wrapped=False, pdf_npoints=1500, **kwargs)[source]

Bases: imagine.priors.prior.Prior

Constructs a prior from a continuous distribution defined in scipy.stats.

Parameters:
  • distr (scipy.stats.rv_continuous) – A distribution function expressed as an instance of scipy.stats.rv_continuous.
  • *args – Any positional arguments required by the function selected in distr (e.g for scipy. .chi2, one needs to supply the number of degrees of freedom, df)
  • loc (float) – Same meaning as in scipy.stats.rv_continuous: sets the centre of the distribution (generally, the mean or mode).
  • scale (float) – Same meaning as in scipy.stats.rv_continuous: sets the width of the distribution (e.g. the standard deviation in the normal case).
  • xmin, xmax (float) – A pair of points representing, respectively, the minimum/maximum parameter values to be considered (note that this will truncate the original scipy distribution provided). If these are not provided (or set to None), the prior range is assumed to run from -infinity to infinity (in this case, unit must be provided).
  • unit (astropy.units.Unit) – If present, sets the units used for this parameter. If absent, this is inferred from xmin and xmax.
  • wrapped (bool) – Specify whether the parameter is periodic (i.e. the range is supposed to “wrap-around”).
class imagine.priors.CustomPrior(samples=None, pdf_fun=None, xmin=None, xmax=None, unit=None, wrapped=False, bw_method=None, pdf_npoints=1500, samples_ref=True)[source]

Bases: imagine.priors.prior.Prior

Allows constructing a prior from a pre-existing sampling of the parameter space or a known probability density function (PDF).

Parameters:
  • samples (array_like) – Array containing a sample of the prior distribution one wants to use. Note: this will use scipy.stats.gaussian_kde to compute the probability density function (PDF) through kernel density estimate using Gaussian kernels.
  • pdf_fun (function) – A Python function containing the PDF for this prior. Note that the function must be able to operate on Quantity object if the parameter is not dimensionless.
  • xmin, xmax (float) – A pair of points representing, respectively, the minimum/maximum parameter values to be considered. If not provided (or set to None), the smallest/largest value in the sample minus/plus one standard deviation will be used.
  • unit (astropy.units.Unit) – If present, sets the units used for this parameter. If absent, this is inferred from xmin and xmax.
  • wrapped (bool) – Specify whether the parameter is periodic (i.e. the range is supposed to “wrap-around”).
  • bw_method (scalar or str) – Used by scipy.stats.gaussian_kde to select the bandwidth employed to estimate the PDF from provided samples. Can be a number, if using fixed bandwidth, or strings ‘scott’ or ‘silverman’ if these rules are to be selected.
  • pdf_npoints (int) – Number of points used to evaluate pdf_fun or the KDE constructed from the samples.
  • samples_ref (bool) – If True (default), a reference to the samples is stored, allowing prior correlations to be computed by the Pipeline.