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)
Overview:
-
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 argumentp
they return some valuelog(f(p))
wheref(p)
is an unnormalised PDF. The size of the argumentp
is given byn_parameters()
.-
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')
whereL
is 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 pointstheta
in parameter space sums to 1), but this is not a strict requirement.Extends
LogPDF
.-
cdf
(x)[source]¶ Returns the cumulative density function at point(s)
x
.x
should be ann x d
array, wheren
is the number of input samples andd
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 usingLogPrior.icdf()
.u
should be ann x d
array, wheren
is the number of input samples andd
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 usingLogPrior.cdf()
.x
should be ann x d
array, wheren
is the number of input samples andd
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')
whereL
is 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
.p
should be ann x d
array, wheren
is the number of input samples andd
is the dimension of the parameter space.
-
-
class
pints.
LogPosterior
(log_likelihood, log_prior)[source]¶ Represents the sum of a
LogPDF
and aLogPrior
defined on the same parameter space.As an optimisation, if the
LogPrior
evaluates as -inf for a particular point in parameter space, the correspondingLogPDF
will not be evaluated.Extends
LogPDF
.Parameters: -
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')
whereL
is 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()`!
-
-
class
pints.
PooledLogPDF
(log_pdfs, pooled)[source]¶ Combines \(m\)
LogPDFs
, each with \(n\) parameters, into a single LogPDF where \(k\) parameters are “pooled” (i.e. have the same value for each LogPDF), so that the resulting combined LogPDF has \(m (n - k) + k\) independent parameters.This is useful for e.g. modelling the time-series of multiple individuals (each individual defines a separate
LogPDF
), and some parameters are expected to be the same across individuals (for example, the noise parameter across different individuals within the same experiment).For two
LogPDFs
\(L _1\) and \(L _2\) with four parameters \((\psi ^{(1)}_1, \psi ^{(1)}_2, \psi ^{(1)}_3, \psi ^{(1)}_4)\) and \((\psi ^{(2)}_1, \psi ^{(2)}_2, \psi ^{(2)}_3, \psi ^{(2)}_4)\) respectively, a pooling of the second and third parameter \(\psi _2 := \psi ^{(1)}_2 = \psi ^{(2)}_2\), \(\psi _3 := \psi ^{(1)}_3 = \psi ^{(2)}_3\) results in a pooled log-pdf of the form\[L(\psi ^{(1)}_1, \psi ^{(1)}_4, \psi ^{(2)}_1, \psi ^{(2)}_4, \psi _2, \psi _3 | D_1, D_2) = L _1(\psi ^{(1)}_1, \psi _2, \psi _3, \psi ^{(1)}_4 | D_1) + L _2(\psi ^{(2)}_1, \psi _2, \psi _3, \psi ^{(2)}_4 | D_2),\]\(D_i\) is the measured time-series of individual \(i\). As \(k=2\) parameters where pooled across the log-likelihoods, the pooled log-likelihood has six parameters in the following order: \((\psi ^{(1)}_1, \psi ^{(1)}_4, \psi ^{(2)}_1, \psi ^{(2)}_4, \psi _2, \psi _3)\).
Note that the input parameters of a
PooledLogPDF
are not just a simple concatenation of the parameters of the individualLogPDFs
. The pooled parameters are only listed once and are moved to the end of the parameter list. This avoids inputting the value of the pooled parameters at mutliple positions. Otherwise the order of the parameters is determined firstly by the order of the likelihoods and then by the order of the parameters of those likelihoods.Extends
LogPDF
.Parameters: - log_pdfs – A sequence of
LogPDF
objects. - pooled – A sequence of booleans indicating which parameters across
the likelihoods are pooled (
True
) or remain unpooled (False
).
Example
pooled_log_likelihood = pints.PooledLogPDF( log_pdfs=[ pints.GaussianLogLikelihood(problem1), pints.GaussianLogLikelihood(problem2)], pooled=[False, True])
-
evaluateS1
(parameters)[source]¶ See
LogPDF.evaluateS1()
.The partial derivatives of the pooled log-likelihood with respect to unpooled parameters equals the partial derivative of the corresponding indiviudal log-likelihood.
\[\frac{\partial L}{\partial \psi} = \frac{\partial L_i}{\partial \psi},\]where \(L\) is the pooled log-likelihood, \(\psi\) an unpooled parameter and \(L _i\) the individual log-likelihood that depends on \(\psi\).
For a pooled parameter \(\theta\) the partial derivative of the pooled log-likelihood equals to the sum of partial derivatives of all individual log-likelihoods
\[\frac{\partial L}{\partial \theta} = \sum _{i=1}^n\frac{\partial L_i}{\partial \theta}.\]Here \(n\) is the number of individual log-likelihoods.
This method only works if all the underlying :class:`LogPDF` objects implement the optional method :meth:`LogPDF.evaluateS1()`!
- log_pdfs – A sequence of
-
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
LogPDF
.Parameters: problem – The time-series problem this log-likelihood is defined for. -
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')
whereL
is 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.
SumOfIndependentLogPDFs
(log_likelihoods)[source]¶ Calculates a sum of
LogPDF
objects, all defined on the same parameter space.This is useful for e.g. Bayesian inference using a single model evaluated on two independent data sets
D
andE
. In this case,\[\begin{split}f(\theta|D,E) &= \frac{f(D, E|\theta)f(\theta)}{f(D, E)} \\ &= \frac{f(D|\theta)f(E|\theta)f(\theta)}{f(D, E)}\end{split}\]Extends
LogPDF
.Parameters: log_likelihoods – A sequence of LogPDF
objects.Example
log_likelihood = pints.SumOfIndependentLogPDFs([ pints.GaussianLogLikelihood(problem1), pints.GaussianLogLikelihood(problem2), ])
-
evaluateS1
(x)[source]¶ See
LogPDF.evaluateS1()
.This method only works if all the underlying :class:`LogPDF` objects implement the optional method :meth:`LogPDF.evaluateS1()`!
-