Question: Bayes needs the priors p(k) and the loss W. What if we don't have them?
Priors drift: flu cases next winter, pedestrians at 8:00 vs. 3:00. The world changes, independently of us.
Priors react to us: a spammer sends more of what gets through our filter. The prior depends on our own q, so no estimate stays valid.
Losses not comparable: no agreed exchange rate between the two mistakes
missed tumour vs. unnecessary biopsy
convicting an innocent vs. freeing a guilty person
deleting a legitimate post vs. leaving a harmful one
What we can still compute without priors: how often each class is misclassified, the class error
ϵ(k)=x:q(x)=k∑p(x∣k)
↑ Bayes decided per x with p(k∣x)=p(x∣k)p(k)/p(x), which needs p(k). Here we fix the true class k and ask how often we are wrong: only p(x∣k).
Non-Bayesian problems: choose q by a rule on the ϵ(k), not on ∑kp(k)ϵ(k).
Three non-Bayesian formulations
Neyman–Pearson
1 = dangerous, 2 = normal (smoke detector: fire / no fire). Missing a danger is ϵ(1), a false alarm is ϵ(2).
q∗=q:X→Kargminfalse alarmsϵ(2)
s.t.missed dangersϵ(1)≤ϵˉ1
Limit missed dangers, then minimise false alarms. The limit alone is met by "always alarm" (ϵ(1)=0), useless.
Minimax
Unknown mix (face unlock: how often impostors try is unknown). Make the worst class error as small as possible. In biometrics this is the equal error rate, the usual way to compare systems.
q∗=q:X→Kargmink∈Kmaxϵ(k)
ϵ(k)=x:q(x)=k∑p(x∣k)
Whatever the mix of classes, the total error is at most maxkϵ(k).
Wald
A reject option without priors or prices. Both errors must stay below ϵ; what we cannot decide safely goes to a human (a cheque reader passes unclear amounts to a clerk). Send the clerk as little as possible.
q∗=q:X→Dargminimaxκi
s.t. ϵ1≤ϵ,ϵ2≤ϵ
κi=∑x:q(x)=?p(x∣i): how much of class i the clerk sees. The caps alone are met by "always ?" (no errors, all work for the clerk).
None of them needs p(k) or W. Neyman–Pearson examples are in the lecture; today: minimax.
Quick check
Reject option, ε=0.2. For some x, maxkp(k∣x)=0.7. Decide…
Rule: answer a class only if 1−maxkp(k∣x)<ε. Here 1−0.7=0.3≥0.2.
Which formulation needs the priors p(k)?
The non-Bayesian ones only use the class errors ϵ(k), built from p(x∣k).
Compare the worst errors: max=0.30 for qa, 0.25 for qb. The smaller worst case wins, even though qa has the smaller average.
Part III
Exercises
Discrete minimax: female or male?
x=(h,w): height bin h1–h3, weight bin w1–w4. Classes: 1 = female, 2 = male.
p(x∣1), female
w1
w2
w3
w4
h1
.197
.145
.094
.017
h2
.077
.299
.145
.017
h3
.001
.008
.000
.000
p(x∣2), male
w1
w2
w3
w4
h1
.011
.005
.011
.011
h2
.005
.071
.408
.038
h3
.002
.014
.255
.169
Task: find the minimax strategy q:X→{1,2} and its worst class error.
Hint: there are 212=4096 strategies. Which ones are worth trying?
Three strategies to start with
Question: what is the worst class error of each? ϵ(k)=∑x:q(x)=kp(x∣k)
Everyone male
w1
w2
w3
w4
h1
M
M
M
M
h2
M
M
M
M
h3
M
M
M
M
ϵ(1)=1, ϵ(2)=0 worst: 1.000
every woman is wrong, every man right
Everyone female
w1
w2
w3
w4
h1
F
F
F
F
h2
F
F
F
F
h3
F
F
F
F
ϵ(1)=0, ϵ(2)=1 worst: 1.000
every man is wrong, every woman right
Light = female, heavy = male
w1
w2
w3
w4
h1
F
F
M
M
h2
F
F
M
M
h3
F
F
M
M
ϵ(1)=0.273, ϵ(2)=0.108 worst: 0.273
women called male (w3,w4): 0.094+0.017+0.145+0.017
The extremes have worst error 1. A sensible split gets 0.273. How low can we go, and which of the 4096 splits should we try?
Discrete minimax: which strategies to try?
↓ How male-like is a cell compared with female-like? The likelihood ratio:
r(x)=p(x∣F)p(x∣M)
w1
w2
w3
w4
h1
0.056
0.034
0.117
0.647
h2
0.065
0.237
2.814
2.235
h3
2.000
1.750
∞
∞
↓ Sort the cells by r, largest first (rank 1 = most male-like):
w1
w2
w3
w4
h1
11
12
9
7
h2
10
8
3
4
h3
5
6
2
1
↓ Give the i lowest-ranked cells to class 2 (male), the rest to class 1 (female). Taking a cell out of order costs more error for the same gain, so the best strategies follow this order (exactly so once we may randomise one boundary cell).
13 candidates: i=0,1,…,12. This is the search the assignment asks for.
Continuous minimax I
Two classes, x∈[−1,1]:
p(x∣1)=∣x∣,p(x∣2)=1−∣x∣
Task: find the minimax strategy q∗=argminqmaxkϵ(k) and its worst error.
ϵ(k)=∫x:q(x)=kp(x∣k)dx
Hint: which x look like class 1? The likelihood ratio
r(x)=p(x∣2)p(x∣1),q(x)=1 where r(x)>α
Try it: move the ratio threshold α (exercise I)
Continuous minimax II
Two classes, x∈[0,1]:
p(x∣1)=1,p(x∣2)=x+0.5
Task: find the minimax strategy and its worst error.
Hint: which x look like class 1? The likelihood ratio
r(x)=p(x∣2)p(x∣1),q(x)=1 where r(x)>α
Question: is the threshold where the two densities cross?
Continuous minimax III: two Gaussians
p(x∣k)=σk2π1exp(−2σk2(x−μk)2)
K={1,2}:μ1=−5,σ1=2μ2=1,σ2=5
Task: find the minimax strategy q∗=argminqmaxkϵ(k).
Remember: the best strategies are thresholds on the likelihood ratio
↓ 2π cancels; dividing two exponentials subtracts the exponents:
r(x)=σ1σ2exp(−2σ12(x−μ1)2+2σ22(x−μ2)2)
↓ ln is increasing and r,α>0, so r>α⟺lnr>lnα. The log undoes the exp:
lnr(x)=lnσ1σ2−2σ12(x−μ1)2+2σ22(x−μ2)2
↓ Expand the squares, collect the powers of x:
lnr(x)=ax2+bx+c
a=2σ221−2σ121,b=σ12μ1−σ22μ2
c=2σ22μ22−2σ12μ12+lnσ1σ2
↓ Our numbers (μ1=−5,σ1=2; μ2=1,σ2=5):
lnr(x)=−0.105x2−1.29x−2.19
r(x)>α⟺ax2+bx+c−lnα>0: a quadratic inequality, at most two roots t1,t2.
How does a ratio threshold split x?
↓ From the previous slide: lnr is a quadratic in x.
lnr(x)=−2σ12(x−μ1)2+2σ22(x−μ2)2+lnσ1σ2
↓ σ1<σ2: a parabola opening down.
↓ Say 1 above lnα (here α=1): class 1 gets an interval [t1,t2].
↓ Class 1 is wrong in its tails, class 2 inside:
ϵ(1)=∫−∞t1p(x∣1)dx+∫t2∞p(x∣1)dx
ϵ(2)=∫t1t2p(x∣2)dx
Minimax: pick α so that ϵ(1)=ϵ(2). No closed form: solve numerically.
How do we solve ϵ(1)=ϵ(2) numerically?
↓ For one fixed α, everything is computable. Roots of the quadratic:
ax2+bx+(c−lnα)=0→t1,t2
↓ Errors from the normal CDF Φ (table, or norm.cdf):
ϵ(1)=1−[Φ(σ1t2−μ1)−Φ(σ1t1−μ1)]
ϵ(2)=Φ(σ2t2−μ2)−Φ(σ2t1−μ2)
↓ Larger α: fewer x say 1, so ϵ(1) grows and ϵ(2) shrinks. They cross once.
↓ Bisection: α=1 has ϵ(1)<ϵ(2), α=4 has ϵ(1)>ϵ(2). Try the midpoint, keep the half where the order flips.
[αlo,αhi]
α
t1,t2
ϵ(1)
ϵ(2)
keep half
[1, 4]
2.5
−9.00, −3.29
0.218
0.173
lower
[1, 2.5]
1.75
−9.54, −2.74
0.141
0.210
upper
[1.75, 2.5]
2.13
−9.26, −3.03
0.178
0.190
upper
[2.13, 2.5]
2.31
−9.13, −3.16
0.198
0.181
lower
[2.13, 2.31]
2.22
−9.19, −3.09
0.188
0.186
…
α≈2.20: class 1 on [−9.20,−3.08], ϵ(1)=ϵ(2)≈0.187. Each step halves the interval.
The assignment searches over the prior p(1)=1+α1 instead (one number, same idea), with fminbound on maxkϵ(k).
Try it: move the ratio threshold α
Part IV
Minimax and Bayes
Priors exist, but we don't know them
Question: how large can the Bayesian error of a strategy q get, if the priors are unknown?
Error of q (0/1 loss): the mass of all pairs we get wrong.
ϵ=k∑x:q(x)=k∑p(x,k)
↓ Split p(x,k)=p(k)p(x∣k); p(k) does not depend on x, so it leaves the inner sum.
ϵ=k∑p(k)ϵ(k)x:q(x)=k∑p(x∣k)
↓ p(k)≥0 and ∑kp(k)=1: ϵ is a convex combination of the ϵ(k), so it is at most the largest one (reached with p(k)=1 for that class).
priorsmaxϵ=kmaxϵ(k)
To be safe for every prior, minimise the worst case: minqmaxkϵ(k).
Minimax = Bayes with unknown priors and the worst prior assumed. Same solution.
Which strategies can be minimax?
Question: do we have to search all strategies, or just a few?
Bayesian strategy for a prior p(1) (lab 2, 0/1 loss): say 1 if
p(x∣1)p(1)≥p(x∣2)p(2)
↓ Divide both sides by p(x∣2)p(1)>0:
p(x∣2)p(x∣1)≥p(1)p(2)=α
↓ Every prior gives one α. Backwards: which prior gives a chosen α? Use p(2)=1−p(1):
α=p(1)1−p(1)
↓ Multiply by p(1), collect the p(1) terms:
αp(1)=1−p(1)⇒p(1)=1+α1
Priors and ratio thresholds match one to one: p(1)∈(0,1)↔α∈(0,∞).
The minimax strategy is a ratio threshold, so it is a Bayesian strategy for some prior c:
qminimax∗=qBayes∗(p(1)=c)
→ Search over one number p(1), reusing the code from lab 2.
What if the true prior is different?
Design the Bayesian strategy qb for p(1)=0.7 (exercise III).
Its risk for that prior:
R(qb)=p(1)ϵ(1)+p(2)ϵ(2)
↓ Two classes: p(2)=1−p(1), so R is a convex combination of ϵ(1) and ϵ(2):
=p(1)ϵ(1)+(1−p(1))ϵ(2)
↓ Collect the terms with p(1):
=p(1)(ϵ(1)−ϵ(2))+ϵ(2)
↓ qb is fixed, so ϵ(1),ϵ(2) are fixed: a straight line in the true prior, a⋅p(1)+b.
Where is the minimax strategy?
Dots: pick a prior, design its Bayesian strategy (lab 2), compute its risk at that prior. Repeat for a few priors.
Blue: do it for every prior: the Bayes risk curve R∗(p(1)).
Grey: a fixed strategy qb is a line, never below the blue curve, touching it at its design prior p0:
R(qb,p)≥R∗(p)=qminR(q,p),= at p=p0
↑ R∗ is the best any strategy can do; qb is the best at p0.
Orange: the worst case of qb over all priors is the higher end of its line, max(ϵ(1),ϵ(2)). Plot it at p0.
Same for p0=0.2 (here the right end is higher), then for every p0: the orange curve.
Black: the lowest worst case is a flat line. It touches the top of the blue curve.
The minimax prior is the worst prior for Bayes: the one with the largest Bayes risk.
Try it: one strategy, two views
Why ϵ(1)=ϵ(2)?
Question: the minimax line is flat. What does that say about its class errors?
Risk of a fixed q when the true prior is p(1) (two slides back):
R(q)=p(1)⋅(ϵ(1)−ϵ(2))+ϵ(2)
↓ A tilted line has its maximum at an end, max(ϵ(1),ϵ(2)), larger than at the flat position. Flat means slope 0:
q∗⇔ϵ(1)=ϵ(2)
↓ Put slope 0 into the line:
R(q∗)=p(1)⋅0(ϵ(1)−ϵ(2))+ϵ(2)=ϵ(2)
The minimax strategy has the same risk for every prior: it does not care what the prior is.
Quick check
A fixed strategy has ϵ(1)=0.1, ϵ(2)=0.3. Its risk if p(1)=0.5?
R=p(1)ϵ(1)+p(2)ϵ(2)=0.5⋅0.1+0.5⋅0.3=0.2
The same strategy: its worst risk over all priors?
A line in p(1), largest at an end: max(ϵ(1),ϵ(2))=0.3 (at p(1)=0).
How does the risk of the minimax strategy change with the true prior?
ϵ(1)=ϵ(2)=ϵ, so R=p(1)ϵ+(1−p(1))ϵ=ϵ for every prior: a flat line.
Quick check: minimax or Bayes?
Is the minimax strategy the Bayesian strategy for equal priors p(1)=p(2)?
It is the Bayesian strategy for the worst prior c. That is 0.5 only in special cases, e.g. a symmetric problem like exercise I. In exercises II and III it is not.
The true priors are equal. Which strategy has the smaller error?
Bayes is optimal for the prior it was designed for. Minimax pays for being safe under every prior (unless c=0.5).
Implementing the discrete search
Question: how do we get ϵ(1),ϵ(2) for all thresholds without a loop over strategies?
Flatten both tables p(x∣1), p(x∣2) to vectors of length N (21 × 21 = 441).
Ratio r=p(x∣1)/p(x∣2) per cell. 0/0 = NaN: treat as class 1 (assignment rule).
Sort cells by r, largest first (most class-1-like): np.argsort, reversed.
Strategy i: first i sorted cells say 1, the rest 2; i=0,…,N (N+1 strategies).
i∗=argminimax(ϵ1[i],ϵ2[i]); map back to the 21 × 21 grid with the sort order.
↓ Moving from i to i+1 moves one cell to class 1: running sums give all errors at once.