ODE

This submodule contains tools used to perform inference on ordinary differential equations.

class pymc3.ode.DifferentialEquation(func, times, *, n_states, n_theta, t0=0)

Specify an ordinary differential equation

\[\dfrac{dy}{dt} = f(y,t,p) \quad y(t_0) = y_0\]
Parameters
funccallable

Function specifying the differential equation. Must take arguments y (n_states,), t (scalar), p (n_theta,)

timesarray

Array of times at which to evaluate the solution of the differential equation.

n_statesint

Dimension of the differential equation. For scalar differential equations, n_states=1. For vector valued differential equations, n_states = number of differential equations in the system.

n_thetaint

Number of parameters in the differential equation.

t0float

Time corresponding to the initial condition

Examples

def odefunc(y, t, p):
    #Logistic differential equation
    return p[0] * y[0] * (1 - y[0])

times = np.arange(0.5, 5, 0.5)

ode_model = DifferentialEquation(func=odefunc, times=times, n_states=1, n_theta=1, t0=0)
grad(inputs, output_grads)

Construct a graph for the gradient with respect to each input variable.

Each returned Variable represents the gradient with respect to that input computed based on the symbolic gradients with respect to each output. If the output is not differentiable with respect to an input, then this method should return an instance of type NullType for that input.

Parameters
inputslist of Variable

The input variables.

output_gradslist of Variable

The gradients of the output variables.

Returns
gradslist of Variable

The gradients with respect to each Variable in inputs.

make_node(y0, theta)

Construct an Apply node that represent the application of this operation to the given inputs.

This must be implemented by sub-classes.

Returns
node: Apply

The constructed Apply node.

perform(node, inputs_storage, output_storage)

Calculate the function on the inputs and put the variables in the output storage.

Parameters
nodeApply

The symbolic Apply node that represents this computation.

inputsSequence

Immutable sequence of non-symbolic/numeric inputs. These are the values of each Variable in node.inputs.

output_storagelist of list

List of mutable single-element lists (do not change the length of these lists). Each sub-list corresponds to value of each Variable in node.outputs. The primary purpose of this method is to set the values of these sub-lists.

paramstuple

A tuple containing the values of each entry in __props__.

Notes

The output_storage list might contain data. If an element of output_storage is not None, it has to be of the right type, for instance, for a TensorVariable, it has to be a NumPy ndarray with the right number of dimensions and the correct dtype. Its shape and stride pattern can be arbitrary. It is not guaranteed that such pre-set values were produced by a previous call to this Op.perform; they could’ve been allocated by another Op’s perform method. A Op is free to reuse output_storage as it sees fit, or to discard it and allocate new memory.