Log-priors

A number of LogPriors are provided for use in e.g. Bayesian inference.

Example:

p = pints.GaussianLogPrior(mean=0, variance=1)
x = p(0.1)

Overview:

class pints.BetaLogPrior(a, b)[source]

Defines a beta (log) prior with given shape parameters a and b, with pdf

\[f(x|a,b) = \frac{x^{a-1} (1-x)^{b-1}}{\mathrm{B}(a,b)}\]

where \(\mathrm{B}\) is the Beta function. A random variable \(X\) distributed according to this pdf has expectation

\[\mathrm{E}(X)=\frac{a}{a+b}.\]

For example, to create a prior with shape parameters a=5 and b=1, use:

p = pints.BetaLogPrior(5, 1)

Extends LogPrior.

cdf(x)[source]

See LogPrior.cdf().

convert_from_unit_cube(u)

Converts samples u uniformly drawn from the unit cube into those drawn from the prior space, typically by transforming using LogPrior.icdf().

u should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

convert_to_unit_cube(x)

Converts samples from the prior x to be drawn uniformly from the unit cube, typically by transforming using LogPrior.cdf().

x should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

evaluateS1(x)[source]

See LogPDF.evaluateS1().

icdf(p)[source]

See LogPrior.icdf().

mean()[source]

See LogPrior.mean().

n_parameters()[source]

See LogPrior.n_parameters().

sample(n=1)[source]

See LogPrior.sample().

class pints.CauchyLogPrior(location, scale)[source]

Defines a 1-d Cauchy (log) prior with a given location, and scale, with pdf

\[f(x|\text{location}, \text{scale}) = \frac{1}{\pi\;\text{scale} \left[1 + \left(\frac{x-\text{location}}{\text{scale}}\right)^2 \right]}.\]

A random variable distributed according to this pdf has undefined expectation.

For example, to create a prior centered around 0 and a scale of 5, use:

p = pints.CauchyLogPrior(0, 5)

Extends LogPrior.

Parameters:
  • location – The center of the distribution.
  • scale – The scale of the distribution.
cdf(x)[source]

See LogPrior.cdf().

convert_from_unit_cube(u)

Converts samples u uniformly drawn from the unit cube into those drawn from the prior space, typically by transforming using LogPrior.icdf().

u should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

convert_to_unit_cube(x)

Converts samples from the prior x to be drawn uniformly from the unit cube, typically by transforming using LogPrior.cdf().

x should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

evaluateS1(x)[source]

See LogPDF.evaluateS1().

icdf(p)[source]

See LogPrior.icdf().

mean()[source]

See LogPrior.mean().

n_parameters()[source]

See LogPrior.n_parameters().

sample(n=1)[source]

See LogPrior.sample().

class pints.ComposedLogPrior(*priors)[source]

N-dimensional LogPrior composed of one or more other \(N_i\)- dimensional LogPriors, such that \(\sum _i N_i = N\). The evaluation of the composed log-prior assumes the input log-priors are all independent from each other.

For example, a composed log prior

p = pints.ComposedLogPrior(log_prior1, log_prior2, log_prior3),

where log_prior1, log_prior2, and log_prior3 each have dimension 1, 2 and 1, will have dimension 4.

The dimensionality of the individual priors does not have to be the same, i.e. \(N_i\neq N_j\) is allowed.

The input parameters of the ComposedLogPrior have to be ordered in the same way as the individual priors. In the above example the prior may be evaluated by p(x), where:

x = [parameter1_log_prior1, parameter1_log_prior2, parameter2_log_prior2, parameter1_log_prior3].

Extends LogPrior.

cdf(x)[source]

See LogPrior.cdf().

This method only works if the underlying :class:`LogPrior` classes all implement the optional method :class:`LogPDF.cdf().`.

convert_from_unit_cube(u)

Converts samples u uniformly drawn from the unit cube into those drawn from the prior space, typically by transforming using LogPrior.icdf().

u should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

convert_to_unit_cube(x)

Converts samples from the prior x to be drawn uniformly from the unit cube, typically by transforming using LogPrior.cdf().

x should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

evaluateS1(x)[source]

See LogPDF.evaluateS1().

This method only works if the underlying :class:`LogPrior` classes all implement the optional method :class:`LogPDF.evaluateS1().`.

icdf(x)[source]

See LogPrior.icdf().

This method only works if the underlying :class:`LogPrior` classes all implement the optional method :class:`LogPDF.icdf().`.

mean()[source]

See LogPrior.mean().

n_parameters()[source]

See LogPrior.n_parameters().

sample(n=1)[source]

See LogPrior.sample().

class pints.ExponentialLogPrior(rate)[source]

Defines an exponential (log) prior with given rate parameter rate with pdf

\[f(x|\text{rate}) = \text{rate} \; e^{-\text{rate}\;x}.\]

A random variable \(X\) distributed according to this pdf has expectation

\[\mathrm{E}(X)=\frac{1}{\text{rate}}.\]

For example, to create a prior with rate=0.5 use:

p = pints.ExponentialLogPrior(0.5)

Extends LogPrior.

cdf(x)[source]

See LogPrior.cdf().

convert_from_unit_cube(u)

Converts samples u uniformly drawn from the unit cube into those drawn from the prior space, typically by transforming using LogPrior.icdf().

u should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

convert_to_unit_cube(x)

Converts samples from the prior x to be drawn uniformly from the unit cube, typically by transforming using LogPrior.cdf().

x should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

evaluateS1(x)[source]

See LogPDF.evaluateS1().

icdf(p)[source]

See LogPrior.icdf().

mean()[source]

See LogPrior.mean().

n_parameters()[source]

See LogPrior.n_parameters().

sample(n=1)[source]

See LogPrior.sample().

class pints.GammaLogPrior(a, b)[source]

Defines a gamma (log) prior with given shape parameter a and rate parameter b, with pdf

\[f(x|a,b)=\frac{b^a x^{a-1} e^{-bx}}{\mathrm{\Gamma}(a)}.\]

where \(\Gamma\) is the Gamma function. A random variable \(X\) distributed according to this pdf has expectation

\[\mathrm{E}(X)=\frac{a}{b}.\]

For example, to create a prior with shape parameters a=5 and b=1, use:

p = pints.GammaLogPrior(5, 1)

Extends LogPrior.

cdf(x)[source]

See LogPrior.cdf().

convert_from_unit_cube(u)

Converts samples u uniformly drawn from the unit cube into those drawn from the prior space, typically by transforming using LogPrior.icdf().

u should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

convert_to_unit_cube(x)

Converts samples from the prior x to be drawn uniformly from the unit cube, typically by transforming using LogPrior.cdf().

x should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

evaluateS1(x)[source]

See LogPDF.evaluateS1().

icdf(p)[source]

See LogPrior.icdf().

mean()[source]

See LogPrior.mean().

n_parameters()[source]

See LogPrior.n_parameters().

sample(n=1)[source]

See LogPrior.sample().

class pints.GaussianLogPrior(mean, sd)[source]

Defines a 1-d Gaussian (log) prior with a given mean and standard deviation sd, with pdf

\[f(x|\text{mean},\text{sd}) = \frac{1}{\text{sd}\sqrt{2\pi}} \exp\left(-\frac{(x-\text{mean})^2}{2\;\text{sd}^2}\right).\]

A random variable \(X\) distributed according to this pdf has expectation

\[\mathrm{E}(X)=\text{mean}.\]

For example, to create a prior with mean of 0 and a standard deviation of 1, use:

p = pints.GaussianLogPrior(0, 1)

Extends LogPrior.

cdf(x)[source]

See LogPrior.cdf().

convert_from_unit_cube(u)

Converts samples u uniformly drawn from the unit cube into those drawn from the prior space, typically by transforming using LogPrior.icdf().

u should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

convert_to_unit_cube(x)

Converts samples from the prior x to be drawn uniformly from the unit cube, typically by transforming using LogPrior.cdf().

x should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

evaluateS1(x)[source]

See LogPDF.evaluateS1().

icdf(p)[source]

See LogPrior.icdf().

mean()[source]

See LogPrior.mean().

n_parameters()[source]

See LogPrior.n_parameters().

sample(n=1)[source]

See LogPrior.sample().

class pints.HalfCauchyLogPrior(location, scale)[source]

Defines a 1-d half-Cauchy (log) prior with a given location and scale. This is a Cauchy distribution that has been truncated to lie in between \((0,\infty)\), with pdf

\[\begin{split}f(x|\text{location},\text{scale})=\begin{cases}\frac{1}{\pi\; \text{scale}\left(\frac{1}{\pi}\arctan\left(\frac{\text{location}} {\text{scale} }\right)+\frac{1}{2}\right)\left(\frac{(x-\text{location} )^2}{\text{scale}^2}+1\right)},&x>0\\0,&\text{otherwise.}\end{cases}\end{split}\]

A random variable distributed according to this pdf has undefined expectation.

For example, to create a prior centered around 0 and a scale of 5, use:

p = pints.HalfCauchyLogPrior(0, 5)

Extends LogPrior.

Parameters:
  • location – The center of the distribution.
  • scale – The scale of the distribution.
cdf(x)[source]

See LogPrior.cdf().

convert_from_unit_cube(u)

Converts samples u uniformly drawn from the unit cube into those drawn from the prior space, typically by transforming using LogPrior.icdf().

u should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

convert_to_unit_cube(x)

Converts samples from the prior x to be drawn uniformly from the unit cube, typically by transforming using LogPrior.cdf().

x should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

evaluateS1(x)[source]

See LogPDF.evaluateS1().

icdf(p)[source]

See LogPrior.icdf().

mean()[source]

See LogPrior.mean().

n_parameters()[source]

See LogPrior.n_parameters().

sample(n=1)[source]

See LogPrior.sample().

class pints.InverseGammaLogPrior(a, b)[source]

Defines an inverse gamma (log) prior with given shape parameter a and scale parameter b, with pdf

\[\begin{split}f(x|a,b)=\begin{cases}\frac{b^a}{\Gamma(a)}x^{-a-1}\exp \left(-\frac{b}{x}\right),&x>0\\0,&\text{otherwise.}\end{cases}\end{split}\]

where \(\Gamma\) is the Gamma function. A random variable \(X\) distributed according to this pdf has expectation

\[\begin{split}\mathrm{E}(X)=\begin{cases}\frac{b}{a-1},&a>1\\ \text{undefined},&\text{otherwise.}\end{cases}\end{split}\]

For example, to create a prior with shape parameter a=5 and scale parameter b=1, use:

p = pints.InverseGammaLogPrior(5, 1)

Extends LogPrior.

cdf(x)[source]

See LogPrior.cdf().

convert_from_unit_cube(u)

Converts samples u uniformly drawn from the unit cube into those drawn from the prior space, typically by transforming using LogPrior.icdf().

u should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

convert_to_unit_cube(x)

Converts samples from the prior x to be drawn uniformly from the unit cube, typically by transforming using LogPrior.cdf().

x should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

evaluateS1(x)[source]

See LogPDF.evaluateS1().

icdf(p)[source]

See LogPrior.icdf().

mean()[source]

See LogPrior.mean().

n_parameters()[source]

See LogPrior.n_parameters().

sample(n=1)[source]

See LogPrior.sample().

class pints.LogNormalLogPrior(log_mean, scale)[source]

Defines a log-normal (log) prior with a given log_mean and scale scale. The log_mean parameter of a log-normal distribution is the mean of a normal distribution whose random samples, when exponentiated, yield samples from a log-normal distribution. This log-normal distribution has pdf

\[f(x|\text{log_mean},\text{scale}) = \frac{1}{x\;\text{scale} \sqrt{2\pi}}\exp\left(-\frac{(\log x-\text{log_mean})^2}{2\; \text{scale}^2}\right).\]

A random variable \(X\) distributed according to this pdf has expectation

\[\mathrm{E}(X)=\exp\left(\text{log_mean}+\frac{\text{scale}^2}{2} \right).\]

For example, to create a prior with log_mean of 0 and a scale of 1, use:

p = pints.LogNormalLogPrior(0, 1)

Extends LogPrior.

cdf(x)[source]

See LogPrior.cdf().

convert_from_unit_cube(u)

Converts samples u uniformly drawn from the unit cube into those drawn from the prior space, typically by transforming using LogPrior.icdf().

u should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

convert_to_unit_cube(x)

Converts samples from the prior x to be drawn uniformly from the unit cube, typically by transforming using LogPrior.cdf().

x should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

evaluateS1(x)[source]

See LogPDF.evaluateS1().

icdf(p)[source]

See LogPrior.icdf().

mean()[source]

See LogPrior.mean().

n_parameters()[source]

See LogPrior.n_parameters().

sample(n=1)[source]

See LogPrior.sample().

class pints.MultivariateGaussianLogPrior(mean, cov)[source]

Defines a multivariate Gaussian (log) prior with a given mean and covariance matrix cov, with pdf

\[f(x|\text{mean},\text{cov}) = \frac{1}{(2\pi)^{d/2}| \text{cov}|^{1/2}} \exp\left(-\frac{1}{2}(x-\text{mean})' \text{cov}^{-1}(x-\text{mean})\right).\]

A random variable \(X\) distributed according to this pdf has expectation

\[\mathrm{E}(X)=\text{mean}.\]

For example, to create a prior with zero mean and identity covariance, use:

p = pints.MultivariateGaussianLogPrior(
        np.array([0, 0]), np.array([[1, 0],[0, 1]]))

Extends LogPrior.

cdf(x)

Returns the cumulative density function at point(s) x.

x should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

convert_from_unit_cube(u)[source]

Converts a sample u uniformly drawn from the unit cube into one drawn from the prior space, using MultivariateGaussianLogPrior.pseudo_icdf().

convert_to_unit_cube(x)[source]

Converts a sample from the prior x to be drawn uniformly from the unit cube using MultivariateGaussianLogPrior.pseudo_cdf().

evaluateS1(x)[source]

See LogPDF.evaluateS1().

icdf(p)

Returns the inverse cumulative density function at cumulative probability/probabilities p.

p should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

mean()[source]

See LogPrior.mean().

n_parameters()[source]

See LogPrior.n_parameters().

pseudo_cdf(xs)[source]

Calculates a pseudo-cdf for a multivariate Gaussian as described in Feroz et al. (2009) (“Multnest…”). In this approach, a multivariate Gaussian is factorised:

\[\pi(\theta_1,\theta_2,...,\theta_d) = \pi_1(\theta_1) \pi_2(\theta_2|\theta_1)... \pi_d(\theta_d|\theta_1, \theta_2,...,\theta_{d-1})\]

The cdfs we report are then the values for each individual conditional. For example, for the second component, we calculate:

\[u_2 = \int_{-\infty}^{\theta_2} \pi_2(\theta_2|\theta_1)d\theta_2\]

So that we return a vector of cdfs (u_1,u_2,…,u_d). Note that, this function is mainly to facilitate Multinest sampling since the distribution (u_1,u_2,…,u_d) is uniform within the unit cube.

pseudo_icdf(ps)[source]

Calculates a pseudo-icdf for a multivariate Gaussian as described in Feroz et al. (2009) (“Multnest…”). In this approach, a multivariate Gaussian is factorised:

\[\pi(\theta_1,\theta_2,...,\theta_d) = \pi_1(\theta_1) \pi_2(\theta_2|\theta_1)... \pi_d(\theta_d|\theta_1, \theta_2,...,\theta_{d-1})\]

The icdfs we report are then the values for each individual conditional. For example, for the second component, we calculate the theta_2 value that satisfies:

\[u_2 = \int_{-\infty}^{\theta_2} \pi_2(\theta_2|\theta_1)d\theta_2\]

So that we return a vector of icdfs (theta_1,theta_2,…,theta_d) Note that, this function is mainly to facilitate Multinest sampling since the distribution (u_1,u_2,…,u_d) is uniform within the unit cube.

sample(n=1)[source]

See LogPrior.call().

class pints.NormalLogPrior(mean, standard_deviation)[source]

Deprecated alias of GaussianLogPrior.

cdf(x)

See LogPrior.cdf().

convert_from_unit_cube(u)

Converts samples u uniformly drawn from the unit cube into those drawn from the prior space, typically by transforming using LogPrior.icdf().

u should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

convert_to_unit_cube(x)

Converts samples from the prior x to be drawn uniformly from the unit cube, typically by transforming using LogPrior.cdf().

x should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

evaluateS1(x)

See LogPDF.evaluateS1().

icdf(p)

See LogPrior.icdf().

mean()

See LogPrior.mean().

n_parameters()

See LogPrior.n_parameters().

sample(n=1)

See LogPrior.sample().

class pints.StudentTLogPrior(location, df, scale)[source]

Defines a 1-d Student-t (log) prior with a given location, degrees of freedom df, and scale with pdf

\[f(x|\text{location},\text{scale},\text{df})=\frac{\left(\frac{ \text{df}}{\text{df}+\frac{(x-\text{location})^2}{\text{scale}^2}} \right)^{\frac{\text{df}+1}{2}}}{\sqrt{\text{df}}\;\text{scale} \;\mathrm{B}\left(\frac{\text{df} }{2},\frac{1}{2}\right)}.\]

where \(\mathrm{B}\) is the Beta function. A random variable \(X\) distributed according to this pdf has expectation

\[\begin{split}\mathrm{E}(X)=\begin{cases}\text{location},&\text{df}>1\\\ \text{undefined},&\text{otherwise.}\end{cases}\end{split}\]

For example, to create a prior centered around 0 with 3 degrees of freedom and a scale of 1, use:

p = pints.StudentTLogPrior(0, 3, 1)

Extends LogPrior.

Parameters:
  • location – The center of the distribution.
  • df (int) – The number of degrees of freedom of the distribution.
  • scale – The scale of the distribution.
cdf(x)[source]

See LogPrior.cdf().

convert_from_unit_cube(u)

Converts samples u uniformly drawn from the unit cube into those drawn from the prior space, typically by transforming using LogPrior.icdf().

u should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

convert_to_unit_cube(x)

Converts samples from the prior x to be drawn uniformly from the unit cube, typically by transforming using LogPrior.cdf().

x should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

evaluateS1(x)[source]

See LogPDF.evaluateS1().

icdf(p)[source]

See LogPrior.icdf().

mean()[source]

See LogPrior.mean().

n_parameters()[source]

See LogPrior.n_parameters().

sample(n=1)[source]

See LogPrior.sample().

class pints.TruncatedGaussianLogPrior(mean, sd, a, b)[source]

Defines a truncated Gaussian log prior.

This distribution is also known as the truncated Normal distribution.

The truncated Gaussian distribution is similar to the Gaussian distribution, but constrained to lie between two values.

The parameters are the mean mean and standard deviation sd, as in the Gaussian distribution, as well as a lower bound a and an upper bound b.

The pdf of the truncated Gaussian distribution is given by

\[f(x|\mu, \sigma, a, b) = \frac{1}{\sigma\sqrt{2\pi}} \exp \left(-\frac{(x-\mu)^2}{2\sigma^2}\right) \frac{1} {\Phi((b-\mu) / \sigma) - \Phi((a-\mu) / \sigma)}\]

for \(x \in [a, b]\), where \(\mu\) indicates the mean and \(\sigma\) indicates the standard deviation, and \(\Phi\) is the standard normal CDF.

For example, to create a prior with mean of 0 and a standard deviation of 1, bounded above at 3 and below at -2, use:

p = pints.TruncatedGaussianLogPrior(0, 1, -2, 3)

For a Gaussian distribution truncated on only one side, numpy.inf or -numpy.inf can be used for the unbounded side.

Extends LogPrior.

cdf(x)[source]

See LogPrior.cdf().

convert_from_unit_cube(u)

Converts samples u uniformly drawn from the unit cube into those drawn from the prior space, typically by transforming using LogPrior.icdf().

u should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

convert_to_unit_cube(x)

Converts samples from the prior x to be drawn uniformly from the unit cube, typically by transforming using LogPrior.cdf().

x should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

evaluateS1(x)[source]

See LogPDF.evaluateS1().

icdf(p)[source]

See LogPrior.icdf().

mean()[source]

See LogPrior.mean().

n_parameters()[source]

See LogPrior.n_parameters().

sample(n=1)[source]

See LogPrior.sample().

class pints.UniformLogPrior(lower_or_boundaries, upper=None)[source]

Defines a uniform prior over a given range.

The range includes the lower, but not the upper boundaries, so that any point x with a non-zero prior must have lower <= x < upper.

In 1D this has pdf

\[\begin{split}f(x|\text{lower},\text{upper})=\begin{cases}0,&\text{if }x\not\in [\text{lower},\text{upper})\\\frac{1}{\text{upper}-\text{lower}} ,&\text{if }x\in[\text{lower},\text{upper})\end{cases}.\end{split}\]

A random variable \(X\) distributed according to this pdf has expectation

\[\mathrm{E}(X)=\frac{1}{2}(\text{lower}+\text{upper}).\]

For example, to create a prior with \(x\in[0,4]\), \(y\in[1,5]\), and \(z\in[2,6]\) use either:

p = pints.UniformLogPrior([0, 1, 2], [4, 5, 6])

or:

p = pints.UniformLogPrior(RectangularBoundaries([0, 1, 2], [4, 5, 6]))

Extends LogPrior.

cdf(xs)[source]

See LogPrior.cdf().

convert_from_unit_cube(u)

Converts samples u uniformly drawn from the unit cube into those drawn from the prior space, typically by transforming using LogPrior.icdf().

u should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

convert_to_unit_cube(x)

Converts samples from the prior x to be drawn uniformly from the unit cube, typically by transforming using LogPrior.cdf().

x should be an n x d array, where n is the number of input samples and d is the dimension of the parameter space.

evaluateS1(x)[source]

See LogPrior.evaluateS1().

icdf(ps)[source]

See LogPrior.icdf().

mean()[source]

See LogPrior.mean().

n_parameters()[source]

See LogPrior.n_parameters().

sample(n=1)[source]

See LogPrior.sample().