markovflow.kernels.sde_kernel

Module containing Stochastic Differential Equation (SDE) kernels.

Module Contents

class SDEKernel(output_dim: int = 1, jitter: float = 0)[source]

Bases: markovflow.kernels.kernel.Kernel, abc.ABC

Abstract class representing kernels defined by the Stochastic Differential Equation:

\[\begin{split}&dx(t)/dt = F(t) x(t) + L(t) w(t),\\ &f(t) = H(t) x(t)\end{split}\]

For most kernels \(F, L, H\) are not time varying; these have the more restricted form:

\[\begin{split}&dx(t)/dt = F x(t) + L w(t),\\ &f(t) = H x(t)\end{split}\]

…with \(w(t)\) white noise process with spectral density \(Q_c\), where:

\[\begin{split}&x ∈ ℝ^d\\ &F, L ∈ ℝ^{d × d}\\ &H ∈ ℝ^{d × o}\\ &Q_c ∈ ℝ^d\\ &d \verb|is the state dimension|\\ &o \verb|is the observation dimension|\end{split}\]

See the documentation for the StationaryKernel class.

Usually:

\[x(t) = [a(t), da(t)/dt, d²a(t)/dt ...]\]

…for some \(a(t)\), so the state dimension represents the degree of the stochastic differential equation in terms of \(a(t)\). Writing it in the above form is a standard trick for converting a higher order linear differential equation into a first order linear one.

Since \(F, L, H\) are constant matrices, the solution can be written analytically. For a given set of time points \(tₖ\), we can solve this SDE and define a state space model of the form:

\[xₖ₊₁ = Aₖ xₖ + bₖ + qₖ\]

…where:

\[\begin{split}&qₖ \sim 𝓝(0, Qₖ)\\ &x₀ \sim 𝓝(μ₀, P₀)\\ &xₖ ∈ ℝ^d\\ &Aₖ ∈ ℝ^{d × d}\\ &bₖ ∈ ℝ^d\\ &Qₖ ∈ ℝ^{d × d}\\ &μ₀ ∈ ℝ^{d × 1}\\ &P₀ ∈ ℝ^{d × d}\end{split}\]

If \(Δtₖ = tₖ₊₁ - tₖ\), then the transition matrix \(Aₜ\) between states \(x(tₖ)\) and \(x(tₖ₊₁)\) is given by:

\[Aₖ = exp(FΔtₖ)\]

The process noise covariance matrix \(Qₖ\) between states \(x(tₖ)\) and \(x(tₖ₊₁)\) is given by:

\[Qₖ = ∫ exp(F (Δtₖ - τ)) L Q_c Lᵀ exp(F (Δtₖ - τ))ᵀ dτ\]

We can write this in terms of the steady state covariance \(P∞\) as:

\[Qₖ = P∞ - Aₖ P∞ Aₖᵀ\]

We also define an emission model for a given output dimension:

\[fₖ = H xₖ\]

…where:

\[\begin{split}&x ∈ ℝ^d\\ &f ∈ ℝ^m\\ &H ∈ ℝ^{m × d}\\ &m \verb| is the output_dim|\end{split}\]
Parameters
  • output_dim – The output dimension of the kernel.

  • jitter – A small non-negative number to add into a matrix’s diagonal to maintain numerical stability during inversion.

property output_dimint[source]

Return the output dimension of the kernel.

build_finite_distribution(time_points: tf.Tensor)markovflow.gauss_markov.GaussMarkovDistribution[source]

Return the GaussMarkovDistribution that this kernel represents on the provided time points.

Note

Currently the only representation we can use is StateSpaceModel.

Parameters

time_points – The times between which to define the distribution, with shape batch_shape + [num_data].

state_space_model(time_points: tf.Tensor)markovflow.state_space_model.StateSpaceModel[source]

Return the StateSpaceModel that this kernel represents on the provided time points.

Parameters

time_points – The times between which to define the state space model, with shape batch_shape + [num_data]. This must be strictly increasing.

generate_emission_model(time_points: tf.Tensor)markovflow.emission_model.EmissionModel[source]

Generate the EmissionModel associated with this kernel that maps from the latent StateSpaceModel to the observations.

For any SDEKernel, the state representation is usually:

\[x(t) = [a(t), da(t)/dt, d²a(t)/dt ...] \verb| for some | a(t)\]

In this case, we are interested only in the first element of \(x\). That is, the output \(f(t)\) is given by \(f(t) = a(t)\), so \(H\) is given by \([1, 0, 0, ...]\).

If different behaviour is required, this method should be overridden.

Parameters

time_points – The time points over which the emission model is defined, with shape batch_shape + [num_data].

initial_mean(batch_shape: tf.TensorShape)tf.Tensor[source]

Return the initial mean of the generated StateSpaceModel.

This will usually be zero, but can be overridden if necessary.

Parameters

batch_shape – Leading dimensions for the initial mean.

Returns

A tensor of zeros with shape batch_shape + [state_dim].

property state_dimint[source]

Return the state dimension of the generated StateSpaceModel.

abstract initial_covariance(initial_time_point: tf.Tensor)tf.Tensor[source]

Return the initial covariance of the generated StateSpaceModel.

For stationary kernels this is typically the covariance of the stationary distribution for \(x, P∞\).

In the general case the initial covariance depends on time, so we need the initial_time_point to generate it.

Parameters

initial_time_point – The time_point associated with the first state, with shape batch_shape + [1,].

Returns

A tensor with shape batch_shape + [state_dim, state_dim].

transition_statistics_from_time_points(time_points: tf.Tensor)[source]

Generate the transition matrices when the time deltas are between adjacent time_points.

Parameters

time_points – A tensor of times at which to produce matrices, with shape batch_shape + [num_transitions + 1].

Returns

A tuple of two tensors, with respective shapes batch_shape + [num_transitions, state_dim, state_dim] batch_shape + [num_transitions, state_dim, state_dim].

abstract transition_statistics(transition_times: tf.Tensor, time_deltas: tf.Tensor)Tuple[tf.Tensor, tf.Tensor][source]

Return the state_transitions() and process_covariances() together to save having to compute them twice.

Parameters
  • transition_times – A tensor of times at which to produce matrices, with shape batch_shape + [num_transitions].

  • time_deltas – A tensor of time gaps for which to produce matrices, with shape batch_shape + [num_transitions].

Returns

A tuple of two tensors, with respective shapes batch_shape + [num_transitions, state_dim, state_dim]. batch_shape + [num_transitions, state_dim, state_dim].

abstract state_offsets(transition_times: tf.Tensor, time_deltas: tf.Tensor)tf.Tensor[source]

Return the state offsets \(bₖ\) of the generated StateSpaceModel.

Parameters
  • transition_times – A tensor of times at which to produce matrices, with shape batch_shape + [num_transitions].

  • time_deltas – A tensor of time gaps for which to produce matrices, with shape batch_shape + [num_transitions].

Returns

A tensor with shape batch_shape + [num_transitions, state_dim].

abstract state_transitions(transition_times: tf.Tensor, time_deltas: tf.Tensor)tf.Tensor[source]

Return the state transition matrices of the generated StateSpaceModel \(Aₖ = exp(FΔtₖ)\).

Parameters
  • transition_times – Time points at which to produce matrices, with shape batch_shape + [num_transitions].

  • time_deltas – Time gaps for which to produce matrices, with shape batch_shape + [num_transitions].

Returns

A tensor with shape batch_shape + [num_transitions, state_dim, state_dim].

process_covariances(transition_times: tf.Tensor, time_deltas: tf.Tensor)tf.Tensor[source]

Return the process covariance matrices of the generated StateSpaceModel.

The process covariance at time \(k\) is calculated as:

\[Qₖ = P∞ - Aₖ P∞ Aₖᵀ\]

These transition matrices can be overridden for more specific use cases if necessary.

Parameters
  • transition_times – Time points at which to produce matrices, with shape batch_shape + [num_transitions].

  • time_deltas – Time gaps for which to produce matrices, with shape batch_shape + [num_transitions].

Returns

A tensor with shape batch_shape + [num_transitions, state_dim, state_dim].

property jitter_matrixtf.Tensor[source]

Jitter to add to the output of process_covariances() and initial_covariance() shape.

Returns

A tensor with shape [state_dim, state_dim].

__add__(other: SDEKernel)Sum[source]

Operator for combining kernel objects by summing them.

__mul__(other: SDEKernel)Product[source]

Operator for combining kernel objects by multiplying them.

class StationaryKernel(output_dim: int = 1, jitter: float = 0, state_mean: Optional[tf.Tensor] = None, **kwargs)[source]

Bases: SDEKernel, abc.ABC

Abstract class representing stationary kernels defined by the Stochastic Differential Equation:

\[\begin{split}&dx(t)/dt = F x(t) + L w(t),\\ &f(t) = H(t) x(t)\end{split}\]

For most kernels \(H\) will not be time varying; that is, \(f(t) = H x(t)\).

Parameters
  • output_dim – The output dimension of the kernel.

  • state_mean – A tensor with shape [state_dim,].

initial_mean(batch_shape: tf.TensorShape)tf.Tensor[source]

Return the initial mean of the generated StateSpaceModel.

This will usually be zero, but can be overridden if necessary.

Parameters

batch_shape – Leading dimensions for the initial mean.

Returns

A tensor of zeros with shape batch_shape + [state_dim].

set_state_mean(state_mean: tf.Tensor, trainable: bool = False)[source]

Sets the state mean for the kernel.

Parameters
  • state_mean – A tensor with shape [state_dim,].

  • trainable – Boolean value to set the state mean trainable.

initial_covariance(initial_time_point: tf.Tensor)tf.Tensor[source]

Return the initial covariance of the generated StateSpaceModel.

For stationary kernels this is the covariance of the stationary distribution for \(x,P∞\) and is independent of the time passed in.

Parameters

initial_time_point – The time point associated with the first state, with shape batch_shape + [1,].

Returns

A tensor with shape batch_shape + [state_dim, state_dim].

transition_statistics(transition_times: tf.Tensor, time_deltas: tf.Tensor)Tuple[tf.Tensor, tf.Tensor][source]

Return state_transitions() and process_covariances() together to save having to compute them twice.

By default this uses the state transitions to calculate the process covariance:

\[Qₖ = P∞ - Aₖ P∞ Aₖᵀ\]
Parameters
  • transition_times – A tensor of times at which to produce matrices, with shape batch_shape + [num_transitions].

  • time_deltas – A tensor of time gaps for which to produce matrices, with shape batch_shape + [num_transitions].

Returns

A tuple of two tensors, with respective shapes batch_shape + [num_transitions, state_dim, state_dim]. batch_shape + [num_transitions, state_dim, state_dim].

property feedback_matrixtf.Tensor[source]

Return the feedback matrix \(F\). This is where:

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

A tensor with shape [state_dim, state_dim].

state_offsets(transition_times: tf.Tensor, time_deltas: tf.Tensor)tf.Tensor[source]

\(dx = F (x - m)dt o x(t) = A x(0) + (I-A)m\)

Parameters
  • transition_times – A tensor of times at which to produce matrices, with shape batch_shape + [num_transitions].

  • time_deltas – A tensor of time gaps for which to produce matrices, with shape batch_shape + [num_transitions].

Returns

A tensor with shape batch_shape + [num_transitions, state_dim]

property steady_state_covariancetf.Tensor[source]

Return the steady state covariance \(P∞\), given implicitly by:

\[F P∞ + P∞ Fᵀ + LQ_cLᵀ = 0\]
Returns

A tensor with shape [state_dim, state_dim].

property state_meantf.Tensor[source]

Return the state mean.

Returns

A tensor with shape [state_dim,].

class NonStationaryKernel(output_dim: int = 1, jitter: float = 0)[source]

Bases: SDEKernel, abc.ABC

Abstract class representing non-stationary kernels defined by the Stochastic Differential Equation:

\[\begin{split}&dx(t)/dt = F(t) x(t) + L(t) w(t),\\ &f(t) = H(t) x(t)\end{split}\]

For most kernels \(H\) will not be time varying; that is, \(f(t) = H x(t)\).

Parameters
  • output_dim – The output dimension of the kernel.

  • jitter – A small non-negative number to add into a matrix’s diagonal to maintain numerical stability during inversion.

abstract feedback_matrices(time_points: tf.Tensor)tf.Tensor[source]

The non-stationary feedback matrix \(F(t)\) at times \(t\), where:

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

time_points – The times at which the feedback matrix is evaluated, with shape batch_shape + [num_time_points].

Returns

A tensor with shape batch_shape + [num_time_points, state_dim, state_dim].

abstract state_offsets(transition_times: tf.Tensor, time_deltas: tf.Tensor)tf.Tensor[source]

Return the state offsets \(bₖ\) of the generated StateSpaceModel.

This will usually be zero, but can be overridden if necessary. :param transition_times: A tensor of times at which to produce matrices, with shape

batch_shape + [num_transitions].

Parameters

time_deltas – A tensor of time gaps for which to produce matrices, with shape batch_shape + [num_transitions].

Returns

A tensor with shape batch_shape + [num_transitions, state_dim]

class ConcatKernel(kernels: List[SDEKernel], jitter: float = 0.0)[source]

Bases: StationaryKernel, abc.ABC

Abstract class implementing the state space model of multiple kernels that have been combined together. Combined with differing emission models this can give rise to the Sum kernel or to a multi-output kernel.

The state space of any ConcatKernel consists of all the state spaces of child kernels concatenated (in the tensorflow.concat sense) together:

\[\begin{split}[x¹(t),\\ x²(t)]\end{split}\]

So the SDE of the kernel becomes:

\[\begin{split}&dx(t)/dt = &[[F¹ 0], &[x¹(t) &[[L¹ 0], &[w¹(t),\\ & &[0 F²]] &x²(t)] + &[0 L²]] &w²(t)]\\ &f(t) = [H¹ H²] x(t)\end{split}\]
Parameters
  • kernels – A list of child kernels that will have their state spaces concatenated together.

  • jitter – A small non-negative number to add into a matrix’s diagonal to maintain numerical stability during inversion.

property state_dimint[source]

Return the state dimension of the generated StateSpaceModel.

property kernelsList[SDEKernel][source]

Return a list of child kernels.

state_transitions(transition_times: tf.Tensor, time_deltas: tf.Tensor)tf.Tensor[source]

Return the state transition matrices of the generated StateSpaceModel \(Aₖ = exp(FΔtₖ)\).

The state transition matrix is the block diagonal matrix of the child state transition matrices.

Parameters
  • transition_times – A tensor of times at which to produce matrices, with shape batch_shape + [num_transitions].

  • time_deltas – A tensor of time gaps for which to produce matrices, with shape batch_shape + [num_transitions].

Returns

A tensor with shape batch_shape + [num_transitions, state_dim, state_dim].

initial_mean(batch_shape: tf.TensorShape)tf.Tensor[source]

Return the initial mean of the generated StateSpaceModel.

The combined mean is the child means concatenated together:

\[[μ1 μ2, ...]\]

…to form a longer mean vector.

Parameters

batch_shape – A tuple of leading dimensions for the initial mean.

Returns

A tensor of zeros with shape batch_shape + [state_dim].

property feedback_matrixtf.Tensor[source]

Return the feedback matrix. This is the block diagonal matrix of child feedback matrices.

Returns

A tensor with shape [state_dim, state_dim].

property steady_state_covariancetf.Tensor[source]

Return the steady state covariance. This is the block diagonal matrix of child steady state covariance matrices.

Returns

A tensor with shape [state_dim, state_dim].

class Sum(kernels: List[SDEKernel], jitter: float = 0.0)[source]

Bases: ConcatKernel

Sums a list of child kernels.

There are two ways to implement this kernel: Stacked and Concatenated.

This class implements the Concatenated version, where the state space of the Sum kernel includes covariance terms between the child kernels.

Parameters
  • kernels – A list of child kernels that will have their state spaces concatenated together.

  • jitter – A small non-negative number to add into a matrix’s diagonal to maintain numerical stability during inversion.

generate_emission_model(time_points: tf.Tensor)markovflow.emission_model.EmissionModel[source]

Generate the emission matrix \(H\). This is the concatenation:

\[H = [H₁, H₂, ..., Hₙ]\]

…where \(\{Hᵢ\}ₙ\) are the emission matrices of the child kernels. Thus the state dimension for this kernel is the sum of the state dimension of the child kernels.

Parameters

time_points – The time points over which the emission model is defined, with shape batch_shape + [num_data].

Returns

The emission model associated with this kernel, with emission matrix with shape batch_shape + [num_data, output_dim, state_dim].

class Product(kernels: List[SDEKernel], jitter: float = 0.0)[source]

Bases: StationaryKernel

Multiplies a list of child kernels.

The feedback matrix is the Kronecker product of the feedback matrices from the child kernels. We will use a product kernel with two child kernels as an example. Let \(A\) and \(B\) be the feedback matrix from these two child kernels. The feedback matrix \(F\) of the product kernel is:

\[\begin{split}&F &= &A ⊗ B\\ & &= &[[A₁₁ B, ..., A₁ₙ B],\\ & & &...,\\ & & &[Aₙ₁ B, ..., Aₙₙ B]]\end{split}\]

…where \(⊗\) is the Kronecker product operator.

The state transition matrix is the Kronecker product of the state transition matrices from the child kernels. Let \(Aₖ\) and \(Bₖ\) be the state transition matrix from these two child kernels at time step \(k\). The state transition matrix \(Sₖ\) of the product kernel is:

\[\begin{split}&Sₖ &= &Aₖ ⊗ Bₖ\\ & &= &[[Aₖ₁₁ Bₖ, ..., Aₖ₁ₙ Bₖ],\\ & & &...,\\ & & &[Aₖₙ₁ Bₖ, ..., Aₖₙₙ Bₖ]]\end{split}\]

The steady state covariance matrix is the Kronecker product of the steady covariance matrix from the child kernels. Let \(A∞\) and \(B∞\) be the steady covariance matrix from these two child kernels. The state transition matrix \(P∞\) of the product kernel is:

\[\begin{split}&P∞ &= &A∞ ⊗ B∞\\ & &= &[[A∞₁₁ B∞, ..., A∞ B∞],\\ & & &...,\\ & & &[A∞ₙ₁ B∞, ..., A∞ₙₙ B∞]]\end{split}\]

The process covariance matrix \(Qₖ\) at time step \(k\) is calculated using the same formula as defined in the parent class SDEKernel:

\[Qₖ = P∞ - Sₖ P∞ Sₖᵀ\]

…where the steady state matrix \(P∞\) and the state transition \(Sₖ\) are defined above.

Parameters
  • kernels – An iterable over the kernels to be multiplied together.

  • jitter – A small non-negative number to add into a matrix’s diagonal to maintain numerical stability during inversion.

property state_dimint[source]

Return the state dimension of the generated StateSpaceModel.

property kernelsList[SDEKernel][source]

Return a list of child kernels.

state_transitions(transition_times: tf.Tensor, time_deltas: tf.Tensor)tf.Tensor[source]

Return the state transition. This is the Kronecker product of the child state transitions.

Parameters
  • transition_times – A tensor of times at which to produce matrices, shape batch_shape + [num_transitions].

  • time_deltas – A tensor of time gaps for which to produce matrices, shape batch_shape + [num_transitions].

Returns

A tensor with shape batch_shape + [num_transitions, state_dim, state_dim].

property feedback_matrixtf.Tensor[source]

Return the feedback matrix. This is the Kronecker product of the child feedback matrices.

Returns

A tensor with shape [state_dim, state_dim].

property steady_state_covariancetf.Tensor[source]

Return the steady state covariance. This is the Kronecker product of the child steady state covariances.

Returns

A tensor with shape [state_dim, state_dim].

generate_emission_model(time_points: tf.Tensor)markovflow.emission_model.EmissionModel[source]

Generate the emission matrix. This is the Kronecker product of all the child emission matrices.

Parameters

time_points – The time points over which the emission model is defined, with shape batch_shape + [num_data].

class IndependentMultiOutput(kernels: List[SDEKernel], jitter: float = 0.0)[source]

Bases: ConcatKernel

Takes a concatenated state space model consisting of multiple child kernels and projects the state space associated with each kernel into a separate observation vector.

The result is similar to training several kernels on the same data separately, except that because of the covariance terms in the state space there can be correlation between the separate observation vectors.

Parameters
  • kernels – An iterable over child kernels which will have their state spaces concatenated together.

  • jitter – A small non-negative number to add into a matrix’s diagonal to maintain numerical stability during inversion.

generate_emission_model(time_points: tf.Tensor)markovflow.emission_model.EmissionModel[source]

Generate the emission matrix \(H\). This is the direct sum of the child emission matrices, for example:

\[H = H₁ ⊕ H₂ ⊕ ... ⊕ Hₙ\]

…where \(\{Hᵢ\}ₙ\) are the emission matrices of the child kernels.

Parameters

time_points – The time points over which the emission model is defined, with shape batch_shape + [num_data].

Returns

The emission model associated with this kernel.

class FactorAnalysisKernel(weight_function: Callable[[gpflow.base.TensorType], gpflow.base.TensorType], kernels: List[SDEKernel], output_dim: int, trainable: bool = True, jitter: float = 0.0)[source]

Bases: ConcatKernel

Produces an emission model which performs a linear mixing of Gaussian processes according to a known time varying weight function and a learnable loading matrix:

\[fᵢ(t) = Σⱼₖ Aᵢⱼ(t)Bⱼₖgₖ(t)\]

…where:

  • \(\{fᵢ\}ₙ\) are the observable processes

  • \(\{gₖ\}ₘ\) are the latent GPs

  • \(A^{n × m}\) is a known, possibly time dependant, weight matrix

  • \(B^{m × m}\) is either the identity or a trainable loading matrix

Parameters
  • weight_function – A function that, given TensorType time points with shape batch_shape + [num_data, ], returns a weight matrix with the relative mixing of the tensors, with shape batch_shape + [num_data, output_dim, n_latents].

  • kernels – An iterable over child kernels that will have their state spaces concatenated together, with shape [n_latents, ].

  • output_dim – The output dimension of the kernel. This should have the same shape as the output_dim of the weight matrix returned by the weight function.

  • trainable – Whether the loading matrix \(B\) should be trainable.

  • jitter – A small non-negative number to add into a matrix’s diagonal to maintain numerical stability during inversion.

generate_emission_model(time_points: tf.Tensor)markovflow.emission_model.EmissionModel[source]

Generate the emission matrix \(WH\). This is where:

\[H = H₁ ⊕ H₂ ⊕ ... ⊕ Hₙ\]

…as per the multi-output kernel, and \(W = AB\).

Parameters

time_points – The time points over which the emission model is defined, with shape batch_shape + [num_data, ].

Returns

The emission model associated with this kernel.

class StackKernel(kernels: List[SDEKernel], jitter: float = 0.0)[source]

Bases: StationaryKernel

Implements the state space model of multiple kernels that have been combined together. Unlike a ConcatKernel, it manages the multiple kernels by introducing a leading dimension (stacking), rather than forming a block diagonal form of each parameter explicitly.

The prior of both a StackKernel and a ConcatKernel is the same (independent). However, posterior state space models built upon a StackKernel will maintain this independency, in contrast to the posteriors building upon a ConcatKernel, which model correlations between the processes.

Combined with different emission models this can give rise to a multi-output stack kernel, and perhaps in the future an additive kernel.

The state space of this kernel consists of all the state space of the child kernels stacked (in the tensorflow.stack sense) together, with padded zeros when the state space of one of the kernels is larger than any of the others:

[ x₁⁽¹⁾(t) ] ᨞
[   0   ]   [ x₁⁽ᵐ⁾(t) ]
          ᨞ [ x₂⁽ᵐ⁾(t) ]

…where \(m\) are the number of kernels / outputs.

So the SDE of the kernel becomes:

dx(t)/dt = [F⁽¹⁾] ᨞   [x⁽¹⁾(t)] ᨞    + [L⁽¹⁾] ᨞    [w⁽¹⁾(t)] ᨞
              ᨞ [F⁽ᵐ⁾]   ᨞ [x⁽ᵐ⁾(t)]      ᨞ [L⁽ᵐ⁾]    ᨞ [w⁽ᵐ⁾(t)]

f(t) = [H⁽¹⁾] ᨞   [x⁽¹⁾(t)] ᨞
          ᨞ [H⁽ᵐ⁾]   ᨞ [x⁽ᵐ⁾(t)]
Parameters
  • kernels – A list of child kernels that will have their state spaces concatenated together. Since we model each output independently, the length of the kernel list defines the number of the outputs. Note that each kernel should have individual output_dim 1.

  • jitter – A small non-negative number to add into a matrix’s diagonal to maintain numerical stability during inversion.

property state_dimint[source]

Return the state dimension of the generated StateSpaceModel.

property kernelsList[SDEKernel][source]

Return a list of child kernels.

_check_batch_shape_is_compatible(batch_shape: tf.TensorShape)None[source]

Helper method to check the compatibility of batch_shape. For the StackKernel the batch_shape must have the following shape:

(…, num_kernels)

In any other case this method raises a tf.errors.InvalidArgumentError.

Parameters

batch_shape – a tuple with the shape to check

state_transitions(transition_times: tf.Tensor, time_deltas: tf.Tensor)tf.Tensor[source]

Return the state transition matrices of the generated StateSpaceModel \(Aₖ = exp(FΔtₖ)\).

The state transition matrix is the stacked matrix of the child state transition matrices, padded with zeros (if necessary) to match the largest state dim across kernels.

Parameters
  • transition_times – A tensor of times at which to produce matrices, with shape batch_shape + [num_transitions].

  • time_deltas – A tensor of time gaps for which to produce matrices, with shape batch_shape + [num_transitions] where batch_shape = (..., num_kernels).

Returns

A tensor with shape batch_shape + [num_transitions, state_dim, state_dim] where batch_shape = (..., num_kernels).

initial_mean(batch_shape: tf.TensorShape)tf.Tensor[source]

Return the initial mean of the generated StateSpaceModel.

This will usually be zero, but can be overridden if necessary.

We override SDEKernel.initial_mean() from the parent class to check there is a compatible batch_shape.

Parameters

batch_shape – A tuple of leading dimensions for the initial mean, where batch_shape can be (..., num_kernels).

Returns

A tensor of zeros with shape batch_shape + [state_dim], where batch_shape = (..., num_kernels).

state_offsets(transition_times: tf.Tensor, time_deltas: tf.Tensor)tf.Tensor[source]

Return the state offsets \(bₖ\) of the generated StateSpaceModel.

This will usually be zero, but can be overridden if necessary.

We override SDEKernel.state_offsets() from the parent class to check there is a compatible batch_shape.

Parameters
  • transition_times – A tensor of times at which to produce matrices, with shape batch_shape + [num_transitions].

  • time_deltas – A tensor of time gaps for which to produce matrices, with shape batch_shape + [num_transitions].

Returns

A tensor with shape batch_shape + [num_transitions, state_dim]

property feedback_matrixtf.Tensor[source]

Return the feedback matrix. This is the stacked matrix of child feedback matrices, padded with zeros to have matching state dims.

Returns

A tensor with shape [num_kernels, state_dim, state_dim].

property steady_state_covariancetf.Tensor[source]

Return the steady state covariance. This is the stacked matrix of child steady state covariance matrices, padded with the identity (if necessary) to have matching state dims.

Note that we further append a singleton dimensions after the num_kernels so it can broadcast across the number of data.

Returns

A tensor with shape [num_kernels, 1, state_dim, state_dim].

initial_covariance(initial_time_point: tf.Tensor)tf.Tensor[source]

Return the initial covariance of the generated StateSpaceModel.

This is typically the covariance of the stationary distribution for \(x, P∞\).

We override SDEKernel.initial_covariance() from the parent class to check there is a compatible batch_shape.

Parameters

initial_time_point – The time point associated with the first state, shape batch_shape + [1,].

Returns

A tensor with shape batch_shape + [state_dim, state_dim], where batch_shape = (..., num_kernels).

class IndependentMultiOutputStack(kernels: List[SDEKernel], jitter: float = 0.0)[source]

Bases: StackKernel

Takes a stacked state space model consisting of multiple child kernels and projects the state space associated with each kernel into a separate observation vector.

The result is similar to training several kernels on the same data separately. There will be no correlations between the processes, in the prior or the posterior.

Parameters
  • kernels – An iterable over child kernels which will have their state spaces concatenated together. Since we model each output independently the length of the kernel list defines the number of the outputs.

  • jitter – A small non-negative number to add into a matrix’s diagonal to maintain numerical stability during inversion.

generate_emission_model(time_points: tf.Tensor)markovflow.emission_model.EmissionModel[source]

Generate the emission matrix \(H\). This is a stacking of the child emission matrices, which are first augmented (if necessary) so that they have the same state_dim.

Parameters

time_points – The time points over which the emission model is defined, with shape batch_shape + [num_data] where batch_shape = (..., num_kernels).

Returns

The emission model associated with this kernel.

__add__(other: IndependentMultiOutputStack)IndependentMultiOutputStack[source]

Operator for combining kernel objects by summing them.

Overrides the base class SDEKernel.__add__() method.

__mul__(other: IndependentMultiOutputStack)IndependentMultiOutputStack[source]

Operator for combining kernel objects by multiplying them.

Overrides the base class SDEKernel.__mul__() method.