Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

A first hidden Markov model

We ask one question. How can a sequence of noisy observations tell us about a sequence of hidden states?

A hidden Markov model (HMM) has three parts.

  1. Hidden state. Zt∈{0,1}Z_t\in\{0,1\} is the state at position tt.

  2. Transition. P(Zt≠Zt−1)=sP(Z_t\neq Z_{t-1})=s controls how often the state changes.

  3. Emission. P(Xt≠Zt)=eP(X_t\neq Z_t)=e controls how often the observation differs from the state.

The forward--backward algorithm uses dynamic programming to sum over all 2T2^T possible hidden paths without listing them. It computes P(Zt=1∣X1,…,XT)P(Z_t=1\mid X_1,\ldots,X_T) at every position.

One fixed sequence

We use one simulated hidden path and four deliberately flipped observations. The hidden path is shown because this is a teaching example. In real data, it is unknown.

Loading...

Transition probability controls persistence

Move the slider for ss. A small value says neighboring positions probably share a state, so the posterior smooths over isolated observations. A larger value permits more frequent state changes, so the posterior follows local observations more closely.

A posterior probability is not a decoded path. It measures uncertainty at each position. Values near 1/21/2 mean that the two hidden states remain difficult to distinguish.

Emission error controls how much the observations are trusted

Now hold s=0.08s=0.08 fixed and move the slider for ee. When ee is small, an observation strongly favors the matching state. As ee approaches 1/21/2, the observations carry less information and the posterior is driven mainly by state persistence.

What to remember

  1. The transition probability describes how states persist or change along a sequence.

  2. The emission probability describes how a hidden state produces an observation.

  3. Forward--backward uses dynamic programming to sum over all possible hidden paths and return a posterior probability at each position.

The Li–Stephens model uses the same structure. The hidden state is the copied reference haplotype, a transition changes the copying source, and an emission mismatch represents imperfect copying.