hmmlearn: how to get the prediction for the hidden state probability at time T+1, given a full observation sequence 1:T

Viewed 7497

I'm using hmmlearn's GaussianHMM to train a Hidden Markov Model with Gaussian observations. Each hidden state k has its corresponding Gaussian parameters: mu_k, Sigma_k.

After training the model, I would like to calculate the following quantity:

P(z_{T+1} = j | x_{1:T}),

where j = 1, 2, ... K, K is the number of hidden states.

The above probability is basically the one-step-ahead hidden state probabilities, given a full sequence of observations: x_1, x_2, ..., x_T, where x_i, i=1,...,T are used to train the HMM model.

I read the documentation, but couldn't find a function to calculate this probability. Is there any workaround?

2 Answers

Once the an HMM model is trained, you can get the t+1 state given 1:t observations X as following:

import numpy as np
from sklearn.utils import check_random_state
sates = model.predict(X)
transmat_cdf = np.cumsum(model.transmat_, axis=1)
random_sate = check_random_state(model.random_state)
next_state = (transmat_cdf[states[-1]] > random_state.rand()).argmax()

the t+1 state is generated according to the t state and the transmat_

Related