osl_dynamics.inference.layers.MultiDynamicMVNLayer#

class osl_dynamics.inference.layers.MultiDynamicMVNLayer(n_modes, n_correlation_modes, n_channels, *, learn_means, learn_standard_deviations, learn_correlations, initial_means=None, initial_standard_deviations=None, initial_correlations=None, standard_deviations_epsilon=0.0, correlations_epsilon=0.0, means_regularizer=None, standard_deviations_regularizer=None, correlations_regularizer=None, pca_components=None, **kwargs)#

Bases: tensorflow.keras.layers.Layer

Multivariate normal observation model with separate mixing of the means/standard deviations and correlations.

The mean and standard deviations at each time point are mixed with alpha and the correlation with beta. The covariance is G F G, where G is the mixed (diagonal) standard deviation and F the mixed correlation. The parameters are projected with PCA components before mixing.

Parameters:
n_modesint

Number of modes for the means and standard deviations.

n_correlation_modesint

Number of modes for the correlations.

n_channelsint

Number of channels.

learn_meansbool

Should the means be trainable?

learn_standard_deviationsbool

Should the standard deviations be trainable?

learn_correlationsbool

Should the correlations be trainable?

initial_meansnp.ndarray, optional

Initial means.

initial_standard_deviationsnp.ndarray, optional

Initial standard deviations (diagonal matrices or diagonals).

initial_correlationsnp.ndarray, optional

Initial correlations.

standard_deviations_epsilonfloat, optional

Value added to the standard deviations.

correlations_epsilonfloat, optional

Value added to the diagonal of the correlations.

means_regularizercallable, optional

Regularizer for the means.

standard_deviations_regularizercallable, optional

Regularizer for the standard deviations.

correlations_regularizercallable, optional

Regularizer for the correlations.

pca_componentsnp.ndarray, optional

PCA components. Shape must be (n_channels, n_channels). Defaults to the identity.

summary_rows()#

Rows for the layer in the summary of a model.

Returns:
rowslist of tuple

(name, details, learned by, number of learned values) for each row.

log_likelihood(x, alpha, beta)#

Log-likelihood of each time point.

Parameters:
xtf.Tensor

Data. Shape is (batch_size, sequence_length, n_channels).

alphatf.Tensor

Mixing coefficients for the means and standard deviations. Shape is (batch_size, sequence_length, n_modes).

betatf.Tensor

Mixing coefficients for the correlations. Shape is (batch_size, sequence_length, n_correlation_modes).

Returns:
log_likelihoodtf.Tensor

Shape is (batch_size, sequence_length).

regularization()#

Regularization of the means, standard deviations and correlations.

Returns:
regularizationtf.Tensor

Scalar.