python-3.xhmmlearn

Is there a function that computes the probability of a sequence T of observations given a hidden Markov model on hmmlearn?


I have a GaussianHMM that I have fitted using hmmlearn.fit function. I also have a bunch of sequences of observations and I want to compute the probability of each sequence happening given my fitted model. I looked into hmmlearn's documentation and I couldn't quite find a method that does what I want. In this case, do I just have to code the forward-backward algorithm? In case I code the forward-backward, I would also need the emission matrix, which is not given by hmmlearn.

Anyone has an advice regarding this? thank you!


Solution

  • I also have a bunch of sequences of observations and I want to compute the probability of each sequence happening given my fitted model

    1. What you might be looking for is the score function, to evaluate the probability of sequence (ie. model.score(X)). Note that this is the log probability, as hmmlearn adjusts for underflow error.

    In case I code the forward-backward, I would also need the emission matrix, which is not given by hmmlearn.

    1. While the GaussianHMM does not have an emission matrix, you can choose to discretize your emissions and utilize MultinomialHMM, which allows you to specify and also later extract the emission matrix model.emissionprob_.