pyhctsa.operations.model_fit.hmm_fit

pyhctsa.operations.model_fit.hmm_fit(y, train_p=0.8, num_states=3)

A hidden Markov model fitted to the first part of the series, and how well it describes the rest.

Fits a hidden Markov model (HMM) with Gaussian emissions to the first train_p proportion of the time series (hctsa’s MF_hmm_Fit, by Baum-Welch EM with hmmlearn). The emissions of all states share one variance (a tied covariance). The model is trained with at most 30 cycles of EM (Baum-Welch), or until convergence.

The fit is deterministic. EM is run from six fixed starting points (state means at the quantiles (k-1/2)/num_states of the training data, or evenly spaced within one standard deviation of its mean; a variance equal to that of the training data; and probabilities 0.5, 0.9 and 0.99 of staying in a state); the fit with the highest training log-likelihood (of the training data under the fit’s final parameters) is kept (see _gaussian_hmm_fit()). The shared variance cannot fall below 1% of the variance of the training data, so that states placed on a few repeated values do not give unbounded likelihoods.

Parameters:
y : array-like

The input time series.

train_p : float

The proportion of data to train on, 0 < train_p < 1. Default is 0.8.

num_states : int

The number of states in the HMM. Default is 3.

Returns:

Dictionary of statistics based on the fitted HMM: the sorted state means (Mu_1, …) and their meanMu, rangeMu, maxMu, minMu; the tied covariance Cov; the transition matrix summaries Pmeandiag, stdmeanP (standard deviation across states of the mean probability of moving into each state), maxP and stdP; the log-likelihood per sample of the training part under the fitted model, LLtrainpersample; and the test log-likelihood per sample LLtestpersample and LLdifference (test minus training).

Return type:

dict