Error measures¶
Error measures are callable objects that return some scalar representing the error between a model and an experiment.
Example:
error = pints.SumOfSquaresError(problem)
x = [1,2,3]
fx = error(x)
Overview:
- class pints.ErrorMeasure[source]¶
Abstract base class for objects that calculate some scalar measure of goodness-of-fit (for a model and a data set), such that a smaller value means a better fit.
ErrorMeasures are callable objects: If
e
is an instance of anErrorMeasure
class you can calculate the error by callinge(p)
wherep
is a point in parameter space. In PINTS, all parameters must be continuous and real.- evaluateS1(x)[source]¶
Evaluates this error measure, and returns the result plus the partial derivatives of the result with respect to the parameters.
The returned data has the shape
(e, e')
wheree
is a scalar value ande'
is a sequence of lengthn_parameters
.This is an optional method that is not always implemented.
- class pints.MeanSquaredError(problem, weights=None)[source]¶
Calculates the mean square error:
\[f = \sum _i^n \frac{(y_i - x_i)^2}{n},\]where \(y\) is the data, \(x\) the model output and \(n\) is the total number of data points.
Extends
ProblemErrorMeasure
.- Parameters:
problem – A
pints.SingleOutputProblem
orpints.MultiOutputProblem
.weights – An optional sequence of (float) weights, exactly one per problem output. If given, the error in each individual output will be multiplied by the corresponding weight. If no weights are specified all outputs will be weighted equally.
- n_parameters()¶
- class pints.NormalisedRootMeanSquaredError(problem)[source]¶
Calculates a normalised root mean squared error:
\[f = \frac{1}{C}\sqrt{\frac{\sum _i^n (y_i - x_i) ^ 2}{n}},\]where \(C\) is the normalising constant, \(y\) is the data, \(x\) the model output and \(n\) is the total number of data points. The normalising constant is given by
\[C = \sqrt{\frac{\sum _i^n y_i^2}{n}}.\]This error measure is similar to the (unnormalised)
RootMeanSquaredError
.Extends
ProblemErrorMeasure
.- Parameters:
problem – A
pints.SingleOutputProblem
.
- evaluateS1(x)¶
Evaluates this error measure, and returns the result plus the partial derivatives of the result with respect to the parameters.
The returned data has the shape
(e, e')
wheree
is a scalar value ande'
is a sequence of lengthn_parameters
.This is an optional method that is not always implemented.
- n_parameters()¶
- class pints.ProbabilityBasedError(log_pdf)[source]¶
Changes the sign of a
LogPDF
to use it as an error. Minimising this error will maximise the probability.Extends
ErrorMeasure
.- Parameters:
log_pdf (pints.LogPDF) – The LogPDF to base this error on.
- evaluateS1(x)[source]¶
See
ErrorMeasure.evaluateS1()
.This method only works if the underlying
LogPDF
implements the optional methodLogPDF.evaluateS1()
!
- class pints.ProblemErrorMeasure(problem=None)[source]¶
Abstract base class for ErrorMeasures defined for
single
ormulti-output
problems.- evaluateS1(x)¶
Evaluates this error measure, and returns the result plus the partial derivatives of the result with respect to the parameters.
The returned data has the shape
(e, e')
wheree
is a scalar value ande'
is a sequence of lengthn_parameters
.This is an optional method that is not always implemented.
- class pints.RootMeanSquaredError(problem)[source]¶
Calculates a normalised root mean squared error:
\[f = \sqrt{\frac{\sum _i^n (y_i - x_i) ^ 2}{n}},\]where \(y\) is the data, \(x\) the model output and \(n\) is the total number of data points.
Extends
ProblemErrorMeasure
.- Parameters:
problem – A
pints.SingleOutputProblem
.
- evaluateS1(x)¶
Evaluates this error measure, and returns the result plus the partial derivatives of the result with respect to the parameters.
The returned data has the shape
(e, e')
wheree
is a scalar value ande'
is a sequence of lengthn_parameters
.This is an optional method that is not always implemented.
- n_parameters()¶
- class pints.SumOfErrors(error_measures, weights=None)[source]¶
Calculates a sum of
ErrorMeasure
objects, all defined on the same parameter space\[f = \sum _i f_i,\]where \(f_i\) are the individual error meaures.
Extends
ErrorMeasure
.- Parameters:
error_measures – A sequence of error measures.
weights – An optional sequence of (float) weights, exactly one per error measure. If given, each individual error will be multiplied by the corresponding weight. If no weights are given all sums will be weighted equally.
Examples
errors = [ pints.MeanSquaredError(problem1), pints.MeanSquaredError(problem2), ] # Equally weighted e1 = pints.SumOfErrors(errors) # Differrent weights: weights = [ 1.0, 2.7, ] e2 = pints.SumOfErrors(errors, weights)
- evaluateS1(x)[source]¶
See
ErrorMeasure.evaluateS1()
.This method only works if all the underlying :class:`ErrorMeasure` objects implement the optional method :meth:`ErrorMeasure.evaluateS1()`!
- class pints.SumOfSquaresError(problem, weights=None)[source]¶
Calculates a sum of squares error:
\[f = \sum _i^n (y_i - x_i) ^ 2,\]where \(y\) is the data, \(x\) the model output and \(n\) is the total number of data points.
Extends
ErrorMeasure
.- Parameters:
problem – A
pints.SingleOutputProblem
orpints.MultiOutputProblem
.
- n_parameters()¶