osl_dynamics.inference.layers.SessionMVNLayer#
- class osl_dynamics.inference.layers.SessionMVNLayer(n_states, n_channels, *, session_labels, embeddings_dim, spatial_embeddings_dim, unit_norm_embeddings, learn_means, learn_covariances, initial_means=None, initial_covariances=None, covariances_epsilon=0.0, means_regularizer=None, covariances_regularizer=None, deviation_kwargs=None, **kwargs)#
Bases:
tensorflow.keras.layers.LayerMultivariate normal observation model with session-specific means and covariances.
The session-specific parameters are the group parameters plus a deviation for each session (
SessionDeviationLayer). The covariance deviations are added to the flattened Cholesky factors.- Parameters:
- n_statesint
Number of states/modes.
- n_channelsint
Number of channels.
- session_labelslist of osl_dynamics.data.SessionLabels
Labels for each session. The session embedding is the sum of the embeddings of its labels.
- embeddings_dimint
Dimension of the session embeddings.
- spatial_embeddings_dimint
Dimension of the spatial embeddings.
- unit_norm_embeddingsbool
Should the embeddings of categorical labels have unit norm?
- learn_meansbool
Should the means be trainable? If not, the means have no deviations.
- learn_covariancesbool
Should the covariances be trainable? If not, the covariances have no deviations.
- initial_meansnp.ndarray, optional
Initial group means.
- initial_covariancesnp.ndarray, optional
Initial group covariances.
- covariances_epsilonfloat, optional
Value added to the diagonal of the covariances.
- means_regularizercallable, optional
Regularizer for the group means.
- covariances_regularizercallable, optional
Regularizer for the group covariances.
- deviation_kwargsdict, optional
Settings for the decoders of the deviations (see
MultiLayerPerceptronLayer).
- 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.
- session_embeddings()#
Embedding of each session.
- Returns:
- embeddingstf.Tensor
Shape is (n_sessions, embeddings_dim).
- set_static_loss_scale(scale)#
Set the scale of the losses that occur once for a dataset: the KL divergence of the deviation magnitudes and the regularization of the deviation decoders. The scale is saved with the weights.
- Parameters:
- scalefloat
Scale.
- session_parameters(training=None, session_id=None)#
Session-specific means and covariances.
- Parameters:
- trainingbool, optional
Training mode (for dropout).
- session_idtf.Tensor, optional
Sessions to return the parameters of. Shape is (n,). Defaults to all sessions.
- Returns:
- meanstf.Tensor
Shape is (n, n_states, n_channels).
- covariancestf.Tensor
Shape is (n, n_states, n_channels, n_channels).
- kltf.Tensor
KL divergence of the deviation magnitudes of the means and covariances (if they are learned), multiplied by
static_loss_scale.
- batch_parameters(inputs, training=None)#
Means and covariances of the session of each sequence in a batch.
- Parameters:
- inputsdict
Batch with
session_id, the session of each time point. Shape is (batch_size, sequence_length).- trainingbool, optional
Training mode (for dropout).
- Returns:
- meanstf.Tensor
Shape is (batch_size, n_states, n_channels).
- covariancestf.Tensor
Shape is (batch_size, n_states, n_channels, n_channels).
- kltf.Tensor
KL divergence returned by
session_parameters.
- regularization()#
Regularization of the group parameters and the deviation decoders.
- Returns:
- regularizationtf.Tensor
Scalar.