API for ARTHMM

class autohmm.ar.ARTHMM(n_unique=2, n_lags=1, n_tied=0, startprob_init=None, transmat_init=None, startprob_prior=1.0, transmat_prior=1.0, algorithm='viterbi', random_state=None, n_iter=25, n_iter_min=2, tol=0.0001, params='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', init_params='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', alpha_init=None, mu_init=None, precision_init=None, precision_prior=None, precision_weight=0.0, mu_prior=None, mu_weight=0.0, shared_alpha=True, n_iter_update=1, verbose=False, mu_bounds=array([-50., 50.]), precision_bounds=array([ 1.00000000e-03, 1.00000000e+04]), alpha_bounds=array([-10., 10.]))

Hidden Markov Model with tied states and autoregressive observations

Parameters:
  • n_unique (int) – Number of unique components.
  • n_tied (int) – Number of tied states for each component.
  • algorithm (string) – Decoding algorithm.
  • params (string) – Controls which parameters are updated in the training process. Defaults to all parameters.
  • init_params (string) – Controls which parameters are initialized prior to training. Defaults to all parameters.
  • startprob_init (array, shape (n_unique)) – Initial state occupation distribution.
  • startprob_prior (array, shape (n_unique)) – Pseudo-observations (counts).
  • transmat_init (array, shape (n_unique, n_unique)) – Matrix of transition probabilities between states.
  • transmat_prior (array, shape (n_unique, n_unique)) – Pseudo-observations (counts).
  • mu_init (array, shape (n_unique)) – Initial mean parameters for each state.
  • mu_weight (int) – Weight of mu prior, shared across components.
  • mu_prior (array, shape (n_unique)) – Prior on mu.
  • precision_init (array, shape (n_unique)) – Initial precision (inverse variance) parameters for each state.
  • precision_weight (int) – Weight of precision (inverse variance) prior.
  • precision_prior (array, shape (n_unique)) – Prior on precision (inverse variance).
  • tol (float) – Convergence threshold, below which EM will stop.
  • n_iter (int) – Number of iterations to perform maximally.
  • n_iter_min (int) – Number of iterations to perform minimally.
  • n_iter_update (int) – Number of iterations per M-Step.
  • random_state (int) – Sets seed.
  • verbose (bool) – When True convergence reports are printed.
  • n_lags (int) – Number of lags (order of AR).
  • shared_alpha (bool) – If set to true, alpha is shared across states.
  • alpha_init (array, shape (n_components, n_lags)) – Initial alpha parameter per state.
  • mu_bounds (array, shape (2)) – Upper and lower bound for mu [lower bound, upper bound].
  • precision_bounds (array, shape (2)) – Upper and lower bound for precision [lower bound, upper bound].
  • alpha_bounds (array, shape(2)) – Upper and lower bound for alpha [lower bound, upper bound].
n_components

int – Number of total components

mu_

array, shape (n_unique, n_features)

precision_

array, shape (n_unique, n_features)

transmat_

array, shape (n_unique, n_unique)

startprob_

array, shape (n_unique, n_unique)

n_lags

int

n_inputs

int

alpha_

array, shape (n_components, n_lags)

decode(X, algorithm='viterbi')

Find most likely state sequence corresponding to obs. Uses the selected algorithm for decoding.

Parameters:
  • X (array_like, shape (n)) – Each row corresponds to a single point in the sequence.
  • algorithm (string, one of the decoder_algorithms) – decoder algorithm to be used. NOTE: Only Viterbi supported for now.
Returns:

  • logprob (float) – Log probability of the maximum likelihood path through the HMM
  • state_sequence (array_like, shape (n,)) – Index of the most likely states for each observation (accounting for tied states by giving them the same index)

fit(X, lengths=None)

Estimate model parameters.

An initialization step is performed before entering the EM-algorithm. If you want to avoid this step for a subset of the parameters, pass proper init_params keyword argument to estimator’s constructor.

Parameters:
  • X (array-like, shape (n_samples, 1)) – Feature matrix of individual samples.
  • lengths (array-like of integers, shape (n_sequences, )) – Lengths of the individual sequences in X. The sum of these should be n_samples.
Returns:

self – Returns model.

Return type:

object

sample(n_samples=2000, observed_states=None, init_samples=None, init_state=None, random_state=None)

Generate random samples from the self.

Parameters:
  • n (int) – Number of samples to generate.
  • observed_states (array) – If provided, states are not sampled.
  • random_state (RandomState or an int seed) – A random number generator instance. If None is given, the object’s random_state is used
  • init_state (int) – If provided, initial state is not sampled.
  • init_samples (array, default: None) – If provided, initial samples (for AR) are not sampled.
  • E (array-like, shape (n_samples, n_inputs)) – Feature matrix of individual inputs.
Returns:

  • samples (array_like, length (n_samples)) – List of samples
  • states (array_like, shape (n_samples)) – List of hidden states (accounting for tied states by giving them the same index)

score_samples(X)

Compute the log probability under the model and compute posteriors.

Parameters:X (array_like, shape (n)) – Each row corresponds to a single point in the sequence.
Returns:
  • logprob (float) – Log likelihood of the sequence X
  • posteriors (array_like, shape (n, n_components)) – Posterior probabilities of each state for each observation