Core classes and methods

Pints provides the SingleOutputProblem and MultiOutputProblem classes to formulate inverse problems based on time series data and ForwardModel.

Overview:

pints.version(formatted=False)[source]

Returns the version number, as a 3-part integer (major, minor, revision). If formatted=True, it returns a string formatted version (for example “Pints 1.0.0”).

class pints.TunableMethod[source]

Defines an interface for a numerical method with a given number of hyper-parameters.

Each optimiser or sampler method implemented in pints has a number of parameters which alters its behaviour, which can be called “hyper-parameters”. The optimiser/sampler method will provide member functions to set each of these hyper-parameters individually. In contrast, this interface provides a generic way to set the hyper-parameters, which allows the user to, for example, use an optimiser to tune the hyper-parameters of the method.

Note that set_hyper_parameters() takes an array of parameters, which might be of the same type (e.g. a NumPy array). So derived classes should not raise any errors if individual hyper parameters are set using the wrong type (e.g. float rather than int), but should instead implicitly convert the argument to the correct type.

n_hyper_parameters()[source]

Returns the number of hyper-parameters for this method (see TunableMethod).

set_hyper_parameters(x)[source]

Sets the hyper-parameters for the method with the given vector of values (see TunableMethod).

Parameters:

x – An array of length n_hyper_parameters used to set the hyper-parameters.

Forward model

class pints.ForwardModel[source]

Defines an interface for user-supplied forward models.

Classes extending ForwardModel can implement the required methods directly in Python or interface with other languages (for example via Python wrappers around C code).

n_outputs()[source]

Returns the number of outputs this model has. The default is 1.

n_parameters()[source]

Returns the dimension of the parameter space.

simulate(parameters, times)[source]

Runs a forward simulation with the given parameters and returns a time-series with data points corresponding to the given times.

Returns a sequence of length n_times (for single output problems) or a NumPy array of shape (n_times, n_outputs) (for multi-output problems), representing the values of the model at the given times.

Parameters:
  • parameters – An ordered sequence of parameter values.

  • times – The times at which to evaluate. Must be an ordered sequence, without duplicates, and without negative values. All simulations are started at time 0, regardless of whether this value appears in times.

Forward model with sensitivities

class pints.ForwardModelS1[source]

Defines an interface for user-supplied forward models which can calculate the first-order derivative of the simulated values with respect to the parameters.

Extends pints.ForwardModel.

n_outputs()

Returns the number of outputs this model has. The default is 1.

n_parameters()

Returns the dimension of the parameter space.

simulate(parameters, times)

Runs a forward simulation with the given parameters and returns a time-series with data points corresponding to the given times.

Returns a sequence of length n_times (for single output problems) or a NumPy array of shape (n_times, n_outputs) (for multi-output problems), representing the values of the model at the given times.

Parameters:
  • parameters – An ordered sequence of parameter values.

  • times – The times at which to evaluate. Must be an ordered sequence, without duplicates, and without negative values. All simulations are started at time 0, regardless of whether this value appears in times.

simulateS1(parameters, times)[source]

Runs a forward simulation with the given parameters and returns a time-series with data points corresponding to the given times, along with the sensitivities of the forward simulation with respect to the parameters.

Parameters:
  • parameters – An ordered list of parameter values.

  • times – The times at which to evaluate. Must be an ordered sequence, without duplicates, and without negative values. All simulations are started at time 0, regardless of whether this value appears in times.

Returns:

  • y – The simulated values, as a sequence of n_times values, or a NumPy array of shape (n_times, n_outputs).

  • y’ – The corresponding derivatives, as a NumPy array of shape (n_times, n_parameters) or an array of shape (n_times, n_outputs, n_parameters).

Problems

class pints.SingleOutputProblem(model, times, values)[source]

Represents an inference problem where a model is fit to a single time series, such as measured from a system with a single output.

Parameters:
  • model – A model or model wrapper extending ForwardModel.

  • times – A sequence of points in time. Must be non-negative and increasing.

  • values – A sequence of scalar output values, measured at the times in times.

evaluate(parameters)[source]

Runs a simulation using the given parameters, returning the simulated values as a NumPy array of shape (n_times,).

evaluateS1(parameters)[source]

Runs a simulation with first-order sensitivity calculation, returning the simulated values and derivatives.

The returned data is a tuple of NumPy arrays (y, y'), where y has shape (self._n_times,) while y' has shape (n_times, n_parameters).

This method only works for problems with a model that implements the :class:`ForwardModelS1` interface.

n_outputs()[source]

Returns the number of outputs for this problem (always 1).

n_parameters()[source]

Returns the dimension (the number of parameters) of this problem.

n_times()[source]

Returns the number of sampling points, i.e. the length of the vectors returned by times() and values().

times()[source]

Returns this problem’s times.

The returned value is a read-only NumPy array of shape (n_times, ), where n_times is the number of time points.

values()[source]

Returns this problem’s values.

The returned value is a read-only NumPy array of shape (n_times, ), where n_times is the number of time points.

class pints.MultiOutputProblem(model, times, values)[source]

Represents an inference problem where a model is fit to a multi-valued time series, such as measured from a system with multiple outputs.

Parameters:
  • model – A model or model wrapper extending ForwardModel.

  • times – A sequence of points in time. Must be non-negative and non-decreasing.

  • values – A sequence of multi-valued measurements. Must have shape (n_times, n_outputs), where n_times is the number of points in times and n_outputs is the number of outputs in the model.

evaluate(parameters)[source]

Runs a simulation using the given parameters, returning the simulated values.

The returned data is a NumPy array with shape (n_times, n_outputs).

evaluateS1(parameters)[source]

Runs a simulation using the given parameters, returning the simulated values.

The returned data is a tuple of NumPy arrays (y, y'), where y has shape (n_times, n_outputs), while y' has shape (n_times, n_outputs, n_parameters).

This method only works for problems whose model implements the :class:`ForwardModelS1` interface.

n_outputs()[source]

Returns the number of outputs for this problem.

n_parameters()[source]

Returns the dimension (the number of parameters) of this problem.

n_times()[source]

Returns the number of sampling points, i.e. the length of the vectors returned by times() and values().

times()[source]

Returns this problem’s times.

The returned value is a read-only NumPy array of shape (n_times, n_outputs), where n_times is the number of time points and n_outputs is the number of outputs.

values()[source]

Returns this problem’s values.

The returned value is a read-only NumPy array of shape (n_times, n_outputs), where n_times is the number of time points and n_outputs is the number of outputs.