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)
- 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
eis an instance of anErrorMeasureclass you can calculate the error by callinge(x)wherexis a point in parameter space. In PINTS, all parameters must be continuous and real.All subclasses of
ErrorMeasureshould provide an implementation of__call__()andn_parameters().- 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')whereeis 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.SingleOutputProblemorpints.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()¶
- problem()¶
Returns the problem this error measure was defined on.
- 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')whereeis a scalar value ande'is a sequence of lengthn_parameters.This is an optional method that is not always implemented.
- n_parameters()¶
- problem()¶
Returns the problem this error measure was defined on.
- class pints.ProbabilityBasedError(log_pdf)[source]¶
Changes the sign of a
LogPDFto 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
LogPDFimplements the optional methodLogPDF.evaluateS1()!
- class pints.ProblemErrorMeasure(problem)[source]¶
Abstract base class for ErrorMeasures defined for
singleormulti-outputproblems.- __call__(x)¶
Evaluates this error measure for parameters
x.
- 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')whereeis 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')whereeis a scalar value ande'is a sequence of lengthn_parameters.This is an optional method that is not always implemented.
- n_parameters()¶
- problem()¶
Returns the problem this error measure was defined on.
- class pints.SumOfErrors(error_measures, weights=None)[source]¶
Calculates a sum of
ErrorMeasureobjects, 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 the 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.SingleOutputProblemorpints.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()¶
- problem()¶
Returns the problem this error measure was defined on.