Textbooks/Introduction to Intelligent Systems/Chapter 5Lite (plain text) version
5Decisions under uncertainty
Version 1 · Technically checked (automated checks only) · 4 source lessons · 8 practice items
Introduction
A detector that says 'fault' is sometimes wrong, and an intelligent system must act anyway. This chapter counts mistakes with a confusion matrix, turns counts into precision and recall, and moves the detection threshold to trade one kind of error for the other. Bayes' rule then updates beliefs from evidence while respecting base rates, and expected value turns beliefs and costs into a decision.
Explanation
This chapter is built from 4 School lessons. Each part below is the lesson's own explanation; open the lesson for its predict-and-discover activities.
5.1 Confusion matrices, precision and recall
A defect detector is '95% accurate'. It might still miss every faulty part. How?
Four outcomes
With 'faulty' as the positive class: TP faulty and flagged; FN faulty but passed (a miss); FP good but flagged (a false alarm); TN good and passed. The confusion matrix lays these out as a 2×2 table of counts, rows for the truth and columns for the decision.
Precision and recall
Precision = TP ÷ (TP + FP): when it says faulty, how often is it right? Low precision wastes good parts. Recall = TP ÷ (TP + FN): of the faulty parts, how many does it catch? Low recall lets faults through. Accuracy = (TP + TN) ÷ total, which is dominated by the common class.
The threshold trade-off
Lowering the threshold flags more parts: recall rises and precision usually falls. Raising it does the opposite. Where to set it is not a maths question but an engineering one: what does each kind of mistake cost? Next lessons put numbers on that.
Common mix-ups
- High accuracy means a good detector.
✓ When positives are rare, a detector can be highly accurate and still miss most of them. Report precision and recall. - There is one correct threshold.
✓ The best threshold depends on the costs of each mistake, which depend on the application.
Open the full lesson: Confusion matrices, precision and recall →
5.2 Expected value: deciding when you can't be sure
A part is 15% likely to be faulty. Ship it, scrap it or check it again? There's a calculation for that.
Expected value
For an action with possible outcomes, expected cost = Σ (probability of outcome × cost of outcome). Shipping a part that is faulty with probability p: p × (return cost) + (1 − p) × 0. Compute it for every action and choose the smallest. It is the average cost per decision over many similar decisions.
Thresholds from costs
Ship beats scrap while p × C_miss < C_scrap, so the decision threshold is p* = C_scrap ÷ C_miss. With £20 and £200 that is 10%: scrap anything more than 10% likely to be faulty. This is how a probability from Bayes' rule becomes an action, and why the 'right' detector threshold depends on costs.
The value of a second look
Re-inspection costs something but removes uncertainty: expected cost = C_check + p × C_scrap (scrap only if it really is faulty). It wins in the middle range of p, where you are genuinely unsure, and loses when you're already nearly certain either way.
What averages hide
Expected value treats a 1% chance of a £10,000 disaster like a certain £100 loss. When outcomes include injury or irreversible harm, engineers add constraints (never ship above some risk, whatever the average) instead of just minimising expected cost.
Common mix-ups
- If something is more likely good than bad, treat it as good.
✓ When the costs of mistakes are unequal, the best action can be the 'unlikely' one. - Expected value predicts what will happen this time.
✓ It is a long-run average; any single decision can turn out better or worse.
Open the full lesson: Expected value: deciding when you can't be sure →
5.3 Bayes' rule for sensor readings
The hazard detector beeps. It catches 90% of real hazards and false-alarms only 5% of the time. Is the rock really dangerous? Probably less likely than you think.
The rule
P(H | E) = P(E | H)·P(H) / P(E), with P(E) = Σ P(E | Hᵢ)P(Hᵢ) over all hypotheses. Prior P(H): belief before the reading. Likelihood P(E | H): how probable the reading is if H is true. Posterior P(H | E): belief after.
Base rates matter
A good sensor on a rare event still gives many false alarms. With a 1% prior, even a 99%-accurate detector with a 1% false-alarm rate gives a posterior of only 50%. Ignoring the prior is the base-rate fallacy.
Updating repeatedly
Today's posterior is tomorrow's prior. Two independent readings multiply their likelihoods. After two alarms from independent detectors in the example, P(hazard) rises from 0.67 to about 0.97. Independence is crucial: two looks by the same camera at the same shadow are not independent evidence.
Common mix-ups
- P(E | H) and P(H | E) are the same thing.
✓ They can be wildly different: a 90% hit rate does not make 90% of alarms real. - More readings always mean more certainty.
✓ Only if they are independent. Correlated readings repeat the same mistake.
5.4 Updating a belief on a grid
Instead of 'hazard or not', what if the unknown can be any number between 0 and 1? Split it into 21 slices and let the data reshape them.
The grid recipe
- Choose grid values p₁…p_m. 2. Assign prior weights π(pⱼ) summing to 1. 3. For the data, compute the likelihood L(pⱼ) = pⱼᵏ(1 − pⱼ)ⁿ⁻ᵏ. 4. Multiply: πⱼ·Lⱼ. 5. Normalise by the sum. That is the posterior: a full distribution over the unknown.
Summaries
The MAP (maximum a posteriori) is the highest bar. The posterior mean Σ pⱼ·postⱼ balances the bars. A credible probability such as P(p > 0.5 | data) is the sum of bars above 0.5: a direct answer to 'how sure are we the camera is better than a coin?'
Prior versus data
With a flat prior, the posterior is the normalised likelihood and its peak is the MLE k/n. Informative priors matter when data are scarce and fade as n grows. A grid is simple and exact for one or two parameters, but the number of cells explodes in high dimensions: that is why filters use Gaussians instead.
Common mix-ups
- A Bayesian answer is just a single best number.
✓ It is a whole distribution; MAP, mean and credible probabilities are summaries chosen for the question. - Priors make Bayesian results arbitrary.
✓ Priors matter with little data and fade with more. Stating them openly is more honest than hiding assumptions.
Worked examples
Confusion matrices, precision and recall: example 1
TP = 40, FP = 10, FN = 20, TN = 930. Find precision, recall and accuracy.
Solution
Precision = 40/50 = 80%. Recall = 40/60 ≈ 66.7%. Accuracy = 970/1000 = 97%. The detector misses a third of the faulty parts despite 97% accuracy.
Expected value: deciding when you can't be sure: example 1
p = 30%, miss £200, scrap £20, re-inspect £8. Which action?
Solution
Ship: 0.3 × 200 = £60. Scrap: £20. Check: 8 + 0.3 × 20 = £14. Re-inspect, which is cheapest on average.
Bayes' rule for sensor readings: example 1
Prior 0.02, hit rate 0.95, false-alarm rate 0.02. Posterior after one alarm?
Solution
0.95 × 0.02 = 0.019; 0.02 × 0.98 = 0.0196. P = 0.019/0.0386 ≈ 0.49.
Updating a belief on a grid: example 1
Three hypotheses for p: 0.2, 0.5, 0.8, equal prior. One success observed. Posterior?
Solution
Likelihoods 0.2, 0.5, 0.8, sum 1.5. Posterior 0.133, 0.333, 0.533.
Interactive figures
Interactive figure (online). Description: Sixty parts are drawn on a score strip: faulty parts as triangles that tend to score high, good parts as circles that tend to score low, with overlap in the middle. A threshold line splits them into flagged and passed. The table shows TP, FN, FP and TN; at a threshold of 50 on the tuning batch most faulty parts are flagged and a handful of good parts are wrongly flagged.
Interactive figure (online). Description: The chart plots expected cost against the probability of a fault for three actions: shipping (a line rising from £0 to £200), scrapping (flat at £20) and re-inspecting (rising gently from £8 to £28). With the defaults, shipping is cheapest below about 4%, re-inspecting between about 4% and 60%, and scrapping above about 60%.
Interactive figure (online). Description: The grid shows 21 bars for the posterior plus prior and likelihood lines. The readout lists the data as ticks and crosses and states MAP, posterior mean, P(p > 0.5) and k/n.
Laboratory
Everything runs in your browser. No kit, nothing mains-powered. Simulations are simplified educational models.
Simulation OS experiment
Simulation OS: Sorting conveyor sensors
Raise and lower the detection threshold, fill in a confusion matrix at each setting and plot precision against recall.
Open Simulation OS: Sorting conveyor sensors →BUILD level
BUILD: Sorting machine, level 5
Choose a threshold for the sorting machine by weighing the cost of a missed fault against the cost of scrapping a good part.
Open BUILD: Sorting machine, level 5 →
Guided practice
Answers are checked on the server; wrong answers get a hint and another try. Signed in, solved items also count towards the source lesson.
- You lower the detection threshold. What usually happens?
- Recall rises, precision falls
- Precision rises, recall falls
- Both rise
- For an airport bag scanner, which matters most?
- Precision
- Recall
- Accuracy
- p = 20%, scrap cost £25, re-inspection £6 (assumed perfect; scrap only if faulty). What is the expected cost of re-inspecting, in pounds? (£)
- A robot's choice has a 0.1% chance of injuring someone. Why isn't expected cost alone the right tool?
- Because 0.1% is too small to matter
- Because some outcomes are unacceptable whatever the average, so they need hard limits
- Because expected value can't handle small probabilities
- Prior P(H) = 0.2. P(E | H) = 0.8, P(E | not H) = 0.1. What is P(H | E)?
- A dust-storm alarm is 99% sensitive and has a 1% false-alarm rate, but storms occur on only 1% of sols. After an alarm, P(storm) is about…
- 99%
- 50%
- 1%
- 90%
- With a flat prior, where is the posterior's peak?
- At the maximum-likelihood estimate
- At 0.5 always
- At the posterior mean
- Nowhere: a flat prior gives a flat posterior
- Why do robots rarely use plain grids to estimate 6-D pose (3 position + 3 orientation)?
- The number of cells grows exponentially with dimension
- Bayes' rule fails in 6-D
- Grids cannot represent uncertainty
- Priors cannot be defined in 6-D
Engineering applications
Security scanners
Airport scanners are tuned for very high recall: missing a threat costs far more than a false alarm, so many harmless bags are searched by hand to make sure almost nothing dangerous passes.
Predictive maintenance
A vibration alarm for rare faults will mostly flag healthy machines unless its false-alarm rate is tiny. Bayes' rule with the true base rate tells maintenance teams how much to trust each alarm.
Watch
Optional verified videos. Nothing loads from YouTube until you press play.
- Machine Learning Fundamentals: The Confusion Matrix (StatQuest with Josh Starmer)
- The medical test paradox, and redesigning Bayes' rule (3Blue1Brown)
- Bayes theorem, the geometry of changing beliefs (3Blue1Brown)
- ROC and AUC, Clearly Explained! (StatQuest with Josh Starmer)
Chapter summary
- A confusion matrix counts true and false positives and negatives; precision = TP/(TP + FP), recall = TP/(TP + FN).
- Lowering a threshold usually raises recall and lowers precision; the costs of each error decide the setting.
- Bayes' rule updates a prior with evidence; ignoring the base rate is the commonest mistake.
- Expected value weighs outcomes by probability and cost; some outcomes, like harm to people, are constraints, not costs.
Glossary
- Random and systematic error
- Random errors scatter readings unpredictably above and below the true value; systematic errors shift every reading the same way.
- Accuracy, precision and resolution
- Accuracy is how close a measurement is to the true value; precision is how close repeated measurements are to each other; resolution is the smallest change an instrument can show.
- Repeated trials
- Repeating a measurement or test several times shows how much results vary and lets you average out random error.
Definitions from the Field Guide.
Project: Set the threshold, defend the choice
For a simulated detector with a known fault rate, tabulate the confusion matrix at five thresholds. Assign stated costs to each error, compute the expected cost of each threshold, and choose one. Say how the choice would change if faults became ten times rarer.
Deliverables
- Confusion matrices at each threshold
- Expected cost per threshold with stated costs
- The choice and the base-rate sensitivity
Keep your work in your Engineering Journal; it stays private unless you choose to share it.
References
- Stuart Russell and Peter Norvig (2020). Artificial Intelligence: A Modern Approach, 4th edition. Pearson.
- Sebastian Thrun et al. (2005). Probabilistic Robotics. MIT Press.
Publication record
- Version
- 1
- Status
- Technically checked (automated checks only)
- Technical review
- Automated checks only, last run 2026-11-29. No human, educator or mentor review is claimed.src/content/textbooks/textbooks.test.ts: schema, every lesson, diagram, practice item, video, Field Guide entry, lab and reference resolves; figure numbers recomputed; no practice answers in client payloads.
- Written by
- Compiled and written by the Tactiverge team with AI assistance, from Tactiverge School lessons that were themselves written with AI assistance.
- Licence
- All rights reserved by the founders unless a licence is approved.
- Corrections
- None recorded yet.Spotted a mistake? Use “Report a problem” on any chapter, or see the corrections page.