API for THMM¶
-
class
autohmm.tm.
THMM
(n_unique=2, n_tied=0, algorithm='viterbi', params='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', init_params='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', startprob_init=None, startprob_prior=1.0, transmat_init=None, transmat_prior=1.0, mu_init=None, mu_weight=0.0, mu_prior=None, precision_init=None, precision_weight=0.0, precision_prior=None, tol=0.0001, n_iter=25, n_iter_min=2, n_iter_update=1, random_state=None, verbose=False, mu_bounds=array([-50., 50.]), precision_bounds=array([ 1.00000000e-03, 1.00000000e+04]))¶ Hidden Markov Model with tied states
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. - 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].
-
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
)
-
decode
(X, algorithm='viterbi')¶ Find most likely state sequence corresponding to
X
. 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.
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 ben_samples
.
Returns: self – Returns self.
Return type: object
-
sample
(n_samples=2000, observed_states=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
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
- logprob (float) – Log likelihood of the sequence