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.
About 40 min · 3 goals · Checked by automated tests
1.Why should I care?
A perception system's output is a probability; a machine must still act. Expected value connects the two: it turns 'probably faulty' and 'a return costs £200' into a decision rule and a threshold you can defend.
- ◇ Compute the expected cost of each action as Σ probability × cost.
- ◇ Find the break-even probability between two actions.
- ◇ Explain what expected value ignores and when worst-case thinking matters more.
2.Predict
A part is 15% likely to be faulty. Shipping a faulty part costs £200; scrapping any part costs £20. Which is cheaper on average?
Guess first. Being wrong here is how the surprise works.
3.Discover
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?
Loading the interactive…
Can't use the interactive? Read a description instead
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%.
4.Checkpoint: guided practice
Check what you just discovered before going on. Hints appear after a wrong answer.
Practice 1
Shipping a part with a 4% chance of being faulty, where a faulty shipment costs £300. What is the expected cost of shipping, in pounds?
5.Understand
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.
Explain it another way
Taking an umbrella: if rain is only 20% likely but getting soaked ruins your day, you take it anyway, because the bad outcome is so much worse than carrying an umbrella.
Bayes decision rule: choose the action a minimising Σₛ P(s | evidence)·L(a, s), where L is the loss table. For two actions and two states it reduces to a threshold on P(s | evidence) set by the loss ratio.
Ship vs scrap: p·M = S gives p* = S/M. Check vs ship: C + p·S = p·M gives p = C/(M − S). Check vs scrap: C + p·S = S gives p = 1 − C/S.
Autonomous vehicles weigh the cost of an unnecessary emergency brake against a missed obstacle. Because a miss can injure someone, designers set hard safety constraints rather than relying on average cost alone.
Worked example 1
p = 30%, miss £200, scrap £20, re-inspect £8. Which action?
Ship: 0.3 × 200 = £60. Scrap: £20. Check: 8 + 0.3 × 20 = £14. Re-inspect, which is cheapest on average.
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.
6.Practice on your own
Practice, not a test. Wrong answers get a hint and another try.
Practice 2 · a fresh version every time
A part has a 5% chance of being faulty. Shipping a faulty part costs £400; shipping a good part costs £0. Scrapping any part costs £5. What is the expected cost of shipping it, in pounds?
Practice 3 · a fresh version every time
Shipping a faulty part costs £200; scrapping any part costs £15. Above what probability of a fault (as a percentage) does scrapping have the lower expected cost?
Practice 4
p = 20%, scrap cost £25, re-inspection £6 (assumed perfect; scrap only if faulty). What is the expected cost of re-inspecting, in pounds?
Practice 5
A robot's choice has a 0.1% chance of injuring someone. Why isn't expected cost alone the right tool?
7.Apply it
Combine this week: take the Bayes posterior for a flagged part (base rate 2%, sensitivity 90%, false positives 5%) and the costs £200 miss, £20 scrap, £8 re-inspection. Decide what to do with flagged and unflagged parts, and compute the expected cost per 1,000 parts of your policy.
8.Reflect
Concepts: Decisions under uncertainty and expected value · Conditional probability and Bayes' rule · Constraints, budgets and trade-offs