osl_dynamics.simulation.hsmm#

Classes for simulating Hidden Semi-Markov Models (HSMMs).

Module Contents#

Classes#

HSMM

HSMM base class.

HSMM_MVN

Hidden Semi-Markov Model Simulation.

MixedHSMM_MVN

Hidden Semi-Markov Model Simulation with a mixture of states at each

class osl_dynamics.simulation.hsmm.HSMM(gamma_shape, gamma_scale, off_diagonal_trans_prob=None, full_trans_prob=None, state_vectors=None, n_states=None)[source]#

HSMM base class.

Contains the probability distribution function for sampling state lifetimes. Uses a Gamma distribution for the probability distribution function.

Parameters:
  • gamma_shape (float) – Shape parameter for the Gamma distribution of state lifetimes.

  • gamma_scale (float) – Scale parameter for the Gamma distribution of state lifetimes.

  • off_diagonal_trans_prob (np.ndarray, optional) – Transition probabilities for out of state transitions.

  • full_trans_prob (np.ndarray, optional) – A transition probability matrix, the diagonal of which will be ignored.

  • n_states (int, optional) – Number of states.

  • state_vectors (np.ndarray, optional) – Mode vectors define the activation of each components for a state. E.g. state_vectors=[[1,0,0],[0,1,0],[0,0,1]] are mutually exclusive states. state_vector.shape[0] must be more than n_states.

construct_off_diagonal_trans_prob()[source]#
generate_states(n_samples)[source]#
class osl_dynamics.simulation.hsmm.HSMM_MVN(n_samples, gamma_shape, gamma_scale, off_diagonal_trans_prob=None, full_trans_prob=None, means=None, covariances=None, n_states=None, n_modes=None, n_channels=None, observation_error=0.0)[source]#

Bases: osl_dynamics.simulation.base.Simulation

Hidden Semi-Markov Model Simulation.

We sample the state using a transition probability matrix with zero probability for self-transitions. The lifetime of each state is sampled from a Gamma distribution.

Parameters:
  • n_samples (int) – Number of samples to draw from the model.

  • gamma_shape (float) – Shape parameter for the Gamma distribution of state lifetimes.

  • gamma_scale (float) – Scale parameter for the Gamma distribution of state lifetimes.

  • off_diagonal_trans_prob (np.ndarray, optional) – Transition probabilities for out of state transitions.

  • full_trans_prob (np.ndarray, optional) – A transition probability matrix, the diagonal of which will be ignored.

  • means (np.ndarray or str, optional) – Mean vector for each state, shape should be (n_states, n_channels). Or 'zero' or 'random'.

  • covariances (numpy.ndarray or str, optional) – Covariance matrix for each state, shape should be (n_states, n_channels, n_channels). Or 'random'.

  • n_states (int, optional) – Number of states. Can pass this argument with keyword n_modes instead.

  • n_channels (int, optional) – Number of channels in the observation model.

  • observation_error (float, optional) – Standard deviation of random noise to be added to the observations.

property n_modes[source]#
property mode_time_course[source]#
__getattr__(attr)[source]#
standardize()[source]#
class osl_dynamics.simulation.hsmm.MixedHSMM_MVN(n_samples, gamma_shape, gamma_scale, mixed_state_vectors=None, mixed_mode_vectors=None, off_diagonal_trans_prob=None, full_trans_prob=None, means=None, covariances=None, n_channels=None, observation_error=0.0)[source]#

Bases: osl_dynamics.simulation.base.Simulation

Hidden Semi-Markov Model Simulation with a mixture of states at each time point.

Each mixture of states has it’s own row/column in the transition probability matrix. The lifetime of each state mixture is sampled from a Gamma distribution.

state_mixing_vectors is a 2D numpy array containing mixtures of the the states that can be simulated, e.g. with n_states=3 we could have state_mixing_vectors=[[0.5, 0.5, 0], [0.1, 0, 0.9]].

Parameters:
  • n_samples (int) – Number of samples to draw from the model.

  • gamma_shape (float) – Shape parameter for the Gamma distribution of state lifetimes.

  • gamma_scale (float) – Scale parameter for the Gamma distribution of state lifetimes.

  • mixed_state_vectors (np.ndarray, optional) – Vectors containing mixing factors for mixed states.

  • mixed_mode_vectors (np.ndarray, optional) – Vectors containing mixing factors for mixed states.

  • off_diagonal_trans_prob (np.ndarray, optional) – Transition probabilities for out of state transitions.

  • full_trans_prob (np.ndarray, optional) – A transition probability matrix, the diagonal of which will be ignored.

  • means (np.ndarray or str, optional) – Mean vector for each state, shape should be (n_states, n_channels). Or 'zero' or 'random'.

  • covariances (numpy.ndarray or str, optional) – Covariance matrix for each state, shape should be (n_states, n_channels, n_channels). Or 'random'.

  • n_channels (int, optional) – Number of channels in the observation model.

  • observation_error (float, optional) – Standard deviation of random noise to be added to the observations.

property n_modes[source]#
property mode_time_course[source]#
__getattr__(attr)[source]#
construct_state_vectors(n_states)[source]#
standardize()[source]#