Untangled

Topic 5.1

Backward and forward-backward

Forward looks at the past. Backward looks at the future. Multiply them at a position and you get how sure the model is about the hidden state there.

Why bother with a second pass?

Viterbi gives one best path. Forward gives one number, P(x). Neither tells you how confident the model is about the state at position t. That is what forward-backward adds, and it is the engine inside HMMER's alignment confidences and ChromHMM.

To split all the paths through a node, you need two halves: everything that happens up to and including position t, and everything that happens after it.

αs(t) = P(x1..t, state at t = s) the past, from forward
βs(t) = P(xt+1..n | state at t = s) the future, from backward

Where people get stuck

  • Backward runs right to left, and starts at 1.βs(n) = 1 for both states. Nothing remains after the last base, and END is forced.
  • The emission is of the next base.In βs(t) you multiply by P(xt+1|q), not by the emission at position t. Position t's base was already accounted for in α.
  • α·β counts position t's base exactly once.α includes the emission at t, β starts after it. So αs(t)·βs(t) is the probability of x and state s at t, and summing over s gives P(x) at every t.
  • γ is a probability, not a score.γs(t) = αs(t)·βs(t) / P(x). For the two states it adds to 1 at each position.
  • Posterior decoding is not Viterbi.It picks the best state at each position separately. The result can differ from the best whole path.

The recurrences

Same transitions and emissions as before. Compare with forward: the direction flips, and the emission being used belongs to the next position.

βs(n) = 1
βs(t) = Σq P(q|s) · P(xt+1|q) · βq(t+1)
P(x) = Σs P(s|START) · P(x1|s) · βs(1)
γs(t) = αs(t) · βs(t) / P(x)
ForwardBackward
Directionleft to rightright to left
Starts atSTART: P(s|START)·P(x1|s)END: β = 1
Emission used at a nodeits own base, xtthe next base, xt+1
GivesP(x) from the right endP(x) from the left end (same number)

Watch it run

Step the backward pass right to left. Click a node to see its arithmetic. After the last column, Combine with α shows the posterior at each position next to the Viterbi path.

Check yourself

Why is αs(t)·βs(t) summed over s always equal to P(x)?

Every path passes through exactly one state at position t. The product α·β is the total probability of all paths that pass through state s there, so summing over the two states covers every path exactly once.

Do I need backward to get P(x)?

No. Forward alone gives it as the sum of the last column. Backward gives the same number from the left end. You need backward when you want per-position posteriors, or when you re-estimate the model.

How can posterior decoding differ from Viterbi?

Viterbi maximizes the probability of one whole path. Posterior decoding maximizes the probability of each position separately, so it can combine locally likely states into a path that is unlikely as a whole, even one with a transition the model rarely allows.

Where does this appear in the course?

Lecture 5.1 uses forward and backward to get a confidence for each base's state in a profile HMM, then picks one alignment that maximizes the expected number of correct bases. Lecture 4.2 mentions the same posterior-weight idea for MEME: the z values play the role of γ.