How is the forward recursion for a hidden Markov model derived? For the HMM with states Rainy (R) and Sunny (S), , transitions , , , , and emissions , , , , what is ?
Probabilistic models, Hidden Markov models
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.
What's being asked
Whether you can derive dynamic programming over hidden states from the HMM factorisation and run it by hand.
Key idea
Write for the hidden state, for the observation, and . Define , the probability of the observations so far with the chain ending in state . Then , , and . This costs instead of for summing over every path.
Steps
- Write the HMM joint: .
- Derive the recursion: , using that depends only on , and only on .
- Initialise: , .
- Recurse: ; .
- Terminate: . Check by brute force over the four paths RR, RS, SR, SS: .
Common mistakes
- Multiplying by the emission of the previous observation instead of .
- Taking a max instead of a sum; that is Viterbi, which answers a different question.
- Ignoring underflow: for long sequences, normalise at each step (keeping the scale factors) or work in log space.
How long your answer should be
Half a page: the recursion, then a small table of values; about 5 minutes.
Last checked on 4 December 2026.
Read this
- Jurafsky and Martin, Speech and Language Processing (3rd ed. draft), Appendix A: Hidden Markov Models: Free PDF. Section A.3, Likelihood Computation: The Forward Algorithm: the α recursion and trellis, with brute-force path enumeration shown first for comparison.
- Bishop, Pattern Recognition and Machine Learning, Section 13.2.2: Free PDF. Section 13.2.2, The Forward-Backward Algorithm (pp. 618–625): derivation of the α recursion from the HMM factorisation and conditional independences, and the scaling fix for underflow in 13.2.4.
- NPTEL: Introduction to Machine Learning (IIT Madras, Prof. Balaraman Ravindran): Week 9: Hidden Markov Models, which covers the HMM model and the forward recursion.
Previous in Probabilistic models: How do you derive the evidence lower bound (ELBO), and what is the gap?
Next in Probabilistic models: How do you derive the E-step and M-step of the EM algorithm for a Gaussian mixture model with components?