Skip to content
Kudos AI
Lire en français
Probabilistic Reasoning

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.

5 min readKudos AI

Prerequisites: Reasoning About a Changing World

A trellis of days with every path drawn faintly, the best surviving path into each node thickening, and the winner traced back from the end past a node the day-by-day answer had picked.

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:

P(Xt+1∣Xt)=healthydegradingfailedhealthy0.950.050degrading0.100.600.30failed001P(X_{t+1} \mid X_t) = \begin{array}{l|ccc} & \text{healthy} & \text{degrading} & \text{failed} \\ \hline \text{healthy} & 0.95 & 0.05 & 0 \\ \text{degrading} & 0.10 & 0.60 & 0.30 \\ \text{failed} & 0 & 0 & 1 \end{array}

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

quiet,quiet,alarm,alarm.\text{quiet},\quad \text{quiet},\quad \text{alarm},\quad \text{alarm}.

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:

Dayhealthydegradingfailedmost likely
11.0000000.0000000.000000healthy
20.5056420.4943580.000000healthy
30.3626910.2259780.411331failed
40.3337990.1023350.563866failed

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

P(healthy,healthy,failed,failed∣e1:4)=0.P(\text{healthy}, \text{healthy}, \text{failed}, \text{failed} \mid e_{1:4}) = 0.

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 34=813^4 = 81 paths, and the Viterbi algorithm performs it in time linear in the number of days. The answer here is

healthy,degrading,failed,failed,\text{healthy},\quad \text{degrading},\quad \text{failed},\quad \text{failed},

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.

Filtered P(rain)
0.111
0.703
0.148
Smoothed P(rain)
0.148
0.554
0.148
Most likely history
dry
dry
dry
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:

Sequenceposterior
healthy, degrading, failed, failed0.411331
healthy, healthy, healthy, healthy0.326541
healthy, healthy, degrading, failed0.097691
healthy, degrading, degrading, failed0.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 0.1×0.10.1 \times 0.1 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.

Related reading

7 min readProbabilistic Reasoning

Reasoning About a Changing World

How two Markov assumptions turn an unbounded history into two small tables, the forward and backward recursions that answer every question about the present and the past, why the most likely sequence needs an algorithm of its own, and what changes when the state is a real number rather than a list.

ProbabilityArtificial Intelligence
3 min readProbabilistic Reasoning

A Hundred Thousand Samples, Four Hundred of Them Real

On the burglary network with both neighbours calling, rejection sampling keeps 183 of 100,000 draws and likelihood weighting keeps all of them at an effective sample size of 396. Both estimates are about 10% off a posterior of 0.284172, and the reason is exactly computable: 252 samples carry 76% of the weight and 99.975% of the squared weight.

Artificial IntelligenceProbability
10 min readProbabilistic Reasoning

Learning the Numbers in a Probability Model

Where the numbers in a Bayesian network or a Gaussian actually come from: the three-step maximum-likelihood recipe worked through on discrete and continuous parameters, the Beta prior that repairs what it does to an unseen event, naive Bayes and the single zero count that destroys it, and the EM algorithm for the case where the counts cannot be taken at all - with every figure computed rather than asserted.

ProbabilityStatisticsArtificial Intelligence
← Back to all articles