Chapter 2 ERM with finite hypothesis classes

In (1.6) we showed that for any hβˆ—βˆˆβ„‹ ,

Lπ’Ÿβ’(h^Z)βˆ’Lπ’Ÿβ’(hβˆ—)≀(Lπ’Ÿβ’(h^Z)βˆ’LZ⁒(h^Z))+(LZ⁒(hβˆ—)βˆ’Lπ’Ÿβ’(hβˆ—)).

We’d like to bound these two terms, which would then give us a bound on how much worse h^Z is than the comparator hβˆ— . Since hβˆ— is arbitrary, choosing the best hβˆ— lets us compare to the best thing ERM could have possibly done.

The first thing to note, though, is that anything with a Z in it – so everything above except for Lπ’Ÿβ’(hβˆ—) – depends on the draw of the random training set ZβˆΌπ’Ÿm . It’s possible that we could get some ridiculously unlikely training set where everything behaves nonsensically. So we’ll need to do some kind of probabilistic bound.

Let’s now try to study that formally.

2.1 Estimation error: asymptotics

Let’s start with the second term from (1.6):

LZ⁒(hβˆ—)βˆ’Lπ’Ÿβ’(hβˆ—)=1mβ’βˆ‘i=1mℓ⁒(hβˆ—,zi)βˆ’π”ΌzβˆΌπ’Ÿβ„“β’(hβˆ—,z).

Remember that the only thing that’s random here is Z=(z1,…,zm) , since hβˆ— is just some fixed hypothesis. So, we can frame this as 1mβ’βˆ‘i=1mri , where the ri=ℓ⁒(hβˆ—,zi) are iid random variables with mean 𝔼ℓ⁒(hβˆ—,zi)=Lπ’Ÿβ’(hβˆ—) . The law of large numbers therefore guarantees that as mβ†’βˆž , 1mβ’βˆ‘i=1mri converges (almost surely) to Lπ’Ÿβ’(hβˆ—) , and so this term in the bound converges to zero.

In fact, for many β„‹ and β„“ , the other term will also have the same property, that LZ⁒(h^Z)β†’Lπ’Ÿβ’(h^Z) . Therefore, by (1.6), we have (if hβˆ— is a minimizer of Lπ’Ÿ ) that Lπ’Ÿβ’(h^Z)β†’Lπ’Ÿβ’(hβˆ—) . Various formalizations of this last property are called consistency, and it’s a nice property to have: eventually, your learning algorithm works as well as it could have. One problem with this notion, though, is that this is all it tells you. There’s no guarantee about what happens with m=1,000 , or when going from m=1,000 to m=1,000,000 , or anything at all other than “eventually it works.”

A more precise analysis might use the central limit theorem. Let Οƒ2=Var[ri] and assume this is finite; 111Formally, we’d write 1mβ’βˆ‘i=1m(riβˆ’π”Όri)β†’d𝒩⁒(0,Οƒ2) ; the β†’d is convergence in distribution. informally, the CLT then says that 1mβ’βˆ‘i=1mri behaves like 𝒩⁒(Lπ’Ÿβ’(hβˆ—),Οƒ2/m) . In fact, it’s often true that the first term is also asymptotically normal ([VAN98], Section 5.3). This is a nicer result than before: it still doesn’t say anything particular for a finite m (maybe the CLT takes a long time to kick in), but it tells us a lot about the asymptotic behaviour, including both its limiting value and also roughly how much variation we can expect around that value.

It can be tough to find these exact limiting distributions in general, though, and they’re not always true (e.g. the one I didn’t state for the first term above has some strict requirements on the way that h is parameterized, which are often not true for real models ([WMG+23])). A similar but somewhat looser style of bound is to say that 222You can check the wiki page for a formal definition of π’ͺp , but it roughly means “with any constant probability, a sequence of sampled random variables is π’ͺ⁑(1/m) .” the estimation error is π’ͺp⁑(1/m) , which is implied by the CLT result above, but can also be much easier to show. Again, this doesn’t imply anything for a finite m (just like how π’ͺ analyses don’t say anything for any specific input size on your algorithms), but it does say things like “for reasonably large m , observing four times as much data should roughly halve your estimation error.”

The most preferred kind of result, though, is usually one with explicit constants: something like (if |β„‹| is finite – see section 2.3)

βˆ€Ξ΄βˆˆ(0,1),PrZβˆΌπ’Ÿm⁑(Lπ’Ÿβ’(h^Z)βˆ’infhβˆˆβ„‹Lπ’Ÿβ’(h)≀2m⁒log⁑|β„‹|+1Ξ΄)β‰₯1βˆ’Ξ΄

or, where B is a problem parameter,

𝔼ZβˆΌπ’ŸmLπ’Ÿβ’(h^Z)≀infhβˆˆβ„‹Lπ’Ÿβ’(h)+8⁒B2m.

These results give you a rate, but also apply to any m , not just eventually. (They might not be meaningful for small m , though; if you’re using 0-1 loss, it’s not very helpful to say the estimation error is less than four!)

2.2 Uniform convergence, bounded loss

We’re first going to assume that ℓ⁒(h,z)∈[a,b] for all h,z ; often a=0 , and e.g. for the 0-1 loss we have b=1 . For something like the square loss, it isn’t “automatically” bounded, but it still might be bounded by the choice of β„‹ and π’Ÿ ; we’ll discuss this later.

Recall that we have two things to bound in (1.6):

Lπ’Ÿβ’(h^Z)βˆ’LZ⁒(h^Z)=𝔼zβˆΌπ’Ÿβ„“β’(h^Z,z)βˆ’1mβ’βˆ‘i=1mℓ⁒(h^Z,zi) (A)

and

LZ⁒(hβˆ—)βˆ’Lπ’Ÿβ’(hβˆ—)=1mβ’βˆ‘i=1mℓ⁒(hβˆ—,zi)βˆ’π”ΌzβˆΌπ’Ÿβ„“β’(hβˆ—,z). (B)

As we discussed, (B) is an average of iid random variables. We can bound this with the following form of Hoeffding’s inequality, which we’ll prove in chapter 3:

Proposition 2.1 (Hoeffding, simple form).

Let (x1,…,xm) be independent, each with mean ΞΌ and bounded in [a,b] almost surely ( Pr⁑(a≀xi≀b)=1 ). Then

Pr⁑(1mβ’βˆ‘i=1mxi≀μ+(bβˆ’a)⁒log⁑(1/Ξ΄)2⁒m)β‰₯1βˆ’Ξ΄β’
Pr⁑(1mβ’βˆ‘i=1mxiβ‰₯ΞΌβˆ’(bβˆ’a)⁒log⁑(1/Ξ΄)2⁒m)β‰₯1βˆ’Ξ΄
Pr⁑(|1mβ’βˆ‘i=1mxiβˆ’ΞΌ|≀(bβˆ’a)⁒log⁑(2/Ξ΄)2⁒m)β‰₯1βˆ’Ξ΄.

Applying this to the random variables xi=ℓ⁒(hβˆ—,zi) handles the bound for (B).

It’s tempting to also try to apply this result directly to (A), which would then complete our bound and everything would be really simple. The problem is that the ℓ⁒(h^Z,zi) aren’t independent! The choice of h^Z depends on all of Z , i.e. on all of the other zj , so ℓ⁒(h^Z,z1) and ℓ⁒(h^Z,z2) are not independent.

So, how can we bound this? The most common way is called uniform convergence. The idea is that if we know that Lπ’Ÿβ’(h)βˆ’LZ⁒(h) is small for all hβˆˆβ„‹ , then it’ll be small for h^Z , no matter how we pick it – since it’s something in β„‹ . That is, 444 sup is the version of max for potentially infinitely many things, like how inf is the version of min . if we know that

suphβˆˆβ„‹[Lπ’Ÿβ’(h)βˆ’LZ⁒(h)]≀Ρ

then we also have that Lπ’Ÿβ’(h^Z)βˆ’LZ⁒(h^Z)≀Ρ . Or, stating it another way,

PrZβˆΌπ’Ÿm(Lπ’Ÿ(h^Z)βˆ’LZ(h^Z)>Ξ΅)≀PrZβˆΌπ’Ÿm(βˆƒhβˆˆβ„‹.Lπ’Ÿ(h)βˆ’LZ(h)>Ξ΅), (2.1)

and so upper-bounding the right-hand side bounds the left-hand side.

How can we bound that?

2.3 Finite β„‹

To start, we’ll make a kind of drastic assumption: that |β„‹| is finite, e.g. we’re only considering 500 possible hypotheses.

Proposition 2.2.

Suppose ℓ⁒(h,z) is almost surely bounded in [a,b] , β„‹ is finite, and h^Z is any ERM in β„‹ . Then for any δ∈(0,1) , with probability at least 1βˆ’Ξ΄ over the choice of ZβˆΌπ’Ÿm , it holds that

Lπ’Ÿβ’(h^Z)βˆ’minhβˆˆβ„‹β‘Lπ’Ÿβ’(h)≀(bβˆ’a)⁒2m⁒log⁑|β„‹|+1Ξ΄.
Proof.

For any hypothesis h , we can allow it a “failure probability” of Ξ΄/(|β„‹|+1) in Hoeffding’s inequality:

PrZβˆΌπ’Ÿm⁑(Lπ’Ÿβ’(h)βˆ’LZ⁒(h)>(bβˆ’a)⁒12⁒m⁒log⁑|β„‹|+1Ξ΄)≀δ|β„‹|+1.

If we do this for each hypothesis hβˆˆβ„‹ , we know that the probability of each particular h being bad is low. We then want to combine them into the probability that anything is bad; we can do this with a union bound.

Lemma 2.3 (Union bound).
555This fact is really useful.

For any two events A and B , Pr⁑(AβˆͺB)≀Pr⁑(A)+Pr⁑(B) .

Combining all of them together, the probability that any h happens to look way better than it is can be bounded as

PrZβˆΌπ’Ÿm(βˆƒhβˆˆβ„‹.Lπ’Ÿ(h)βˆ’LZ(h)>(bβˆ’a)12⁒m⁒log⁑|β„‹|+1Ξ΄)≀|β„‹|Ξ΄|β„‹|+1.

But we’ll also need the other direction for (B): hβˆ—βˆˆarg⁒minhβˆˆβ„‹β‘Lπ’Ÿβ’(h) in particular doesn’t look way worse than it actually is. Giving it the same failure probability to make things nice,

PrZβˆΌπ’Ÿm⁑(LZ⁒(hβˆ—)βˆ’Lπ’Ÿβ’(hβˆ—)>(bβˆ’a)⁒12⁒m⁒log⁑|β„‹|+1Ξ΄)≀δ|β„‹|+1.

Now, if (⁒A⁒)≀ΡA and (⁒B⁒)≀ΡB , then (1.6) tells us that Lπ’Ÿβ’(h^Z)βˆ’Lπ’Ÿβ’(hβˆ—)≀(⁒A⁒)+(⁒B⁒)≀ΡA+Ξ΅B . Using another union bound,

PrZβˆΌπ’Ÿm⁑(Lπ’Ÿβ’(h^Z)βˆ’Lπ’Ÿβ’(hβˆ—)>(bβˆ’a)⁒12⁒m⁒log⁑|β„‹|+1Ξ΄+(bβˆ’a)⁒12⁒m⁒log⁑|β„‹|+1Ξ΄)=PrZβˆΌπ’Ÿm⁑(Lπ’Ÿβ’(h^Z)βˆ’Lπ’Ÿβ’(hβˆ—)>(bβˆ’a)⁒2m⁒log⁑|β„‹|+1Ξ΄)≀|β„‹||β„‹|+1⁒δ+1|β„‹|+1⁒δ=Ξ΄.∎

Another way to state proposition 2.2 is that with m samples, we can achieve estimation error at most Ξ΅ with probability at least 1βˆ’(|β„‹|+1)⁒exp⁑(βˆ’m⁒Ρ22⁒(bβˆ’a)2) .

Or, alternatively, we can say that we can achieve estimation error at most Ξ΅ with probability at least 1βˆ’Ξ΄ if we have at least 2⁒(bβˆ’a)2Ξ΅2⁒log⁑|β„‹|+1Ξ΄ samples.

2.3.1 Is this finiteness assumption reasonable?

Every β„‹ we use in practice is finite. Our models are represented on a computer with bounded memory, so we consider no more than 2max number of bits hypotheses.

On the other hand, |β„‹| might be really large. Typical vision CNNs are around a few hundred megabytes: 100 megabytes is 800,000,000 bits, and log⁑(|β„‹|+1)β‰ˆlog⁑2800,000,000=800,000,000⁒log⁑2β‰ˆ554,517,744 is quite big. For 0-1 loss, this would mean that for our bound to show that ERM learns a 100-MB network even to within an extremely loose Ξ΅=20% additive error with probability at least 1βˆ’Ξ΄=50% , we’d need

mβ‰₯20.22⁒(log⁑(|β„‹|+1)+log⁑10.5)β‰ˆ50⁒(554⁒ million+0.7)β‰ˆ28⁒ billion.

100 MB is a relatively small model these days (ViTs are usually a few gigabytes), and 28 billion is a lot of samples.

But the union bound we did over β„‹ ignores all structure in β„‹ . If we change just one parameter by 0.00001 , then we’re treating the error of that new hypothesis totally separately, when in reality those two errors are tightly correlated. We’ll approach that soon, with various techniques that will also allow us to handle infinitely large β„‹ ; but first, we’ll go back and prove Hoeffding’s inequality.