osl_dynamics.models.base.SessionMVNMixin#
- class osl_dynamics.models.base.SessionMVNMixin#
Bases:
MVNMixinMethods for models whose Keras model has a
SessionMVNLayercalledobs_model.get_means,get_covariancesand the corresponding setters are for the group parameters.- set_regularizers(training_data)#
Set regularizers for the means and covariances from the data.
A multivariate normal prior is applied to the means with
mu=0,sigma=diag((range/2)**2). Ifconfig.diagonal_covariances=True, a log-normal prior is applied to the diagonal of the covariances withmu=0,sigma=sqrt(log(2*range)), otherwise an inverse Wishart prior is applied to the covariances withnu=n_channels-1+0.1andpsi=diag(range).rangeis the range of each channel in the data. For models with session-specific parameters, these priors are on the group parameters, and the KL divergence of the deviation magnitudes and the regularization of the deviation decoders are divided by the number of sequences in the data (and the sequence length ifconfig.loss_reduction='mean').- Parameters:
- training_dataosl_dynamics.data.Data or tf.data.Dataset
Training data.
- free_energy(*args, **kwargs)#
Variational free energy.
A warning is logged if
set_regularizershas not been called, because the KL divergence of the session deviations is then left out.- Parameters:
- *args, **kwargs
Arguments of the
free_energymethod of the model:datasetandconcatenate(andverbosefor DIVE).
- Returns:
- free_energyfloat or np.ndarray
Free energy, or free energy of each session if
concatenate=False(shape (n_sessions,)).
- get_session_means()#
Get the session-specific means.
- Returns:
- meansnp.ndarray
Mean of each state or mode for each session. Shape is (n_sessions, n_states, n_channels) or (n_sessions, n_modes, n_channels).
- get_session_covariances()#
Get the session-specific covariances.
- Returns:
- covariancesnp.ndarray
Covariance of each state or mode for each session. Shape is (n_sessions, n_states, n_channels, n_channels) or (n_sessions, n_modes, n_channels, n_channels).
- get_label_embeddings()#
Embedding weights of each session label.
- Returns:
- embeddingsdict
For a categorical label, the embedding of each category (n_classes, embeddings_dim). For a continuous label, the kernel and bias of the dense layer.
- get_session_embeddings()#
Get the embedding of each session.
- Returns:
- embeddingsnp.ndarray
Embedding of each session (the sum of the embeddings of its labels). Shape is (n_sessions, embeddings_dim).
- get_means()#
Get the means.
- Returns:
- meansnp.ndarray
Mean of each state or mode. Shape is (n_states, n_channels) or (n_modes, n_channels).
- get_covariances()#
Get the covariances.
- Returns:
- covariancesnp.ndarray
Covariance of each state or mode. Shape is (n_states, n_channels, n_channels) or (n_modes, n_channels, n_channels).
- get_observation_model_parameters()#
Get the means and covariances.
- Returns:
- meansnp.ndarray
Mean of each state or mode. Shape is (n_states, n_channels) or (n_modes, n_channels).
- covariancesnp.ndarray
Covariance of each state or mode. Shape is (n_states, n_channels, n_channels) or (n_modes, n_channels, n_channels).
- set_embeddings(embeddings)#
Set the embeddings of session labels and reset the model.
- Parameters:
- embeddingsdict
Embedding weights for each label name, as returned by
get_label_embeddings: the embedding of each category (n_classes, embeddings_dim) for a categorical label and the kernel and bias of the dense layer for a continuous label.
- set_deviation_parameters(training_data)#
Set the initial deviation magnitudes from the data and reset the model.
The gamma distribution of the magnitude of each session is matched to the deviation of the session’s static mean (or Cholesky factor of the covariance) from the average over sessions.
- Parameters:
- training_dataosl_dynamics.data.Data or list of tf.data.Dataset
Training data. Must have one dataset for each session.
- set_means(means, update_initializer=True)#
Set the means.
- Parameters:
- meansnp.ndarray
Mean of each state or mode. Shape is (n_states, n_channels) or (n_modes, n_channels).
- update_initializerbool, optional
Should we use this value when the model is reset?
- set_covariances(covariances, update_initializer=True)#
Set the covariances.
- Parameters:
- covariancesnp.ndarray
Covariance of each state or mode. Shape is (n_states, n_channels, n_channels) or (n_modes, n_channels, n_channels). If the model has diagonal covariances, the diagonal is used.
- update_initializerbool, optional
Should we use this value when the model is reset?
- set_observation_model_parameters(parameters, update_initializer=True)#
Set the means and covariances.
- Parameters:
- parameterstuple
Means and covariances, as returned by
get_observation_model_parameters.- update_initializerbool, optional
Should we use these values when the model is reset?