An HMM has hidden states Rainy (R) and Sunny (S), initial probabilities , transitions , , , , and emissions , , , . Using the Viterbi algorithm, what is the most likely hidden sequence for the observations (walk, shop)?
Probabilistic models, Hidden Markov models
Level L2 Elementary. Length Medium. Nature Mat Mathematical.
What's being asked
Whether you can run max-product dynamic programming with back-pointers, and know how it differs from the forward algorithm.
Key idea
Write for the hidden state and for the observation at time , for transitions and for emissions. , the probability of the best path that ends in state at time , satisfies , with back-pointer . It is the forward algorithm with the sum replaced by a max.
Steps
- Initialise: , .
- , back-pointer S.
- , back-pointer S.
- Terminate: at ; follow the back-pointer to . The most likely sequence is (Sunny, Sunny), with joint probability .
- Contrast: the forward algorithm sums over paths to get ; Viterbi maximises to get the single best path. The best path need not equal the sequence of individually most likely states from forward–backward.
Common mistakes
- Picking the best state at each time greedily instead of back-tracking from the end.
- Summing instead of maximising, which gives forward probabilities.
- Reporting as the posterior probability of the path. To get , divide by , giving about .
How long your answer should be
A two-column table of values with back-pointers, then one line for the path; 3 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.4, Decoding: The Viterbi Algorithm: the δ recursion with back-pointers, worked on a small two-state (hot/cold) HMM much like this one.
- Bishop, Pattern Recognition and Machine Learning, Section 13.2.5: Free PDF. Section 13.2.5, The Viterbi Algorithm (pp. 629–631): max-sum as the forward recursion with max in place of sum, and why the best path differs from the per-step most likely states.
- NPTEL: Natural Language Processing (IIT Kharagpur, Prof. Pawan Goyal): Week 4: Viterbi Decoding for HMM, Parameter Learning, which walks through the Viterbi recursion on an HMM.
Previous in Probabilistic models: How is naive Bayes drawn as a graphical model, and what is its independence assumption? A spam filter has . The word "offer" appears in 60% of spam and 10% of ham (non-spam) emails; the word "meeting" appears in 30% of spam and 50% of ham. Using only these two words, what is for an email that contains both?
Next in Probabilistic models: What is the conditional distribution of a partitioned multivariate Gaussian? If is jointly Gaussian with means , , variances , and covariance , what is ?