TactivergeLite

Lite / Textbooks / Introduction to Intelligent Systems / Chapter 5

5. Decisions under uncertainty

Version 1 · Technically checked (automated checks only) · 4 source lessons · Full interactive version

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.

Figure 5.1. Counting a detector's mistakes (described in words)

A confusion matrix for 1000 parts, 50 of them faulty. The detector catches 45 faulty parts and misses 5; it wrongly flags 30 good parts and passes 920. Precision is 45 ÷ 75 = 0.6 and recall is 45 ÷ 50 = 0.9.

Explanation

Built from 4 School lessons. Each part is the lesson's own explanation.

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

Open the Lite 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

Open the Lite 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

Open the Lite lesson: Bayes' rule for sensor readings

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

  1. 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

Open the Lite lesson: Updating a belief on a grid

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, in words

Figure 5.2 from Confusion matrices, precision and recall

On the tuning batch, slide the threshold from 0 to 100 and watch the four boxes. Find a threshold with recall at least 90%, then one with precision at least 90%. Can you get both at once? Write down the threshold you'd pick for a brake-part line and for a cheap plastic clip.

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.

Figure 5.3 from Expected value: deciding when you can't be sure

With the default costs, sweep p from 0 to 100% and note where the best action changes. Read the break-even points from the chart and check them by hand. Now make re-inspection free, then expensive. When is checking again worth it?

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%.

Figure 5.4 from Updating a belief on a grid

Pick 'Probably good'. Add one success and one failure: note the posterior mean. Now add 20 more in a 50:50 ratio. The prior's pull fades. Repeat with 'Probably poor' and check both posteriors converge.

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.

The interactive versions are in the full chapter.

Laboratory

These run in a browser on the full site (they need a faster connection). Simulations are simplified educational models.

Practice

Each question links to its Lite lesson, where your answer is checked on our server and a wrong answer gets a hint. Answers are never sent to your device.

  1. You lower the detection threshold. What usually happens?
    Answer it in “Confusion matrices, precision and recall”
  2. For an airport bag scanner, which matters most?
    Answer it in “Confusion matrices, precision and recall”
  3. p = 20%, scrap cost £25, re-inspection £6 (assumed perfect; scrap only if faulty). What is the expected cost of re-inspecting, in pounds?
    Answer it in “Expected value: deciding when you can't be sure”
  4. A robot's choice has a 0.1% chance of injuring someone. Why isn't expected cost alone the right tool?
    Answer it in “Expected value: deciding when you can't be sure”
  5. Prior P(H) = 0.2. P(E | H) = 0.8, P(E | not H) = 0.1. What is P(H | E)?
    Answer it in “Bayes' rule for sensor readings”
  6. 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…
    Answer it in “Bayes' rule for sensor readings”
  7. With a flat prior, where is the posterior's peak?
    Answer it in “Updating a belief on a grid”
  8. Why do robots rarely use plain grids to estimate 6-D pose (3 position + 3 orientation)?
    Answer it in “Updating a belief on a grid”

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)

Streaming video uses a lot of data. Everything you need is in the text.

Summary

Glossary

Random and systematic error
Random errors scatter readings unpredictably above and below the true value; systematic errors shift every reading the same way. Field Guide
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. Field Guide
Repeated trials
Repeating a measurement or test several times shows how much results vary and lets you average out random error. 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

Write it up on paper or in your own notes. Lite never stores what you write.

References

← 4. Search and planning6. State estimation and sensor fusion →