markovflow.gauss_markov
Module representing a Gauss-Markov chain.
GaussMarkovDistribution
Bases: tf.Module, abc.ABC
tf.Module
abc.ABC
Abstract class for representing a Gauss-Markov chain. Classes that extend this one (such as StateSpaceModel) represent a different parameterisation of the joint Gaussian distribution.
StateSpaceModel
event_shape
Return the shape of the event in the Gauss-Markov chain that is [num_transitions + 1, state_dim].
[num_transitions + 1, state_dim]
batch_shape
Return the shape of any leading dimensions in the Gauss-Markov chain that come before event_shape.
state_dim
Return the state dimension of the Gauss-Markov chain.
num_transitions
Return the number of transitions in the Gauss-Markov chain.
_build_precision
Compute the compact banded representation of the precision matrix.
precision
Return the precision matrix of the joint Gaussian.
marginal_means
Return the marginal means of the joint Gaussian.
A tensor with shape batch_shape + [num_transitions + 1, state_dim].
batch_shape + [num_transitions + 1, state_dim]
marginal_covariances
Return the marginal covariances of the joint Gaussian.
A tensor with shape batch_shape + [num_transitions + 1, state_dim, state_dim].
batch_shape + [num_transitions + 1, state_dim, state_dim]
covariance_blocks
Return the diagonal and lower off-diagonal blocks of the covariance.
A tuple of tensors, with respective shapes batch_shape + [num_transitions + 1, state_dim], batch_shape + [num_transitions, state_dim, state_dim].
batch_shape + [num_transitions, state_dim, state_dim]
marginals
Return the means \(μₖ\) and the covariances \(Σₖₖ\) of the marginal distributions over consecutive states \(xₖ\).
The means and covariances, with respective shapes batch_shape + [num_transitions + 1, state_dim], batch_shape + [num_transitions + 1, state_dim, state_dim].
sample
Sample trajectories from the distribution.
sample_shape – The shape (and hence number of) trajectories to sample from the distribution.
The state samples, with shape sample_shape + self.batch_shape + self.event_shape.
sample_shape + self.batch_shape + self.event_shape
log_det_precision
Calculate the log determinant of the precision matrix.
A tensor with shape batch_shape.
log_pdf
Return the value of the log of the PDF evaluated at states.
That is:
states – The state trajectory, with shape sample_shape + self.batch_shape + self.event_shape.
The log pdf, with shape sample_shape + self.batch_shape.
sample_shape + self.batch_shape
create_trainable_copy
Create a trainable version.
This is primarily for use with variational approaches where we want to optimise the parameters of the Gauss-Markov distribution.
A Gauss-Markov distribution that is a copy of this one with trainable parameters.
create_non_trainable_copy
Create a non-trainable version.
Convert a trainable version of this class back to being non-trainable.
A Gauss-Markov distribution that is a copy of this one.
kl_divergence
Return the KL divergence of the current Gauss-Markov distribution from the specified input dist:
dist
To do so we first compute the marginal distributions from the Gauss-Markov form:
…where \(μᵢ\) are the marginal means and \(Pᵢ\) are the banded precisions.
The KL divergence is then given by:
…where \(N = (\verb|num_transitions| + 1) * \verb|state_dim|\) (that is, the dimensionality of the Gaussian).
dist – Another similarly-parameterised Gauss-Markov distribution.
The KL divergences, with shape self.batch_shape.
self.batch_shape
check_compatible
Check that two GaussMarkovDistribution objects are compatible.
If not, raise an exception.