imagine.priors package

Submodules

imagine.priors.basic_priors module

class imagine.priors.basic_priors.FlatPrior(interval=[0, 1])[source]

Bases: imagine.priors.prior.GeneralPrior

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

No initialization is required.

__call__(cube)[source]

Return variable value as it is

Parameters:cube (list) – List of variable values in range [0,1]
Returns:
Return type:List of variable values in range [0,1]
class imagine.priors.basic_priors.GaussianPrior(mu=0.0, sigma=1.0, interval=[-1.0, 1.0])[source]

Bases: imagine.priors.prior.ScipyPrior

Truncated normal prior 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)
  • interval (tuple or list) – A pair of points representing, respectively, the minimum and maximum parameter values to be considered.

imagine.priors.prior module

class imagine.priors.prior.GeneralPrior(samples=None, pdf_fun=None, pdf_x=None, pdf_y=None, interval=None, bw_method=None, pdf_npoints=1500, inv_cdf_npoints=1500)[source]

Bases: object

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

Like in MultiNest, priors here are represented by a mapping of uniformly distributed scaled parameter values into a distribution with the desired properties (i.e. following the expected PDF). Such mapping is equivalent to the inverse of the cumulative distribution function (CDF) associated with the prior distribution.

Notes

Here we make a summary of the algorithm that allows finding the inverse of the CDF (and therefore, a IMAGINE prior) from a set of samples or PDF. (1) If set of samples is provided, computes Kernel Density Estimate (KDE) representation of it using Gaussian kernels. (2) The KDE is evaluated on pdf_npoints and thi si used to construct a interpolated cubic spline, which can be inspected through the method pdf(). (4) From PDF spline, the CDF is computed, which can be accessed using cdf(). (5) The CDF is evaluated on inv_cdf_npoints, and the inverse of the CDF is, again, constructed as a interpolated cubic spline. The spline object is available at inv_cdf().

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 associated with this prior. If an no interval is provided, the domain of PDF(x) will be assumed to be within the interval [0,1].
  • pdf_x, pdf_y (array_like) – The PDF can be provided as two arrays of points following (pdf_x, pdf_y) = (x, PDF(x)). In the absence of an interval, the interval [min(pdf_x), max(pdf_x)] will be used.
  • interval (tuple or list) – A pair of points representing, respectively, the minimum and maximum parameter values to be considered.
  • 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.
  • inv_cdf_npoints (int) – Number of points used to evaluate the CDF for the calculation of its inverse.
__call__(x)[source]

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

pdf_unscaled(x)[source]

Probability density function (PDF) associated with this prior.

cdf

Cumulative distribution function (CDF) associated with this prior.

inv_cdf

Inverse of the CDF associated with this prior, expressed as a scipy.interpolate.CubicSpline object.

pdf

Probability density function (PDF) associated with this prior.

class imagine.priors.prior.ScipyPrior(distr, *args, loc=0.0, scale=1.0, interval=[-1.0, 1.0], **kwargs)[source]

Bases: imagine.priors.prior.GeneralPrior

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.stats.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).
  • interval (tuple or list) – A pair of points representing, respectively, the minimum and maximum parameter values to be considered (will be used to rescale the interval).

Module contents

class imagine.priors.FlatPrior(interval=[0, 1])[source]

Bases: imagine.priors.prior.GeneralPrior

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

No initialization is required.

__call__(cube)[source]

Return variable value as it is

Parameters:cube (list) – List of variable values in range [0,1]
Returns:
Return type:List of variable values in range [0,1]
class imagine.priors.GaussianPrior(mu=0.0, sigma=1.0, interval=[-1.0, 1.0])[source]

Bases: imagine.priors.prior.ScipyPrior

Truncated normal prior 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)
  • interval (tuple or list) – A pair of points representing, respectively, the minimum and maximum parameter values to be considered.
class imagine.priors.GeneralPrior(samples=None, pdf_fun=None, pdf_x=None, pdf_y=None, interval=None, bw_method=None, pdf_npoints=1500, inv_cdf_npoints=1500)[source]

Bases: object

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

Like in MultiNest, priors here are represented by a mapping of uniformly distributed scaled parameter values into a distribution with the desired properties (i.e. following the expected PDF). Such mapping is equivalent to the inverse of the cumulative distribution function (CDF) associated with the prior distribution.

Notes

Here we make a summary of the algorithm that allows finding the inverse of the CDF (and therefore, a IMAGINE prior) from a set of samples or PDF. (1) If set of samples is provided, computes Kernel Density Estimate (KDE) representation of it using Gaussian kernels. (2) The KDE is evaluated on pdf_npoints and thi si used to construct a interpolated cubic spline, which can be inspected through the method pdf(). (4) From PDF spline, the CDF is computed, which can be accessed using cdf(). (5) The CDF is evaluated on inv_cdf_npoints, and the inverse of the CDF is, again, constructed as a interpolated cubic spline. The spline object is available at inv_cdf().

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 associated with this prior. If an no interval is provided, the domain of PDF(x) will be assumed to be within the interval [0,1].
  • pdf_x, pdf_y (array_like) – The PDF can be provided as two arrays of points following (pdf_x, pdf_y) = (x, PDF(x)). In the absence of an interval, the interval [min(pdf_x), max(pdf_x)] will be used.
  • interval (tuple or list) – A pair of points representing, respectively, the minimum and maximum parameter values to be considered.
  • 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.
  • inv_cdf_npoints (int) – Number of points used to evaluate the CDF for the calculation of its inverse.
__call__(x)[source]

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

pdf_unscaled(x)[source]

Probability density function (PDF) associated with this prior.

cdf

Cumulative distribution function (CDF) associated with this prior.

inv_cdf

Inverse of the CDF associated with this prior, expressed as a scipy.interpolate.CubicSpline object.

pdf

Probability density function (PDF) associated with this prior.

class imagine.priors.ScipyPrior(distr, *args, loc=0.0, scale=1.0, interval=[-1.0, 1.0], **kwargs)[source]

Bases: imagine.priors.prior.GeneralPrior

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.stats.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).
  • interval (tuple or list) – A pair of points representing, respectively, the minimum and maximum parameter values to be considered (will be used to rescale the interval).