Log-PDFs

LogPDFs are callable objects that represent distributions, including likelihoods and Bayesian priors and posteriors. They are unnormalised, i.e. their area does not necessarily sum up to 1, and for efficiency reasons we always work with the logarithm e.g. a log-likelihood instead of a likelihood.

Example:

p = pints.GaussianLogPrior(mean=0, variance=1)
x = p(0.1)
class pints.LogPDF[source]

Represents the natural logarithm of a (not necessarily normalised) probability density function (PDF).

All LogPDF types are callable: when called with a vector argument x they return some value log(f(x)) where f(x) is an unnormalised PDF. The size of the argument x is given by n_parameters(). In PINTS, all parameters must be continuous and real.

All subclasses of LogPDF should provide an implementation of __call__() and n_parameters(). Providing evaluateS1() is optional.

__call__(x)[source]

Evaluates this LogPDF for parameters x.

evaluateS1(x)[source]

Evaluates this LogPDF, and returns the result plus the partial derivatives of the result with respect to the parameters.

The returned data is a tuple (L, L') where L is a scalar value and L' is a sequence of length n_parameters.

Note that the derivative returned is of the log-pdf, so L' = d/dp log(f(p)), evaluated at p=x.

This is an optional method that is not always implemented.

n_parameters()[source]

Returns the dimension of the space this LogPDF is defined over.

class pints.LogPrior[source]

Represents the natural logarithm log(f(theta)) of a known probability density function f(theta).

Priors are usually normalised (i.e. the integral f(theta) over all points theta in parameter space sums to 1), but this is not a strict requirement.

Extends LogPDF.

__call__(x)

Evaluates this LogPDF for parameters x.

cdf(x)[source]

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 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)[source]

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)

Evaluates this LogPDF, and returns the result plus the partial derivatives of the result with respect to the parameters.

The returned data is a tuple (L, L') where L is a scalar value and L' is a sequence of length n_parameters.

Note that the derivative returned is of the log-pdf, so L' = d/dp log(f(p)), evaluated at p=x.

This is an optional method that is not always implemented.

icdf(p)[source]

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]

Returns the analytical value of the expectation of a random variable distributed according to this LogPDF.

n_parameters()

Returns the dimension of the space this LogPDF is defined over.

sample(n=1)[source]

Returns n random samples from the underlying prior distribution.

The returned value is a NumPy array with shape (n, d) where n is the requested number of samples, and d is the dimension of the prior.

class pints.LogLikelihood[source]

Represents a log-likelihood defined on a parameter space.

This class adds no new functionality, but exists to indicate when a LogPDF represents the probability of a data set given a set of parameters, rather than a probability of those parameters.

Extends: LogPDF

__call__(x)

Evaluates this LogPDF for parameters x.

evaluateS1(x)

Evaluates this LogPDF, and returns the result plus the partial derivatives of the result with respect to the parameters.

The returned data is a tuple (L, L') where L is a scalar value and L' is a sequence of length n_parameters.

Note that the derivative returned is of the log-pdf, so L' = d/dp log(f(p)), evaluated at p=x.

This is an optional method that is not always implemented.

n_parameters()

Returns the dimension of the space this LogPDF is defined over.

class pints.ProblemLogLikelihood(problem)[source]

Represents a log-likelihood on a problem’s parameter space, used to indicate the likelihood of an observed (fixed) time-series given a particular parameter set (variable).

Extends LogLikelihood.

Parameters:

problem – The time-series problem this log-likelihood is defined for.

__call__(x)

Evaluates this LogPDF for parameters x.

evaluateS1(x)

Evaluates this LogPDF, and returns the result plus the partial derivatives of the result with respect to the parameters.

The returned data is a tuple (L, L') where L is a scalar value and L' is a sequence of length n_parameters.

Note that the derivative returned is of the log-pdf, so L' = d/dp log(f(p)), evaluated at p=x.

This is an optional method that is not always implemented.

n_parameters()[source]

See LogPDF.n_parameters().

class pints.LogPosterior(log_likelihood, log_prior)[source]

Represents the sum of a LogLikelihood and a LogPrior defined on the same parameter space.

As an optimisation, if the LogPrior evaluates as -inf for a particular point in parameter space, the corresponding LogPDF will not be evaluated.

Extends LogPDF.

Parameters:
  • log_likelihood – A LogLikelihood, defined on the same parameter space.

  • log_prior – A LogPrior, representing prior knowledge of the parameter space.

__call__(x)[source]

Evaluates this LogPDF for parameters x.

evaluateS1(x)[source]

Evaluates this LogPDF, and returns the result plus the partial derivatives of the result with respect to the parameters.

The returned data has the shape (L, L') where L is a scalar value and L' is a sequence of length n_parameters.

This method only works if the underlying :class:`LogPDF` and :class:`LogPrior` implement the optional method :meth:`LogPDF.evaluateS1()`!

log_likelihood()[source]

Returns the LogLikelihood used by this posterior.

log_prior()[source]

Returns the LogPrior used by this posterior.

n_parameters()[source]

See LogPDF.n_parameters().