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
LogPDFtypes are callable: when called with a vector argumentxthey return some valuelog(f(x))wheref(x)is an unnormalised PDF. The size of the argumentxis given byn_parameters(). In PINTS, all parameters must be continuous and real.All subclasses of
LogPDFshould provide an implementation of__call__()andn_parameters(). ProvidingevaluateS1()is optional.- 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')whereLis a scalar value andL'is a sequence of lengthn_parameters.Note that the derivative returned is of the log-pdf, so
L' = d/dp log(f(p)), evaluated atp=x.This is an optional method that is not always implemented.
- class pints.LogPrior[source]¶
Represents the natural logarithm
log(f(theta))of a known probability density functionf(theta).Priors are usually normalised (i.e. the integral
f(theta)over all pointsthetain 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.xshould be ann x darray, wherenis the number of input samples anddis the dimension of the parameter space.
- convert_from_unit_cube(u)[source]¶
Converts samples
uuniformly drawn from the unit cube into those drawn from the prior space, typically by transforming usingLogPrior.icdf().ushould be ann x darray, wherenis the number of input samples anddis the dimension of the parameter space.
- convert_to_unit_cube(x)[source]¶
Converts samples from the prior
xto be drawn uniformly from the unit cube, typically by transforming usingLogPrior.cdf().xshould be ann x darray, wherenis the number of input samples anddis 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')whereLis a scalar value andL'is a sequence of lengthn_parameters.Note that the derivative returned is of the log-pdf, so
L' = d/dp log(f(p)), evaluated atp=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.pshould be ann x darray, wherenis the number of input samples anddis the dimension of the parameter space.
- 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')whereLis a scalar value andL'is a sequence of lengthn_parameters.Note that the derivative returned is of the log-pdf, so
L' = d/dp log(f(p)), evaluated atp=x.This is an optional method that is not always implemented.
- 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')whereLis a scalar value andL'is a sequence of lengthn_parameters.Note that the derivative returned is of the log-pdf, so
L' = d/dp log(f(p)), evaluated atp=x.This is an optional method that is not always implemented.
- class pints.LogPosterior(log_likelihood, log_prior)[source]¶
Represents the sum of a
LogLikelihoodand aLogPriordefined on the same parameter space.As an optimisation, if the
LogPriorevaluates as -inf for a particular point in parameter space, the correspondingLogPDFwill 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.
- 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')whereLis a scalar value andL'is a sequence of lengthn_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
LogLikelihoodused by this posterior.