Mogeng / IOHMM

Input Output Hidden Markov Model (IOHMM) in Python
BSD 3-Clause "New" or "Revised" License
159 stars 35 forks source link

Regarding Transition Probabilities #37

Open Singh-Sonam opened 2 years ago

Singh-Sonam commented 2 years ago

Hello

I am using a few covariates for transition, but when I am using the sample code provided to view transition probabilities, it is throwing an error. For Example : covariates_transition = ['a','b','c','d','e', 'f','g','h','i']

When using print(np.exp(SHMM.model_transition[0].predict_log_proba(np.array([[]])))), I am getting an error : X has 1 features per sample; expecting 10. How can I get the transition probabilities for the two hidden state model with transition covariates.

Also, how can I get the most likely state for each observation? In hmmlearn , remodel = hmm.GaussianHMM(n_components=2).fit(X, lengths) Z3 = remodel.predict(X) provides the hidden states, how can i get that in this model.

Thank you for all the help.

ghcsung commented 1 year ago

You probably have a covariate (input) associated with the transition probabilities. For the first question I did:

# the number of zeros inside np.array() should be equal to the number of your covariates, I have two inputs.

empty = np.array([[1, 0, 0]]) # 1 for constant

SHMM0.model_transition[0].fit_intercept = False
SHMM0.model_transition[1].fit_intercept = False

print(np.exp(SHMM0.model_transition[0].predict_log_proba(empty)))
print(np.exp(SHMM0.model_transition[1].predict_log_proba(empty)))

This gets the transition probabilities for when your covariates are all 0 (except the constant).