Skip to content
Part IA Lent Term

Hidden Markov Models: Definition

Motivation

Two-state weather HMM with transitions between Freezing and Not Freezing states, showing emission probabilities for each state

Naive Bayes treats every observation independently: word order does not matter. But many real-world problems involve sequences where items depend on their neighbours: speech, weather patterns, financial time series, biological sequences (DNA, proteins). Hidden Markov Models explicitly model these temporal dependencies through a two-level structure: hidden states that evolve over time and visible observations emitted by those states.

Formal Definition: μ=(S,V,A,B,π)\mu = (S, V, A, B, \pi)

An HMM models a system where we observe outputs (emissions) but cannot directly observe the underlying process (hidden states). The model is fully specified by five components:

SymbolNameDescription
SSHidden StatesThe unobservable states: $S = {s_1, s_2, \ldots, s_{
VVObservationsThe observable emissions: $V = {v_1, v_2, \ldots, v_{
AATransition Matrixaij=P(qt=sjqt1=si)a_{ij} = P(q_t = s_j \mid q_{t-1} = s_i) — row ii, column jj
BBEmission Matrixbi(vk)=P(ot=vkqt=si)b_i(v_k) = P(o_t = v_k \mid q_t = s_i) — row ii, column kk
π\piInitial Distributionπj=P(q1=sj)\pi_j = P(q_1 = s_j) — probability of starting in state jj

Each row of AA sums to 1. Each row of BB sums to 1. jπj=1\sum_j \pi_j = 1.

Concrete Example: Weather HMM

This is the 2024 Q8 HMM. Hidden states: S={Freezing(F),NotFreezing(NF)}S = \{\text{Freezing}(F), \text{NotFreezing}(NF)\} (air temperature, unobservable without a thermometer). Observations: V={Snow(S),Rain(R),Dry(D)}V = \{\text{Snow}(S), \text{Rain}(R), \text{Dry}(D)\} (visible weather).

Transition matrix AA — models how temperature changes month to month:

qt1q_{t-1} / qtq_tFFNFNF
FFP(FF)P(F \mid F)P(NFF)P(NF \mid F)
NFNFP(FNF)P(F \mid NF)P(NFNF)P(NF \mid NF)

Emission matrix BB — models the weather given the temperature:

qtq_t / oto_tSSRRDD
FFP(SF)P(S \mid F)P(RF)P(R \mid F)P(DF)P(D \mid F)
NFNFP(SNF)P(S \mid NF)P(RNF)P(R \mid NF)P(DNF)P(D \mid NF)

Note: Snow requires freezing temperatures (P(SNF)0P(S \mid NF) \approx 0). Rain implies above-freezing (P(RF)0P(R \mid F) \approx 0). Dry is possible in either state.

Initial distribution π\pi: π=[P(q1=F),  P(q1=NF)]\pi = [P(q_1 = F),\; P(q_1 = NF)].

What Makes HMMs Different from Naive Bayes

Naive Bayes: P(cd)P(c)iP(wic)P(c \mid d) \propto P(c) \prod_i P(w_i \mid c) — each word contributes independently. Word order does not matter. “The dog bit the man” and “The man bit the dog” are identical to NB.

HMMs model the dependence between consecutive items through the transition matrix AA. The hidden state at time tt depends on the hidden state at t1t-1. The observation at time tt depends on the state at tt. This sequential structure makes HMMs suitable for any data where context matters: part-of-speech tagging, speech recognition, activity recognition, financial regime detection.

Dual-Tape Training Data

Training requires fully labelled sequences: both the hidden state and the observation at every timestep must be known. This is called dual-tape data. Example:

Timestep1234567
State (qtq_t)LMHHHMM
Observation (oto_t)+++++++++++++

From this we count transitions and emissions to estimate AA and BB.

Summary

ComponentFormulaMeaning
SSSet of hidden states (size $
VVSet of observable symbols (size $
aija_{ij}P(qt=sjqt1=si)P(q_t = s_j \mid q_{t-1} = s_i)Transition probability
bi(vk)b_i(v_k)P(ot=vkqt=si)P(o_t = v_k \mid q_t = s_i)Emission probability
πj\pi_jP(q1=sj)P(q_1 = s_j)Initial state probability
Rows sum to 1jaij=1\sum_j a_{ij} = 1, kbi(vk)=1\sum_k b_i(v_k) = 1Valid probability distributions

Past paper questions: y2024p3q8, y2025p3q9