IVP

class probnum.diffeq.IVP(timespan, initrv, rhs, jac=None, hess=None, sol=None)[source]

Bases: probnum.diffeq.ODE

Initial value problems (IVP).

This class descibes initial value problems based on systems of first order ordinary differential equations (ODEs),

\[\dot y(t) = f(t, y(t)), \quad y(t_0) = y_0, \quad t \in [t_0, T]\]

It provides options for defining custom right-hand side (RHS) functions, their Jacobians and closed form solutions.

Since we use them for probabilistic ODE solvers these functions fit into the probabilistic framework as well. That is, the initial value is a RandomVariable object with some distribution that reflects the prior belief over the initial value. To recover “classical” initial values one can use the Dirac distribution.

Parameters:
  • timespan ((float, float)) – Time span of IVP.
  • initrv (RandomVariable,) – RandomVariable that describes the belief over the initial value. Usually its distribution is Dirac (noise-free) or Normal (noisy). To replicate “classical” initial values use the Dirac distribution. Implementation depends on the mean of this RandomVariable, so please only use RandomVariable objects with available means, e.g. Diracs or Normals.
  • rhs (callable, signature: (t, y, **kwargs)) – RHS function \(f : [0, T] \times \mathbb{R}^d \rightarrow \mathbb{R}^d\) of the ODE system. As such it takes a float and an np.ndarray of shape (d,) and returns a np.ndarray of shape (d,). As of now, no vectorization is supported (nor needed).
  • jac (callable, signature: (t, y, **kwargs), optional) – Jacobian of RHS function \(J_f : [0, T] \times \mathbb{R}^d \rightarrow \mathbb{R}^d\) of the ODE system. As such it takes a float and an np.ndarray of shape (d,) and returns a np.ndarray of shape (d,). As of now, no vectorization is supported (nor needed).
  • sol (callable, signature: (t, **kwargs), optional) – Solution of IVP.

See also

ODE
Abstract interface for ordinary differential equations.

Examples

>>> from probnum.diffeq import IVP
>>> rhsfun = lambda t, y, **kwargs: 2.0*y
>>> from probnum import random_variables as rvs
>>> initrv = rvs.Dirac(0.1)
>>> timespan = (0, 10)
>>> ivp = IVP(timespan, initrv, rhsfun)
>>> print(ivp.rhs(0., 2.))
4.0
>>> print(ivp.timespan)
[0, 10]
>>> print(ivp.t0)
0
>>> initrv = rvs.Normal(0.1, 1.0)
>>> ivp = IVP(timespan, initrv, rhsfun)
>>> jac = lambda t, y, **kwargs: 2.0
>>> ivp = IVP(timespan, initrv, rhs=rhsfun, jac=jac)
>>> print(ivp.rhs(0., 2.))
4.0
>>> print(ivp.jacobian(100., -1))
2.0

Attributes Summary

initialdistribution Distribution of the initial random variable.
initialrandomvariable Initial random variable.
ndim Spatial dimension of the IVP problem.
t0
timespan Returns \((t_0, T)\) as [self.t0, self.tmax].
tmax

Methods Summary

__call__(t, y, **kwargs) Piggybacks on self.rhs(t, y).
hessian(t, y, **kwargs) Hessian of model function f.
jacobian(t, y, **kwargs) Jacobian of model function f.
rhs(t, y, **kwargs) Evaluates model function f.
solution(t, **kwargs) Solution of the IVP.

Attributes Documentation

initialdistribution

Distribution of the initial random variable.

initialrandomvariable

Initial random variable.

ndim

Spatial dimension of the IVP problem.

Depends on the mean of the initial random variable.

t0
timespan

Returns \((t_0, T)\) as [self.t0, self.tmax]. Mainly here to provide an interface to scipy.integrate. Both \(t_0\) and \(T\) can be accessed via self.t0 and self.tmax respectively.

tmax

Methods Documentation

__call__(t, y, **kwargs)

Piggybacks on self.rhs(t, y).

hessian(t, y, **kwargs)

Hessian of model function f.

For \(d=3\), the Hessian \(H_f(t, y) \in \mathbb{R}^{3 \times 3 \times 3}\) is expected be evaluated as

\[H_f(t, y) = \left[H_{f_1}(t, y), H_{f_2}(t, y), H_{f_3}(t, y) \right]^\top\]

since for any directions \(v_1, v_2\) the outcome of \(H_f(t_0, y_0) \cdot v_1 \cdot v_2\) is expected to contain the incline of \(f_i\) in direction \((v_1, v_2)\).

jacobian(t, y, **kwargs)

Jacobian of model function f.

rhs(t, y, **kwargs)

Evaluates model function f.

solution(t, **kwargs)

Solution of the IVP.