SDSC6001 Assignment 1: Covering-Number Generalization Bound

Problem: Prove a covering-number bound and verify it by simulation

Background (given)

Let H\mathcal{H} be a family of functions mapping X\mathcal{X} to Y⊆R\mathcal{Y} \subseteq \mathbb{R}. We consider the squared loss

ℓ(h(x),y)=(h(x)−y)2\ell(h(x), y) = (h(x) - y)^2

Let DD be an unknown distribution over X×Y\mathcal{X} \times \mathcal{Y}. For h∈Hh \in \mathcal{H}, define the true risk and empirical risk:

R(h)=E(x,y)∼D[(h(x)−y)2],R^S(h)=1m∑i=1m(h(xi)−yi)2R(h) = \mathbb{E}_{(x,y)\sim D}[(h(x) - y)^2], \quad \hat{R}_S(h) = \frac{1}{m}\sum_{i=1}^{m}(h(x_i) - y_i)^2

where S=((x1,y1),…,(xm,ym))∼DmS = ((x_1, y_1), \ldots, (x_m, y_m)) \sim D^m is an i.i.d. sample.

Assume H\mathcal{H} is bounded: there exists M>0M > 0 such that

∣h(x)−y∣≤Mfor all (x,y)∈X×Y and all h∈H|h(x) - y| \leq M \quad \text{for all } (x, y) \in \mathcal{X} \times \mathcal{Y} \text{ and all } h \in \mathcal{H}

Covering number (sup norm). For ε>0\varepsilon > 0, the covering number N(H,ε)\mathcal{N}(\mathcal{H}, \varepsilon) under ∥⋅∥∞\|\cdot\|_\infty is the smallest kk such that there exist h1,…,hk∈Hh_1, \ldots, h_k \in \mathcal{H} satisfying: for every h∈Hh \in \mathcal{H}, there exists i≤ki \leq k with

∥h−hi∥∞=sup⁡x∈X∣h(x)−hi(x)∣≤ε\|h - h_i\|_\infty = \sup_{x \in \mathcal{X}} |h(x) - h_i(x)| \leq \varepsilon

Similar to VC dimension, covering numbers provides a measurement of complexity of a class of functions: the larger the covering number, the richer is the family of functions. The objective of this problem is to illustrate this by proving a learning bound in the case of the squared loss.

Target bound (to prove)

Prove the following generalization bound:

PS∼Dm[sup⁡h∈H∣R(h)−R^S(h)∣≥ε]≤N(H,ε8M)⋅2exp⁡(−mε22M4)(⋆)\mathbb{P}_{S\sim D^m}\left[\sup_{h\in\mathcal{H}}|R(h) - \hat{R}_S(h)| \geq \varepsilon\right] \leq \mathcal{N}\left(\mathcal{H}, \frac{\varepsilon}{8M}\right) \cdot 2\exp\left(-\frac{m\varepsilon^2}{2M^4}\right) \quad (\star)


Part I: Proof

Let LS(h)=R(h)−R^S(h)L_S(h) = R(h) - \hat{R}_S(h).


Problem 1 (20%): Lipschitz step

Problem Statement: Show that for all h1,h2∈Hh_1, h_2 \in \mathcal{H} and any sample SS,

∣LS(h1)−LS(h2)∣≤4M∥h1−h2∥∞|L_S(h_1) - L_S(h_2)| \leq 4M \|h_1 - h_2\|_\infty

Hint: Use a2−b2=(a−b)(a+b)a^2 - b^2 = (a-b)(a+b) and boundedness by MM.


Proof:

First, we analyze the Lipschitz property of R(h)R(h) and R^S(h)\hat{R}_S(h) with respect to hh separately.

Step 1: Analyze ∣R(h1)−R(h2)∣|R(h_1) - R(h_2)|

R(h1)−R(h2)=E(x,y)∼D[(h1(x)−y)2−(h2(x)−y)2]R(h_1) - R(h_2) = \mathbb{E}_{(x,y)\sim D}[(h_1(x) - y)^2 - (h_2(x) - y)^2]

Using the identity a2−b2=(a−b)(a+b)a^2 - b^2 = (a-b)(a+b), let a=h1(x)−ya = h_1(x) - y and b=h2(x)−yb = h_2(x) - y:

(h1(x)−y)2−(h2(x)−y)2=(h1(x)−h2(x))((h1(x)−y)+(h2(x)−y))(h_1(x) - y)^2 - (h_2(x) - y)^2 = (h_1(x) - h_2(x))((h_1(x) - y) + (h_2(x) - y))

Therefore:

∣R(h1)−R(h2)∣=∣E(x,y)∼D[(h1(x)−h2(x))((h1(x)−y)+(h2(x)−y))]∣|R(h_1) - R(h_2)| = \left|\mathbb{E}_{(x,y)\sim D}[(h_1(x) - h_2(x))((h_1(x) - y) + (h_2(x) - y))]\right|

By the boundedness assumption ∣hi(x)−y∣≤M|h_i(x) - y| \leq M, we have:

  • ∣h1(x)−h2(x)∣≤∥h1−h2∥∞|h_1(x) - h_2(x)| \leq \|h_1 - h_2\|_\infty

  • ∣(h1(x)−y)+(h2(x)−y)∣≤∣h1(x)−y∣+∣h2(x)−y∣≤2M|(h_1(x) - y) + (h_2(x) - y)| \leq |h_1(x) - y| + |h_2(x) - y| \leq 2M

Therefore:

∣R(h1)−R(h2)∣≤E[∥h1−h2∥∞⋅2M]=2M∥h1−h2∥∞|R(h_1) - R(h_2)| \leq \mathbb{E}[\|h_1 - h_2\|_\infty \cdot 2M] = 2M\|h_1 - h_2\|_\infty

Step 2: Analyze ∣R^S(h1)−R^S(h2)∣|\hat{R}_S(h_1) - \hat{R}_S(h_2)|

R^S(h1)−R^S(h2)=1m∑i=1m[(h1(xi)−yi)2−(h2(xi)−yi)2]\hat{R}_S(h_1) - \hat{R}_S(h_2) = \frac{1}{m}\sum_{i=1}^{m}[(h_1(x_i) - y_i)^2 - (h_2(x_i) - y_i)^2]

Similarly using a2−b2=(a−b)(a+b)a^2 - b^2 = (a-b)(a+b):

=1m∑i=1m(h1(xi)−h2(xi))((h1(xi)−yi)+(h2(xi)−yi))= \frac{1}{m}\sum_{i=1}^{m}(h_1(x_i) - h_2(x_i))((h_1(x_i) - y_i) + (h_2(x_i) - y_i))

Taking absolute value:

∣R^S(h1)−R^S(h2)∣≤1m∑i=1m∣h1(xi)−h2(xi)∣⋅2M|\hat{R}_S(h_1) - \hat{R}_S(h_2)| \leq \frac{1}{m}\sum_{i=1}^{m}|h_1(x_i) - h_2(x_i)| \cdot 2M

≤1m∑i=1m∥h1−h2∥∞⋅2M=2M∥h1−h2∥∞\leq \frac{1}{m}\sum_{i=1}^{m}\|h_1 - h_2\|_\infty \cdot 2M = 2M\|h_1 - h_2\|_\infty

Step 3: Combine the results

∣LS(h1)−LS(h2)∣=∣R(h1)−R^S(h1)−R(h2)+R^S(h2)∣|L_S(h_1) - L_S(h_2)| = |R(h_1) - \hat{R}_S(h_1) - R(h_2) + \hat{R}_S(h_2)|

≤∣R(h1)−R(h2)∣+∣R^S(h1)−R^S(h2)∣\leq |R(h_1) - R(h_2)| + |\hat{R}_S(h_1) - \hat{R}_S(h_2)|

≤2M∥h1−h2∥∞+2M∥h1−h2∥∞=4M∥h1−h2∥∞\leq 2M\|h_1 - h_2\|_\infty + 2M\|h_1 - h_2\|_\infty = 4M\|h_1 - h_2\|_\infty


Problem 2 (15%): Union bound over a cover

Problem Statement: If H=⋃i=1kBi\mathcal{H} = \bigcup_{i=1}^{k} B_i, show that

P[sup⁡h∈H∣LS(h)∣≥ε]≤∑i=1kP[sup⁡h∈Bi∣LS(h)∣≥ε]\mathbb{P}\left[\sup_{h\in\mathcal{H}}|L_S(h)| \geq \varepsilon\right] \leq \sum_{i=1}^{k}\mathbb{P}\left[\sup_{h\in B_i}|L_S(h)| \geq \varepsilon\right]


Proof:

Define event A={sup⁡h∈H∣LS(h)∣≥ε}A = \{\sup_{h\in\mathcal{H}}|L_S(h)| \geq \varepsilon\} and Ai={sup⁡h∈Bi∣LS(h)∣≥ε}A_i = \{\sup_{h\in B_i}|L_S(h)| \geq \varepsilon\}.

Step 1: Show that A⊆⋃i=1kAiA \subseteq \bigcup_{i=1}^{k} A_i

Suppose event AA occurs, i.e., there exists h∗∈Hh^* \in \mathcal{H} such that ∣LS(h∗)∣≥ε|L_S(h^*)| \geq \varepsilon.

Since H=⋃i=1kBi\mathcal{H} = \bigcup_{i=1}^{k} B_i, there exists some j∈{1,…,k}j \in \{1, \ldots, k\} such that h∗∈Bjh^* \in B_j.

Therefore sup⁡h∈Bj∣LS(h)∣≥∣LS(h∗)∣≥ε\sup_{h\in B_j}|L_S(h)| \geq |L_S(h^*)| \geq \varepsilon, which means AjA_j occurs.

So A⊆⋃i=1kAiA \subseteq \bigcup_{i=1}^{k} A_i.

Step 2: Apply the union bound

By monotonicity of probability and the union bound:

P[A]≤P[⋃i=1kAi]≤∑i=1kP[Ai]\mathbb{P}[A] \leq \mathbb{P}\left[\bigcup_{i=1}^{k} A_i\right] \leq \sum_{i=1}^{k}\mathbb{P}[A_i]

That is:

P[sup⁡h∈H∣LS(h)∣≥ε]≤∑i=1kP[sup⁡h∈Bi∣LS(h)∣≥ε]\mathbb{P}\left[\sup_{h\in\mathcal{H}}|L_S(h)| \geq \varepsilon\right] \leq \sum_{i=1}^{k}\mathbb{P}\left[\sup_{h\in B_i}|L_S(h)| \geq \varepsilon\right]


Problem 3 (25%): From cover to finite set + concentration

Problem Statement: Let k=N(H,ε/(8M))k = \mathcal{N}(\mathcal{H}, \varepsilon/(8M)), and let h1,…,hkh_1, \ldots, h_k be centers of ∥⋅∥∞\|\cdot\|_\infty balls of radius ε/(8M)\varepsilon/(8M) that cover H\mathcal{H}. Use the Lipschitz step to prove that for each ii,

P[sup⁡h∈B∞(hi,ε/(8M))∣LS(h)∣≥ε]≤P[∣LS(hi)∣≥ε2]\mathbb{P}\left[\sup_{h\in B_\infty(h_i, \varepsilon/(8M))}|L_S(h)| \geq \varepsilon\right] \leq \mathbb{P}\left[|L_S(h_i)| \geq \frac{\varepsilon}{2}\right]

Then apply a concentration inequality (e.g. Hoeffding) to bound P(∣LS(hi)∣≥ε/2)\mathbb{P}(|L_S(h_i)| \geq \varepsilon/2) and conclude (⋆)(\star).

Important: Clearly define the random variables you apply Hoeffding to, and justify the bounded range needed for the inequality.


Proof:

Step 1: Use Lipschitz property

Let h∈B∞(hi,ε/(8M))h \in B_\infty(h_i, \varepsilon/(8M)), i.e., ∥h−hi∥∞≤ε/(8M)\|h - h_i\|_\infty \leq \varepsilon/(8M).

By the Lipschitz result from Problem 1:

∣LS(h)−LS(hi)∣≤4M∥h−hi∥∞≤4M⋅ε8M=ε2|L_S(h) - L_S(h_i)| \leq 4M\|h - h_i\|_\infty \leq 4M \cdot \frac{\varepsilon}{8M} = \frac{\varepsilon}{2}

Step 2: Upper bound transformation

For any h∈B∞(hi,ε/(8M))h \in B_\infty(h_i, \varepsilon/(8M)):

∣LS(h)∣≤∣LS(hi)∣+∣LS(h)−LS(hi)∣≤∣LS(hi)∣+ε2|L_S(h)| \leq |L_S(h_i)| + |L_S(h) - L_S(h_i)| \leq |L_S(h_i)| + \frac{\varepsilon}{2}

Therefore:

sup⁡h∈B∞(hi,ε/(8M))∣LS(h)∣≤∣LS(hi)∣+ε2\sup_{h\in B_\infty(h_i, \varepsilon/(8M))}|L_S(h)| \leq |L_S(h_i)| + \frac{\varepsilon}{2}

Step 3: Probability bound

If sup⁡h∈B∞(hi,ε/(8M))∣LS(h)∣≥ε\sup_{h\in B_\infty(h_i, \varepsilon/(8M))}|L_S(h)| \geq \varepsilon, then:

∣LS(hi)∣+ε2≥ε  ⟹  ∣LS(hi)∣≥ε2|L_S(h_i)| + \frac{\varepsilon}{2} \geq \varepsilon \implies |L_S(h_i)| \geq \frac{\varepsilon}{2}

Therefore:

P[sup⁡h∈B∞(hi,ε/(8M))∣LS(h)∣≥ε]≤P[∣LS(hi)∣≥ε2]\mathbb{P}\left[\sup_{h\in B_\infty(h_i, \varepsilon/(8M))}|L_S(h)| \geq \varepsilon\right] \leq \mathbb{P}\left[|L_S(h_i)| \geq \frac{\varepsilon}{2}\right]

Step 4: Apply Hoeffding’s inequality

Define random variables:

Zj=(hi(xj)−yj)2−E[(hi(x)−y)2],j=1,…,mZ_j = (h_i(x_j) - y_j)^2 - \mathbb{E}[(h_i(x) - y)^2], \quad j = 1, \ldots, m

Then Z1,…,ZmZ_1, \ldots, Z_m are i.i.d. random variables with E[Zj]=0\mathbb{E}[Z_j] = 0.

Note that:

LS(hi)=R(hi)−R^S(hi)=E[(hi(x)−y)2]−1m∑j=1m(hi(xj)−yj)2=−1m∑j=1mZjL_S(h_i) = R(h_i) - \hat{R}_S(h_i) = \mathbb{E}[(h_i(x) - y)^2] - \frac{1}{m}\sum_{j=1}^{m}(h_i(x_j) - y_j)^2 = -\frac{1}{m}\sum_{j=1}^{m}Z_j

Determine the bounded range of ZjZ_j:

Since ∣hi(x)−y∣≤M|h_i(x) - y| \leq M, we have:

0≤(hi(x)−y)2≤M20 \leq (h_i(x) - y)^2 \leq M^2

Therefore (hi(xj)−yj)2∈[0,M2](h_i(x_j) - y_j)^2 \in [0, M^2], and E[(hi(x)−y)2]∈[0,M2]\mathbb{E}[(h_i(x) - y)^2] \in [0, M^2].

So:

Zj∈[−M2,M2]Z_j \in [-M^2, M^2]

The range of ZjZ_j is 2M22M^2.

Apply Hoeffding’s inequality:

For bounded independent random variables Z1,…,ZmZ_1, \ldots, Z_m where Zj∈[aj,bj]Z_j \in [a_j, b_j], Hoeffding’s inequality gives:

P[∣1m∑j=1mZj∣≥t]≤2exp⁡(−2m2t2∑j=1m(bj−aj)2)\mathbb{P}\left[\left|\frac{1}{m}\sum_{j=1}^{m}Z_j\right| \geq t\right] \leq 2\exp\left(-\frac{2m^2t^2}{\sum_{j=1}^{m}(b_j - a_j)^2}\right)

In our case, bj−aj=2M2b_j - a_j = 2M^2, so:

P[∣LS(hi)∣≥ε2]=P[∣1m∑j=1mZj∣≥ε2]\mathbb{P}\left[|L_S(h_i)| \geq \frac{\varepsilon}{2}\right] = \mathbb{P}\left[\left|\frac{1}{m}\sum_{j=1}^{m}Z_j\right| \geq \frac{\varepsilon}{2}\right]

≤2exp⁡(−2m2(ε/2)2m(2M2)2)=2exp⁡(−2m2⋅ε2/4m⋅4M4)=2exp⁡(−mε28M4)\leq 2\exp\left(-\frac{2m^2(\varepsilon/2)^2}{m(2M^2)^2}\right) = 2\exp\left(-\frac{2m^2 \cdot \varepsilon^2/4}{m \cdot 4M^4}\right) = 2\exp\left(-\frac{m\varepsilon^2}{8M^4}\right)

We obtain:

P[∣LS(hi)∣≥ε2]≤2exp⁡(−mε22M4)\mathbb{P}\left[|L_S(h_i)| \geq \frac{\varepsilon}{2}\right] \leq 2\exp\left(-\frac{m\varepsilon^2}{2M^4}\right)

Step 5: Combine to obtain the final bound

By the union bound from Problem 2, with Bi=B∞(hi,ε/(8M))B_i = B_\infty(h_i, \varepsilon/(8M)) covering H\mathcal{H}:

P[sup⁡h∈H∣LS(h)∣≥ε]≤∑i=1kP[sup⁡h∈Bi∣LS(h)∣≥ε]\mathbb{P}\left[\sup_{h\in\mathcal{H}}|L_S(h)| \geq \varepsilon\right] \leq \sum_{i=1}^{k}\mathbb{P}\left[\sup_{h\in B_i}|L_S(h)| \geq \varepsilon\right]

≤∑i=1kP[∣LS(hi)∣≥ε2]≤k⋅2exp⁡(−mε22M4)\leq \sum_{i=1}^{k}\mathbb{P}\left[|L_S(h_i)| \geq \frac{\varepsilon}{2}\right] \leq k \cdot 2\exp\left(-\frac{m\varepsilon^2}{2M^4}\right)

=N(H,ε8M)⋅2exp⁡(−mε22M4)= \mathcal{N}\left(\mathcal{H}, \frac{\varepsilon}{8M}\right) \cdot 2\exp\left(-\frac{m\varepsilon^2}{2M^4}\right)


Part II: Simulation verification (40%, open design)

In this part, you will design your own simulation to empirically estimate the LHS probability in (⋆)(\star) and compare it with the RHS bound.

Experimental Setup

Hypothesis Class: Clipped Linear Functions

Domain and Range:

  • X=[0,1]\mathcal{X} = [0, 1]

  • Y=[−1,1]\mathcal{Y} = [-1, 1]

Hypothesis Class: Clipped linear functions

H={hw:w∈[−1,1]},hw(x)=clip(wx,−1,1)\mathcal{H} = \{h_w : w \in [-1, 1]\}, \quad h_w(x) = \text{clip}(wx, -1, 1)

where clip(z,−1,1)=max⁡(−1,min⁡(1,z))\text{clip}(z, -1, 1) = \max(-1, \min(1, z)).

Data Distribution DD:

  • x∼Uniform(0,1)x \sim \text{Uniform}(0, 1)

  • y=clip(0.5x+η,−1,1)y = \text{clip}(0.5x + \eta, -1, 1), where η∼N(0,0.12)\eta \sim \mathcal{N}(0, 0.1^2)

Boundedness Constant MM

For x∈[0,1]x \in [0, 1] and w∈[−1,1]w \in [-1, 1]:

  • hw(x)∈[−1,1]h_w(x) \in [-1, 1]

  • y∈[−1,1]y \in [-1, 1]

Therefore:

∣hw(x)−y∣≤∣hw(x)∣+∣y∣≤1+1=2|h_w(x) - y| \leq |h_w(x)| + |y| \leq 1 + 1 = 2

We set M=2M = 2.

Covering Number Calculation

For w1,w2∈[−1,1]w_1, w_2 \in [-1, 1], consider ∥hw1−hw2∥∞\|h_{w_1} - h_{w_2}\|_\infty.

In the non-clipping region, for x∈[0,1]x \in [0, 1]:

∣hw1(x)−hw2(x)∣=∣w1x−w2x∣=∣w1−w2∣⋅x≤∣w1−w2∣|h_{w_1}(x) - h_{w_2}(x)| = |w_1 x - w_2 x| = |w_1 - w_2| \cdot x \leq |w_1 - w_2|

The maximum is achieved at x=1x = 1 (when no clipping occurs):

∥hw1−hw2∥∞≤∣w1−w2∣\|h_{w_1} - h_{w_2}\|_\infty \leq |w_1 - w_2|

To ensure ∥hw1−hw2∥∞≤r\|h_{w_1} - h_{w_2}\|_\infty \leq r, we need ∣w1−w2∣≤r|w_1 - w_2| \leq r.

Therefore, covering [−1,1][-1, 1] with a grid of spacing rr requires:

N(H,r)≤⌈2r⌉+1\mathcal{N}(\mathcal{H}, r) \leq \left\lceil \frac{2}{r} \right\rceil + 1

For r=ε/(8M)=ε/16r = \varepsilon/(8M) = \varepsilon/16:

N(H,ε16)≤⌈32ε⌉+1\mathcal{N}\left(\mathcal{H}, \frac{\varepsilon}{16}\right) \leq \left\lceil \frac{32}{\varepsilon} \right\rceil + 1

Experimental Parameters

Parameter Value
Sample size grid mm [50, 100, 200, 500, 1000, 2000, 5000]
Error grid ε\varepsilon [0.1, 0.2, 0.3, 0.5]
Monte Carlo trials TT 1000
Test set size (for true risk estimation) 50000
Hypothesis class discretization 201 uniformly spaced ww values in [−1,1][-1, 1]
Random seed 42
Python version 3.9+

True Risk Estimation

We approximate R(h)R(h) using a large independent test set (50,000 samples):

R(h)≈1ntest∑i=1ntest(h(xitest)−yitest)2R(h) \approx \frac{1}{n_{test}}\sum_{i=1}^{n_{test}}(h(x_i^{test}) - y_i^{test})^2

A test set of 50,000 samples is sufficiently large to control the estimation error.

Experimental Results

After running the code, we obtain the following results (see simulation.py for details):

Results Table

Comparison of empirical probability p^(m,ε)\hat{p}(m, \varepsilon) and theoretical bound RHS for different (m,ε)(m, \varepsilon) combinations:

mm ε\varepsilon p^(m,ε)\hat{p}(m,\varepsilon) RHS (Theoretical Bound) RHS > 1?
50 0.10 0.3070 6.32e+02 Yes
100 0.10 0.1590 6.22e+02 Yes
200 0.10 0.0320 6.03e+02 Yes
500 0.10 0.0000 5.49e+02 Yes
1000 0.10 0.0000 4.70e+02 Yes
50 0.20 0.0490 3.02e+02 Yes
100 0.20 0.0050 2.84e+02 Yes
5000 0.20 0.0000 0.6216 No
50 0.30 0.0030 1.88e+02 Yes
2000 0.30 0.0000 0.7790 No
5000 0.30 0.0000 0.0002 No
1000 0.50 0.0000 0.0526 No

Covering Numbers:

  • ε=0.1\varepsilon = 0.1: N(H,0.0063)=321\mathcal{N}(\mathcal{H}, 0.0063) = 321

  • ε=0.2\varepsilon = 0.2: N(H,0.0125)=161\mathcal{N}(\mathcal{H}, 0.0125) = 161

  • ε=0.3\varepsilon = 0.3: N(H,0.0187)=108\mathcal{N}(\mathcal{H}, 0.0187) = 108

  • ε=0.5\varepsilon = 0.5: N(H,0.0312)=65\mathcal{N}(\mathcal{H}, 0.0312) = 65

SDSC6001_comparison_plot

covering_analysis