osl_dynamics.models.simplified_dynemo
#
Simplified DyNeMo.
See the documentation for a description of this model.
See also
C. Gohil, et al., “Mixtures of large-scale functional brain network modes”. Neuroimage 263, 119595 (2022).
Module Contents#
Classes#
Settings for Simplified DyNeMo. |
|
Simplified DyNeMo model class. |
- class osl_dynamics.models.simplified_dynemo.Config[source]#
Bases:
osl_dynamics.models.mod_base.BaseModelConfig
,osl_dynamics.models.inf_mod_base.VariationalInferenceModelConfig
Settings for Simplified DyNeMo.
- Parameters:
model_name (str) – Model name.
n_modes (int) – Number of modes.
n_channels (int) – Number of channels.
sequence_length (int) – Length of sequence passed to the inference network and generative model.
model_rnn (str) – RNN to use, either
'gru'
or'lstm'
.model_n_layers (int) – Number of layers.
model_n_units (int) – Number of units.
model_normalization (str) – Type of normalization to use. Either None,
'batch'
or'layer'
.model_activation (str) – Type of activation to use after normalization and before dropout. E.g.
'relu'
,'elu'
, etc.model_dropout (float) – Dropout rate.
model_regularizer (str) – Regularizer.
learn_alpha_temperature (bool) – Should we learn
alpha_temperature
?initial_alpha_temperature (float) – Initial value for
alpha_temperature
.learn_means (bool) – Should we make the mean vectors for each mode trainable?
learn_covariances (bool) – Should we make the covariance matrix for each mode trainable?
initial_means (np.ndarray) – Initialisation for mean vectors.
initial_covariances (np.ndarray) – Initialisation for state covariances. If
diagonal_covariances=True
and full matrices are passed, the diagonal is extracted.covariances_epsilon (float) – Error added to mode covariances for numerical stability.
diagonal_covariances (bool) – Should we learn diagonal mode covariances?
means_regularizer (tf.keras.regularizers.Regularizer) – Regularizer for mean vectors.
covariances_regularizer (tf.keras.regularizers.Regularizer) – Regularizer for covariance matrices.
batch_size (int) – Mini-batch size.
learning_rate (float) – Learning rate.
lr_decay (float) – Decay for learning rate. Default is 0.1. We use
lr = learning_rate * exp(-lr_decay * epoch)
.gradient_clip (float) – Value to clip gradients by. This is the
clipnorm
argument passed to the Keras optimizer. Cannot be used ifmulti_gpu=True
.n_epochs (int) – Number of training epochs.
optimizer (str or tf.keras.optimizers.Optimizer) – Optimizer to use.
'adam'
is recommended.multi_gpu (bool) – Should be use multiple GPUs for training?
strategy (str) – Strategy for distributed learning.
- class osl_dynamics.models.simplified_dynemo.Model(config)[source]#
Bases:
osl_dynamics.models.dynemo.Model
Simplified DyNeMo model class.
- Parameters:
config (osl_dynamics.models.simplified_dynemo.Config) –
- abstract sample_alpha()[source]#
Uses the model RNN to sample mode mixing factors,
alpha
.- Parameters:
n_samples (int) – Number of samples to take.
theta_norm (np.ndarray, optional) – Normalized logits to initialise the sampling with. Shape must be (sequence_length, n_modes).
- Returns:
alpha – Sampled alpha.
- Return type:
np.ndarray
- abstract fine_tuning()[source]#
Fine tuning the model for each session.
Here, we train the inference RNN and observation model with the model RNN fixed held fixed at the group-level.
- Parameters:
training_data (osl_dynamics.data.Data) – Training dataset.
n_epochs (int, optional) – Number of epochs to train for. Defaults to the value in the
config
used to create the model.learning_rate (float, optional) – Learning rate. Defaults to the value in the
config
used to create the model.store_dir (str, optional) – Directory to temporarily store the model in.
- Returns:
alpha (list of np.ndarray) – Session-specific mixing coefficients. Each element has shape (n_samples, n_modes).
means (np.ndarray) – Session-specific means. Shape is (n_sessions, n_modes, n_channels).
covariances (np.ndarray) – Session-specific covariances. Shape is (n_sessions, n_modes, n_channels, n_channels).
- abstract dual_estimation()[source]#
Dual estimation to get the session-specific observation model parameters.
Here, we train the observation model parameters (mode means and covariances) with the inference RNN and model RNN held fixed at the group-level.
- Parameters:
training_data (osl_dynamics.data.Data or list of tf.data.Dataset) – Training dataset.
n_epochs (int, optional) – Number of epochs to train for. Defaults to the value in the
config
used to create the model.learning_rate (float, optional) – Learning rate. Defaults to the value in the
config
used to create the model.store_dir (str, optional) – Directory to temporarily store the model in.
- Returns:
means (np.ndarray) – Session-specific means. Shape is (n_sessions, n_modes, n_channels).
covariances (np.ndarray) – Session-specific covariances. Shape is (n_sessions, n_modes, n_channels, n_channels).