I just finished working on LEARNINGlover.com: Hidden Marokv Models: The Forward Algorithm. Here is an introduction to the script.

Suppose you are at a table at a casino and notice that things don’t look quite right. Either the casino is extremely lucky, or things should have averaged out more than they have. You view this as a pattern recognition problem and would like to understand the number of ‘loaded’ dice that the casino is using and how these dice are loaded. To accomplish this you set up a number of Hidden Markov Models, where the number of loaded die are the latent variables, and would like to determine which of these, if any is more likely to be using.

First lets go over a few things.

We will call each roll of the dice an observation. The observations will be stored in variables *o _{1}, o_{2}, …, o_{T}*, where

*T*is the number of total observations.

To generate a hidden Markov Model (HMM) we need to determine 5 parameters:

- The N states of the model, defined by S = {S
_{1}, …, S_{N}} - The M possible output symbols, defined by = {
_{1},_{2}, …,_{M}} - The State transition probability distribution A = {a
_{ij}}, where a_{ij}is the probability that the state at time t+1 is S_{j}, given that the state at time t is S_{i}. - The Observation symbol probability distribution B = {b
_{j}(_{k})} where b_{j}(_{k}) is the probability that the symbol_{k}is emitted in state S_{j}. - The initial state distribution = {
_{i}}, where_{i}is the probability that the model is in state S_{i}at time t = 0.The HMMs we’ve generated are based on two questions. For each question, you have provided 3 different answers which leads to 9 possible HMMs. Each of these models has its corresponding state transition and emission distributions.

- How often does the casino change dice?
- 0) Dealer Repeatedly Uses Same Dice
- 1) Dealer Uniformly Changes Die
- 2) Dealer Rarely Uses Same Dice

- Which sides on the loaded dice are more likely?
- 0) Larger Numbers Are More Likely
- 1) All Numbers Are Equally Likely
- 2) Smaller Numbers Are More Likely

How often does the casino change dice? Which sides on

the loaded dice

are more likely?(0, 0) (0, 1) (0, 2) (1, 0) (1, 1) (1, 2) (2, 0) (2, 1) (2, 2) One of the interesting problems associated with Hidden Markov Models is called the Evaluation Problem, which asks the question “What is the probability that the given sequence of observations O = o

_{1}, o_{2}, …, o_{T}are generated by the HMM . In general, this calculation, p{O | }, can be calculated by simple probability. However because of the complexity of that calculation, there are more efficient methods.The forward algorithm is one such method. It creates an auxiliary variable

_{t}(i) which is the probability that the model has generated the partially observed sequence o_{1}, …, o_{t}, where 1 t T. This variable can be calculated by the following formula:_{t+1}(j) = b_{j}(o_{t+1})_{i = 1 to N}(_{t}(i)a_{ij}), where 1 j N, 1 t T-1._{1}(j) =_{j}b_{j}(o_{1}), for 1 j N.Once we have calculated the

_{t}(j) variables, we can solve the evaluation problem by p{O | } =_{i = 1 to N}_{T}(i)There is more on this example at LEARNINGlover.com: Hidden Marokv Models: The Forward Algorithm.

Some further reading on Hidden Markov Models:

- How often does the casino change dice?

## One thought on “Hidden Markov Models: The Forward Algorithm”