Topic 5.1
Forward
The same trellis as Viterbi with a different question: how probable is the sequence at all, adding up every path that could have produced it?
Where people get stuck
- Sum, not max.Viterbi keeps the better incoming route. Forward adds both. Nothing is thrown away, and no pointers are saved.
- α is a total over many paths.αs(t) is the probability of the first t bases together with being in state s at position t, summed over every path that ends there.
- P(x) is not the probability of one path.P(x) = Σπ P(x, π | θ). It is at least as large as the best single path, and often that best path carries only a modest share.
- Why it matters.To score how well a model explains a sequence, you compare log₂ P(x|θ) with the background. That uses the total over alignments, not one chosen alignment.
The recurrence
Compare it line by line with Viterbi. The only change is that max becomes a sum.
| Viterbi | Forward | |
|---|---|---|
| Combine incoming routes | max | sum |
| Saves pointers | yes | no |
| Answer | best path and its probability | P(x), total over all paths |
Watch it run
Line thickness shows how much of each node's total comes from each incoming route. At the end, a brute-force list of every path shows that forward reached the same total without enumerating them.
Check yourself
Why can P(x) never be smaller than the Viterbi probability?
P(x) is a sum of nonnegative terms, one per path, and the Viterbi probability is the largest single term in that sum. A sum can never be smaller than its largest term.
Can you take logs of every forward value like in Viterbi?
Not directly. Forward needs sums of probabilities, and the log of a sum is not a sum of logs. Real implementations use a log-sum-exp trick or rescale each column.
What is the practical difference between the two answers for a real sequence?
Viterbi gives one concrete labeling you can display, such as a gene prediction. Forward gives a single score for how well the whole model explains the sequence. In lecture, forward and backward together also give a confidence for each base's state.