How is the forward recursion for a hidden Markov model derived? For the HMM with states Rainy (R) and Sunny (S), π=(0.6,0.4), transitions P(R→R)=0.7, P(R→S)=0.3, P(S→R)=0.4, P(S→S)=0.6, and emissions P(walk∣R)=0.1, P(shop∣R)=0.4, P(walk∣S)=0.6, P(shop∣S)=0.3, what is P(walk,shop)?

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 zt for the hidden state, ot for the observation, aij=P(zt+1=j∣zt=i) and bj(o)=P(o∣zt=j). Define αt(j)=P(o1,…,ot, zt=j), the probability of the observations so far with the chain ending in state j. Then α1(j)=πjbj(o1), αt+1(j)=bj(ot+1)∑iαt(i) aij, and P(o1:T)=∑jαT(j). This costs O(TK2) instead of O(KT) for summing over every path.

Steps

  1. Write the HMM joint: p(z1:T,o1:T)=πz1bz1(o1)∏t=2Tazt−1zt bzt(ot).
  2. Derive the recursion: αt+1(j)=∑iP(o1:t,zt=i) P(zt+1=j∣zt=i) P(ot+1∣zt+1=j), using that zt+1 depends only on zt, and ot+1 only on zt+1.
  3. Initialise: α1(R)=0.6×0.1=0.06, α1(S)=0.4×0.6=0.24.
  4. Recurse: α2(R)=(0.06×0.7+0.24×0.4)×0.4=0.138×0.4=0.0552; α2(S)=(0.06×0.3+0.24×0.6)×0.3=0.162×0.3=0.0486.
  5. Terminate: P(walk,shop)=0.0552+0.0486=0.1038. Check by brute force over the four paths RR, RS, SR, SS: 0.0168+0.0054+0.0384+0.0432=0.1038.

Common mistakes

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

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 K components?