A test finds 90 % of sick patients. Which probability is 0.9?
We know the patient is sick (right of the bar) and ask about the test result.
P(H)=0.5, P(E∣H)=0.6, P(E∣¬H)=0.2. What is P(H∣E)?
P(H∣E)=P(E∣H)P(H)+P(E∣¬H)P(¬H)P(E∣H)P(H) =0.6⋅0.5+0.2⋅0.50.6⋅0.5=0.40.3=0.75 The wolf and the pens from lab 1.
Which of these always sums to 1?
A conditional distribution sums to 1 over the variable left of the bar.
You roll a fair die and win the number shown in CZK. Expected win?
∑i=1661i=3.5. Today's risk is the same kind of average, of penalties.
Can a probability density p(x) be larger than 1?
Only the area under it must be 1. A narrow Gaussian peaks above 1.
You find a mushroom in the forest. Eat it or not? What is each symbol here?
| Symbol | Meaning | Mushroom example |
|---|---|---|
| X | observations x∈X: what we know (measurement, feature vector) | cap colour, smell, ring… and context: rain, temperature, month, place |
| K | hidden states (classes) k∈K: what we don't know | edible / poisonous |
| D | possible decisions (actions) | eat / leave it |
| pXK | joint probability pXK(x,k) of seeing x when the state is k | how often a red smelly one is poisonous |
| W | penalty (loss) W(k,d): the price of decision d when the truth is k | ate a poisonous one: hospital |
| q | strategy (decision function) q:X→D | your rule: "red with white dots → leave it" |
Penalty W(k,d) for the mushroom:
| truth k \ decision d | eat | leave it |
|---|---|---|
| edible | 0 | 1 (no dinner) |
| poisonous | 1000 (hospital) | 0 |
Question: the mushroom is 95 % likely edible. Should you eat it?
Question: over many mushrooms, what penalty does strategy q pay on average?
One pair (x,k): we decide q(x) and pay W(k,q(x)).
This pair occurs with probability pXK(x,k).
Average = sum over all pairs, weighted by probability: the Bayesian risk
This is the standard expectation Ez∼p[f(z)]=∑zp(z)f(z), with z=(x,k):
Is R(q) bounded?
Question: we can score any strategy with R(q). Which one do we want?
How many strategies are there? Say x is just the cap colour (4 values), D = {eat, leave}.
Question: must we try all ∣D∣∣X∣ strategies? No, decide each x separately
Start from the definition:
↓ Recall q:X→D: a strategy is one decision q(x)∈D for every x, and q(x) only appears in the term of its own x. So each term can be minimised on its own: the min moves inside the sum.
↓ For a fixed x, the value q(x) is just some decision: call it d and minimise over d∈D. Split the joint: pXK(x,k)=p(x)pK∣X(k∣x). The factor p(x) is the same for every d, so it can go in front of the min: multiplying all options by the same non-negative number does not change which one is smallest.
Question: if every mistake costs the same, which decision is best?
0/1 loss (D=K):
↓ Plug W into R(x,d)=∑kp(k∣x)W(k,d): the term k=d is multiplied by 0, all others by 1.
↓ The posterior sums to 1 over all k, so the sum over k=d is 1 minus the missing term.
↓ Minimising 1−p(d∣x) is the same as maximising p(d∣x).
↓ Bayes' rule: p(k∣x)=p(x∣k)p(k)/p(x). p(x) is the same for every k, so it does not change the argmax.
In q∗=argminqR(q), the argmin runs over…
q∗ is a whole function. It just happens that we can find it one x at a time.
With the 0/1 loss, R(q) is…
An average of 0s and 1s is a probability.
p(poisonous∣x)=0.01, penalties as before (1000 / 1). Eat?
R(x,eat)=0.01⋅1000=10, R(x,leave)=0.99⋅1=0.99.
The second character of a plate is the region (kraj):
Question: you stand at a crossroads in South Bohemia. Before looking at a plate: A or C?
So far p(x∣k) was given for every discrete x. We only have images: N×10×10 pixels.
Question: which single number x would separate A from C?
Today, a toy version: x=g(R−L), where g normalises, clips and rounds to X={0,1,2,3}.
In the lab: L−R, normalised and clipped to 21 values {−10,…,10}.
| x | 0 | 1 | 2 | 3 |
|---|---|---|---|---|
| P(x∣A) | 0.3 | 0.2 | 0.1 | 0.4 |
| P(x∣C) | 0.7 | 0.2 | 0.1 | 0 |
| W0/1: k \ d | A | C |
|---|---|---|
| A | 0 | 1 |
| C | 1 | 0 |
Now P(A)=0.25, P(C)=0.75. What is q∗(1)?
0.2⋅0.25=0.05<0.2⋅0.75=0.15: the prior breaks the tie.
Still P(A)=0.25. What is q∗(3)?
p(3∣C)=0: C never produces x=3, so any prior loses.
Uniform priors, but saying C when it is A costs 10. What is q∗(0)?
p(A∣0)=0.3: R(0,C)=0.3⋅10=3, R(0,A)=0.7⋅1=0.7.
Question: x∈R now. What changes in the risk?
Given: μA,μC,σA,σC,p(A),p(C), 0/1 loss. Still q∗(x)=argmaxkp(x∣k)p(k).
Where the two weighted curves cross.
Roots of ax2+bx+c=0:
Where is ax2+bx+c>0? It depends on the sign of a (picture).
In our case: a>0⇔σA>σC. The wider class wins on both tails.
Lab (find_strategy_2normal): thresholds t1≤t2 and a decision for each of the 3 intervals. Handle a=0, Δ=0 and Δ<0. Play with it: desmos.com/calculator/qa60j7hx6u
Question: with the 0/1 loss, R(q) = P(mistake). How do we compute it?
i numbers the intervals X1,X2,X3 (right); in Xi we answer qi: q1=A, q2=C, q3=A.
↓ Intuitive: in Xi we are wrong if the true class is any k=qi (hatched):
Problem: K−1 integrals per interval (below: K=3).
↓ In Xi exactly one class is right, qi (shaded); right + wrong = 1:
↓ Area between thresholds = area left of t2 − area left of t1: ∫t1t2p(x∣k)dx=Fk(t2)−Fk(t1)
Code: norm.cdf(t2, mu, sd) - norm.cdf(t1, mu, sd)
σA=σC, p(A)=p(C). Where is the threshold?
a=0 and the ln term is 0: halfway between the means.
Now p(A) grows. The threshold moves…
A becomes more likely a priori, so A's region grows.
σA=2, σC=0.5. Far out in the tails we decide…
The wider Gaussian decays more slowly: a>0, A wins outside the roots. The lab data is this case.
bayes_risk_discrete, find_strategy_discrete (ties → A), classify_discrete, classification_errorfind_strategy_2normal (t1, t2, 3 decisions), bayes_risk_2normal, classify_2normalQuestion: the lab also uses W2, where one kind of mistake costs 5. How does that move the decision?
Costs W(A,C)=wAC (true A, said C), W(C,A)=wCA, 0 when correct.
↓ In R(x,d)=∑kp(k∣x)W(k,d) only the wrong class survives:
↓ Decide A when R(x,A)<R(x,C); write p(k∣x)=p(x∣k)p(k)/p(x) and cancel p(x):
Question: two Gaussians (μA=0, μC=3, σ=1, equal priors). Calling a true A "C" now costs 5 (wAC=5, wCA=1). Where does the threshold go?
0/1 loss: equal σ and priors → halfway, t=1.5.
↓ With costs we compare the curves scaled by the cost of the other mistake (previous slide):
↓ Take ln as before; only c changes, c→c+ln5, and −3x+c>0 gives
↓ Risk ≠ error probability, so no "1 − P(correct)"; weight each mistake by its cost: