Hidden Markov Models

GATE Relevance: High

🎯 Learning Objectives

  • Define HMM components: states, observations, transitions, emissions
  • State the three fundamental HMM problems
  • Apply the Forward algorithm for evaluation
  • Apply the Viterbi algorithm for decoding
  • Understand Baum-Welch (EM) for learning at a high level

1. HMM Definition

Hidden Markov Model

An HMM is defined by λ = (A, B, π):

  • States: S = {s1, s2, …, sN} (hidden)
  • Observations: O = {o1, o2, …, oM} (visible)
  • Transition matrix A: aij = P(qt+1 = sj | qt = si)
  • Emission matrix B: bj(k) = P(ot = vk | qt = sj)
  • Initial distribution π: πi = P(q1 = si)

Key Assumptions

  • Markov property: P(qt+1 | q1, …, qt) = P(qt+1 | qt)
  • Output independence: P(ot | q1, …, qt, o1, …, ot) = P(ot | qt)

2. Three Fundamental HMM Problems

ProblemTaskAlgorithm
EvaluationP(O | λ) — likelihood of observationsForward algorithm
DecodingBest state sequence given OViterbi algorithm
LearningEstimate λ from observationsBaum-Welch (EM)

3. Forward Algorithm

Forward Algorithm — O(T · N2)

Define forward variable: αt(i) = P(o1, o2, …, ot, qt = si | λ)

  1. Initialization: α1(i) = πi · bi(o1)
  2. Recursion: αt+1(j) = [∑i=1N αt(i) · aij] · bj(ot+1)
  3. Termination: P(O | λ) = ∑i=1N αT(i)

Example GATE Style

States: {Sunny, Rainy}. Observations: {Walk, Shop, Clean}.
π = [0.6, 0.4], A = [[0.7, 0.3], [0.4, 0.6]]
B = [[0.1, 0.4, 0.5], [0.6, 0.3, 0.1]]
Observation sequence: Walk, Shop. Compute P(O).

α1(S) = 0.6 × 0.1 = 0.06, α1(R) = 0.4 × 0.6 = 0.24

α2(S) = (0.06 × 0.7 + 0.24 × 0.4) × 0.4 = (0.042 + 0.096) × 0.4 = 0.0552

α2(R) = (0.06 × 0.3 + 0.24 × 0.6) × 0.3 = (0.018 + 0.144) × 0.3 = 0.0486

P(O) = 0.0552 + 0.0486 = 0.1038

4. Viterbi Algorithm

Viterbi Algorithm — O(T · N2)

Like Forward, but replaces sum with max. Finds the most likely state sequence.

Define: δt(i) = maxq1,...,qt-1 P(q1, …, qt = si, o1, …, ot)

  1. Initialization: δ1(i) = πi · bi(o1)
  2. Recursion: δt+1(j) = maxi[δt(i) · aij] · bj(ot+1). Store ψt+1(j) = argmaxi[δt(i) · aij].
  3. Termination: Best final state q*T = argmaxi δT(i). Backtrack using ψ.

5. Baum-Welch (EM) — Overview

The Baum-Welch algorithm is an Expectation-Maximization procedure that iteratively refines the HMM parameters (π, A, B) to maximize the likelihood of the observed data. It alternates between:

  • E-step: Compute expected sufficient statistics using forward-backward algorithm
  • M-step: Re-estimate parameters using the expected counts

Convergence is guaranteed to a local maximum of the likelihood.

Summary

  • HMM = hidden states + observed emissions + transition/emission probabilities
  • Forward: computes P(observations) in O(TN2)
  • Viterbi: finds best state sequence — same complexity, replace ∑ with max
  • Baum-Welch: EM algorithm for parameter learning
  • HMMs model sequential data: speech, POS tagging, gene finding