The Week That Cannot Have Happened
Take the most likely state on each day and write them down in order, and you have a report the model assigns probability exactly zero: on a four-day machine-monitoring example the day-by-day answer is healthy, healthy, failed, failed, and healthy to failed is a transition that cannot occur. What the two questions actually are, why smoothing and Viterbi answer different ones, and what the 0.411 posterior on the best path means for anyone who has to act on it.
Prerequisites: Reasoning About a Changing World
A machine is in one of three conditions: healthy, degrading, or failed. It cannot jump straight from healthy to failed; something has to degrade first, even if only for a day. Written as a transition model, with the failed state absorbing:
A vibration sensor raises an alarm with probability 0.1 when the machine is healthy, 0.2 when it is degrading, and 0.9 once it has failed. The machine starts healthy. Over four days the sensor reports
A. The day-by-day answer
The obvious thing to compute is, for each day, the probability of each condition given all four observations. That is smoothing, and it is what a monitoring dashboard shows you. Summing over every path:
| Day | healthy | degrading | failed | most likely |
|---|---|---|---|---|
| 1 | 1.000000 | 0.000000 | 0.000000 | healthy |
| 2 | 0.505642 | 0.494358 | 0.000000 | healthy |
| 3 | 0.362691 | 0.225978 | 0.411331 | failed |
| 4 | 0.333799 | 0.102335 | 0.563866 | failed |
Read the last column down: healthy, healthy, failed, failed.
That report is impossible. It has the machine healthy on day 2 and failed on day 3, and the transition model gives that step probability zero. The sequence is not merely unlikely, or a rough summary of something nearby. Its probability is exactly
Nothing went wrong in the arithmetic. Every one of those four numbers is correct. Each one answers a question about a single day, and stacking four answers to four separate questions does not produce an answer to a question about the week.
B. The question Viterbi answers
The other question is: which whole sequence is most probable? That is a single maximisation over the paths, and the Viterbi algorithm performs it in time linear in the number of days. The answer here is
with posterior probability 0.411331. It is a different sequence from the day-by-day one, and in particular it says the machine spent day 2 degrading - the very day whose own marginal put degrading second, at 0.494358 against 0.505642 for healthy.
That margin is the whole lesson in one number. Day 2 is almost a coin flip. The day-by-day rule takes the side that wins by 1.1 points and never asks what the choice commits it to. Viterbi asks only about sequences, so it can accept a slightly worse day 2 in exchange for a day 3 that is reachable at all.
The figure shows the same disagreement in the umbrella world, where every transition is allowed, so there the stacked marginals are merely not the most probable path rather than an impossible one.
Interactive: what you knew then, and what you know now
Click a day to toggle the umbrella.
- Days where they disagree
- 2
- Its probability
- 40.2%
On day 2 the smoothed marginal and the most likely history disagree. The marginal for that day is 0.554, so taken on its own the day was probably rainy - yet every individually-rainy history is beaten by one in which it was dry. Both numbers are right: the marginal sums over histories that individually lose, while the sequence has to commit to one of them. This is why a chain of per-step winners is not a plausible history, and why Viterbi is a different algorithm rather than a convenience.
C. The runner-up is a different story entirely
The second most likely week is not a small variation on the first:
| Sequence | posterior |
|---|---|
| healthy, degrading, failed, failed | 0.411331 |
| healthy, healthy, healthy, healthy | 0.326541 |
| healthy, healthy, degrading, failed | 0.097691 |
| healthy, degrading, degrading, failed | 0.054844 |
The best explanation is that the machine failed on day 3. The second best, at 0.326541, is that nothing happened at all and a healthy machine raised two false alarms in a row, which it does with probability on any given pair of days. Those two stories cannot both be nearly right. They are rival accounts, and the gap between them is the evidence a maintenance decision actually rests on.
This also puts the headline number in its place. The most likely sequence carries 0.411331 of the posterior, so the single best explanation of the week is wrong about 59% of the time. Viterbi returns the mode of a distribution over sequences, not a reconstruction of what happened, and reporting it without the mass behind it hides how thin the win was.
D. Which one you want
The two questions are genuinely different, and each is right for different work.
- Smoothing, day by day, is what you want when the decision is per day: was this transaction fraudulent, was the patient in atrial fibrillation during this minute, should this day's output be quarantined. Each answer is used on its own and never assembled into a narrative.
- The most likely sequence is what you want when the output is read as a story: a transcript, a gene annotation, a fault report, a part-of-speech tagging. Anything a human or a downstream program will read as a sequence must be internally consistent, and only the joint maximisation guarantees that.
The failure mode to watch for is a system that computes the first and presents it as the second. It is common, because the marginals are what a filter already produces and stacking them costs nothing. The stacked report will usually look plausible. When the transition model has a structural zero in it, as almost every real one does, it will occasionally be not just wrong but impossible, and nothing in the pipeline will notice.
E. The cheap check
If you are stacking marginals, you can detect the problem without changing your method. Take the reported sequence and evaluate its probability under the transition model: multiply the transition probabilities along it. If that product is zero, the report describes something the model says cannot happen.
It costs one pass over the output, and on this example it returns zero on day 2 to day 3. Reporting the four daily numbers as four numbers is honest. Reading them down the column is where the impossible week comes from.
References & further reading
- Stuart Russell, Peter Norvig, Artificial Intelligence: A Modern Approach, Pearson (3rd edition), 2010· Kudos AI reference library
Copyrighted works are cited for reference only and are not hosted here; please consult the publisher for access.