markovflow.utils
Module containing utility functions.
tf_scope_fn_decorator
Decorator to wrap the function call in a name_scope of the form “.{name of function}”.
The prefix . is required because names_scopes cannot be prefixed with _.
.
_
Without this some function names (such as private functions) would raise an error.
tf_scope_class_decorator
Decorator to wrap all the methods in a class in a name_scope of the form “{name of class}.{name of method}”.
Do not decorate the top level; TensorBoard renders badly if there is only one block.
block_diag
Construct block diagonal matrices from a list of batched 2D tensors.
matrices – A list of tensors with shape [..., Nᵢ, Mᵢ]. That is, a list of matrices with the same batch dimension.
[..., Nᵢ, Mᵢ]
A matrix with the input matrices stacked along its main diagonal, with shape [..., ∑ᵢ,Nᵢ, ∑ᵢ,Mᵢ].
[..., ∑ᵢ,Nᵢ, ∑ᵢ,Mᵢ]
to_delta_time
Convert a tensor of time points to differences between the times. This function returns:
Time points must be a strictly increasing vector, for example:
time_points – A tensor \(tₖ\) with shape [..., a].
[..., a]
A tensor \(Δtₖ\) with shape [..., a - 1].
[..., a - 1]
InvalidArgumentError – Raises if \(Δtₖ ≤ 0\).
kronecker_product
Return the tensor representing the Kronecker product of the argument matrices.
matrices – The list of matrices to compute the Kronecker product from.
The Kronecker product tensor.
augment_square_matrix
Augment a square matrix to match state_dim + extra_dim, where state_dim is the dimensionality of the inner square matrix of matrix.
state_dim + extra_dim
state_dim
Effectively it creates a block diagonal by padding (if necessary) with an identity or zeros:
matrix – A tensor with shape [..., state_dim, state_dim].
[..., state_dim, state_dim]
extra_dim – The extra dimension we want to augment it with. If extra_dim is \(0\), the matrix remains unaltered.
extra_dim
fill_zeros – Whether to fill with zeros or identity.
A tensor with shape [..., max_dim, max_dim], where max_dim = state_dim + extra_dim.
[..., max_dim, max_dim]
max_dim = state_dim + extra_dim
augment_matrix
Augment a non-square matrix so that the last dimension becomes state_dim + extra_dim, where state_dim is the size of the last dimension of the matrix.
Effectively it expands the matrix (if necessary) with zeros in the last dimension to match max_dim = state_dim + extra_dim. In other words:
matrix – A tensor with shape [..., state_dim].
[..., state_dim]
extra_dim – The extra dimension we want to augment it with. If extra_dim is \(0\) the matrix remains unaltered.
A tensor with shape [..., max_dim], where max_dim = state_dim + extra_dim.
[..., max_dim]
batch_base_conditional
p_n(g2_n) = N(g2_n; 0, Kmm) (independent of n) p_n(g1_n) = N(g1; 0, knn) p_n(g1_n | g2_n) = N(g1_n; knm (Kmm⁻¹) g2_n, knn - knm (Kmm⁻¹) kmn)
q_n(g2_n) = N(g2_n; f_n, q_sqrt_n q_sqrt_nᵀ)
q_n(g1_n) = ∫ q_n(g2_n) p_n(g1_n| g2_n)
Kmn – [M, …, N]
Kmm – [M, M]
Knn – […, N, N] or N
f – [M, N]
q_sqrt – If this is a Tensor, it must have shape [N, M, M] (lower triangular) or [M, N] (diagonal)
white – bool
[N,], [N,]