markovflow.sde

Package containing SDE classes and related functions.

Package Contents

class SDE(state_dim=1)[source]

Bases: abc.ABC

Abstract class representing Stochastic Differential Equation.

..math::

&dx(t)/dt = f(x(t),t) + l(x(t),t) w(t)

Parameters

state_dim – The output dimension of the kernel.

property state_dimint

Return the state dimension of the sde.

abstract drift(x: tf.Tensor, t: tf.Tensor)tf.Tensor

Drift function of the SDE i.e. f(x(t),t)

Parameters
  • x – state at t i.e. x(t) with shape (n_batch, state_dim).

  • t – time t with shape (n_batch, state_dim).

Returns

Drift value i.e. f(x(t), t) with shape (n_batch, state_dim).

Raises

NotImplementedError – Must be implemented in derived classes.

abstract diffusion(x: tf.Tensor, t: tf.Tensor)tf.Tensor

Diffusion function of the SDE i.e. l(x(t),t)

Parameters
  • x – state at t i.e. x(t) with shape (n_batch, state_dim).

  • t – time t with shape (n_batch, 1).

Returns

Diffusion value i.e. l(x(t), t) with shape (n_batch, state_dim, state_dim).

Raises

NotImplementedError – Must be implemented in derived classes.

gradient_drift(x: tf.Tensor, t: tf.Tensor = tf.zeros((1, 1)))tf.Tensor

Calculates the gradient of the drift wrt the states x(t).

..math:: df(x(t))/dx(t)

Parameters
  • x – states with shape (num_states, state_dim).

  • t – time of states with shape (num_states, 1), defaults to zero.

Returns

the gradient of the SDE drift with shape (num_states, state_dim).

expected_drift(q_mean: tf.Tensor, q_covar: tf.Tensor)tf.Tensor

Calculates the Expectation of the drift under the provided Gaussian over states.

..math:: E_q(x(t))[f(x(t))]

Parameters
  • q_mean – mean of Gaussian over states with shape (n_batch, num_states, state_dim).

  • q_covar – covariance of Gaussian over states with shape (n_batch, num_states, state_dim, state_dim).

Returns

the expectation value with shape (n_batch, num_states, state_dim).

expected_gradient_drift(q_mean: tf.Tensor, q_covar: tf.Tensor)tf.Tensor

Calculates the Expectation of the gradient of the drift under the provided Gaussian over states

..math:: E_q(.)[f’(x(t))]

Parameters
  • q_mean – mean of Gaussian over states with shape (n_batch, num_states, state_dim).

  • q_covar – covariance of Gaussian over states with shape (n_batch, num_states, state_dim, state_dim).

Returns

the expectation value with shape (n_batch, num_states, state_dim).

class OrnsteinUhlenbeckSDE(decay: tf.Tensor, q: tf.Tensor = tf.ones((1, 1)))[source]

Bases: SDE

Ornstein-Uhlenbeck SDE represented by

..math:: dx(t) = -λ x(t) dt + dB(t), the spectral density of the Brownian motion is specified by q.

Initialize the Ornstein-Uhlenbeck SDE.

Parameters
  • decay – λ, a tensor with shape (1, 1).

  • q – spectral density of the Brownian motion (state_dim, state_dim).

drift(x: tf.Tensor, t: tf.Tensor)tf.Tensor

Drift of the Ornstein-Uhlenbeck process ..math:: f(x(t), t) = -λ x(t)

Parameters
  • x – state at t i.e. x(t) with shape (n_batch, state_dim).

  • t – time t with shape (n_batch, 1).

Returns

Drift value i.e. f(x(t), t) with shape (n_batch, state_dim).

diffusion(x: tf.Tensor, t: tf.Tensor)tf.Tensor

Diffusion of the Ornstein-Uhlenbeck process ..math:: l(x(t), t) = sqrt(q)

Parameters
  • x – state at t i.e. x(t) with shape (n_batch, state_dim).

  • t – time t with shape (n_batch, 1).

Returns

Diffusion value i.e. l(x(t), t) with shape (n_batch, state_dim, state_dim).

class DoubleWellSDE(q: tf.Tensor = tf.ones((1, 1)))[source]

Bases: SDE

Double-Well SDE represented by

..math:: dx(t) = f(x(t)) dt + dB(t),

where f(x(t)) = 4 x(t) (1 - x(t)^2) and the spectral density of the Brownian motion is specified by q.

Initialize the Double-Well SDE.

Parameters

q – spectral density of the Brownian motion (state_dim, state_dim).

drift(x: tf.Tensor, t: tf.Tensor)tf.Tensor

Drift of the double-well process ..math:: f(x(t), t) = 4 x(t) (1 - x(t)^2)

Parameters
  • x – state at t i.e. x(t) with shape (n_batch, state_dim).

  • t – time t with shape (n_batch, 1).

Returns

Drift value i.e. f(x(t), t) with shape (n_batch, state_dim).

diffusion(x: tf.Tensor, t: tf.Tensor)tf.Tensor

Diffusion of the double-well process ..math:: l(x(t), t) = sqrt(q)

Parameters
  • x – state at t i.e. x(t) with shape (n_batch, state_dim).

  • t – time t with shape (n_batch, 1).

Returns

Diffusion value i.e. l(x(t), t) with shape (n_batch, state_dim, state_dim).