Friday, 14 August 2015

Basic Hidden Markov model

A hidden Markov model is a statistical model which builds upon the concept of a Markov chain.

The idea behind the model is simple: imagine your system can be modeled as a Markov chain and the signals emitted by the system depend only on the current state of the system. If the states of the system are not visible and what you can observe are only the emitted signals, then this is a Hidden Markov model.

As an example, imagine you have a friend in another country whose activities depend only on the weather. According to the weather conditions he is more likely to do some activities instead of others however (assuming you have no smartphone ;)) you cannot observe the weather in his country and you only have a report with a sequence of activities.

The three top problems you might want to solve are:

1) Given the parameters, calculate the probability of a certain sequence of activities on the report.

2) Given the parameters, calculate the most likely occurring sequence.

3) Given a sequence or a set of sequences, find the parameters.

Here is a simple example (from Wikipedia) in Python of a working HMM.



  1. Hi, thanks for this post.
    I don't quite understand where you got this:

  2. ok I just went to the wikipedia page. I think you forgot the probabilities for the activities.
    While I'm here again, could you please comment on st = 1 in line 23. what is its purpose? I saw this pattern in a number of codes on viterbi and HMM without any explanation.