markovflow.mean_function

Module containing mean functions.

Module Contents

class MeanFunction(name=None)[source]

Bases: tf.Module, abc.ABC

Abstract class for mean functions.

Represents the action \(u(t)\) added to the latent states:

\[dx(t)/dt = F x(t) + u(t) + L w(t)\]

…resulting in the the mean function:

\[dμ(t)/dt = F μ(t) + u(t)\]

We can then solve the pure SDE:

\[dg(t)/dt = F g(t)+ L w(t)\]

…where:

\[g(t) = x(t) - μ(t)\]

This class provides a very general interface for the function \(μ(t)\).

Note

Implementations of this class should typically avoid performing computation in their __init__ method. Performing computation in the constructor conflicts with running in TensorFlow’s eager mode.

__call__(time_points: tf.Tensor)tf.Tensor[source]

Return the mean function evaluated at the given time points.

Parameters

time_points – A tensor with shape [... num_data].

Returns

The mean function evaluated at the time points, with shape [... num_data, obs_dim].

class ZeroMeanFunction(obs_dim: int)[source]

Bases: MeanFunction

Represents a mean function that is zero everywhere.

Parameters

obs_dim – The dimension of the zeros to output.

__call__(time_points: tf.Tensor)tf.Tensor[source]

Return the mean function evaluated at the given time points.

Parameters

time_points – A tensor with shape [... num_data].

Returns

The mean function evaluated at the time points, with shape [... num_data, obs_dim].

class LinearMeanFunction(coefficient: float, obs_dim: int = 1)[source]

Bases: MeanFunction

Represents a mean function that is linear. That is, where \(m(t) = a * t\).

Parameters
  • coefficient – The linear coefficient.

  • obs_dim – The output dimension of the mean function.

__call__(time_points: tf.Tensor)tf.Tensor[source]

Return the mean function evaluated at the given time points.

Parameters

time_points – A tensor with shape [... num_data].

Returns

The mean function evaluated at the time points with shape [... num_data, obs_dim].

class ImpulseMeanFunction(action_times: tf.Tensor, state_perturbations: tf.Tensor, kernel: markovflow.kernels.SDEKernel)[source]

Bases: MeanFunction

Represents a mean function that is an impulse action. This is given by:

\[u(t) = Σₖ uₖ δ(t - tₖ)\]

…in:

\[dx(t)/dt = F x(t) + u(t) + L w(t)\]

…and then:

\[\begin{split}&μ_(t) = 0 & t ≤ t₀\\ &μ₀(t) = exp(F (t - t₀)) u₀ &t₀ < t ≤ t₁\\ &μₖ(t) = exp(F (t - tₖ))(μₖ₋₁(tₖ) + uₖ) &tₖ < t ≤ tₖ₊₁\end{split}\]

Or:

\[\begin{split}&μ₋₁(t) = 0 & t ≤ t₀\\ &μₖ(t) = exp(F (t - tₖ))aₖ &tₖ < t ≤ tₖ₊₁\end{split}\]

If we let:

\[\begin{split}&a₋₁ = 0\\ &a₀ = u₀\\ &aₖ = Aₖaₖ₋₁ + uₖ\end{split}\]

…where:

\[Aₖ = exp(F (tₖ - tₖ₋₁))\]

…then we can write this as a LowerTriangularBlockTriDiagonal equation:

[ I             ] a₀   u₀
[-A₁, I         ] a₁   u₁
[    -A₂, I     ] a₂ = u₂
[         ᨞  ᨞  ] ⋮     ⋮
[         -Aₙ, I] aₙ   uₙ

We can then determine the \(aₖ\) using a matrix solve.

Note

The effect of the action is not seen until fractionally after it is applied. That is, if an impulse is applied at time \(t\), \(μ(t)\) will not see the effect but \(μ(t + ε)\) will.

Parameters
  • action_times – The times at which actions occur, with shape [... num_actions].

  • state_perturbations – The magnitude of the impulse, with shape [... num_actions, state_dim].

  • kernel – The kernel that is used to generate this mean function.

__call__(time_points: tf.Tensor)tf.Tensor[source]

Return the mean function evaluated at the given time points.

For each time point, we find the index of the function associated with it; that is, the closest previous impulse.

This index is then used to find the parameters of the function:

\[μₖ(t) = exp(F (t - tₖ))aₖ\]

…where \(tₖ < t ≤ tₖ₊₁\).

Parameters

time_points – A tensor with shape [... num_data].

Returns

The mean function evaluated at the time points, with shape [... num_data, state_dim].

class StepMeanFunction(action_times: tf.Tensor, state_perturbations: tf.Tensor, kernel: markovflow.kernels.SDEKernel)[source]

Bases: MeanFunction

Represents a mean function that is a step action. This is given by:

\[\begin{split}&u(t) = 0 &t ≤ t₀\\ &u(t) = uₖ &tₖ < t ≤ tₖ₊₁\end{split}\]

…in:

\[dx(t)/dt = F x(t) + u(t) + L w(t)\]

Then:

\[\begin{split}&μ_(t) = 0 & t ≤ t₀\\ &μ₀(t) = -F⁻¹u₀ + exp(F (t - t₀))F⁻¹u₀ &t₀ < t ≤ t₁\\ &μₖ(t) = -F⁻¹uₖ + exp(F (t - tₖ))(F⁻¹uₖ + μₖ₋₁(tₖ)) &tₖ < t ≤ tₖ₊₁\end{split}\]

Or:

\[\begin{split}&μ₋₁(t) = 0 & t ≤ t₀\\ &μₖ(t) = aₖ + exp(F (t - tₖ))bₖ &tₖ < t ≤ tₖ₊₁\end{split}\]

If we let:

\[\begin{split}&a₋₁ = b₋₁ = 0\\ &aₖ = -F⁻¹uₖ\\ &bₖ = -aₖ + μₖ₋₁(tₖ) = Aₖbₖ₋₁ + aₖ₋₁ - aₖ\end{split}\]

…where:

\[Aₖ = exp(F (tₖ - tₖ₋₁))\]

…we can write this as a LowerTriangularBlockTriDiagonal equation:

[ I             ] b₀   [a₋₁ - a₀]
[-A₁, I         ] b₁   [a₀ - a₁]
[    -A₂, I     ] b₂ = [a₁ - a₂]
[         ᨞  ᨞  ] ⋮         ⋮
[         -Aₙ, I] bₙ   [aₙ₋₁ - aₙ]

We can then determine the \(bₖ\) using a matrix solve.

Parameters
  • action_times – The times at which actions occur, with shape [... num_actions].

  • state_perturbations – The magnitude of the impulse, with shape [... num_actions, obs_dim].

  • kernel – The kernel that is used to generate this mean function.

__call__(time_points: tf.Tensor)tf.Tensor[source]

Return the mean function evaluated at the given time points.

For each time point, we find the index of the function associated with it; that is, the closest previous step (call it \(k\)).

This index is then used to find the parameters of the function:

\[μₖ(t) = aₖ + exp(F (t - tₖ))bₖ\]

…where \(tₖ < t ≤ tₖ₊₁\).

Parameters

time_points – A tensor with shape [... num_data].

Returns

The mean function evaluated at the time points, with shape [... num_data, obs_dim].