Simple Algorithm
Machine Learning · Convergence · 30 min

VC Dimension & the Fundamental Theorem

Shattering, Sauer’s lemma and the characterization of learnability.

Finite VC dimension is the exact dividing line between classes that finitely many examples can teach and classes they cannot. This lesson proves the hard direction: a counting lemma that turns 2n2^n into a polynomial, a ghost sample that stands in for the unknown distribution, lower bounds showing the resulting rates cannot be beaten, and what all of it says, and fails to say, about neural networks.

What you’ll learn

  • Prove the Sauer–Shelah lemma ΠH(n)≤∑i≤d(ni)≤(en/d)d\Pi_{\mathcal H}(n)\le\sum_{i\le d}\binom ni\le(en/d)^d by induction, and explain why growth functions are either 2n2^n or polynomial.
  • Prove uniform convergence for classes of finite VC dimension by ghost-sample symmetrization and random swaps, with explicit constants.
  • State the realizable and agnostic lower bounds and describe the distributions that force them.
  • Apply the VC-dimension bounds for piecewise-linear networks, and explain why class-level bounds are vacuous for modern networks.

Counting labelings: the Sauer–Shelah lemma

Throughout, H\mathcal H is a class of binary classifiers with the 0–1 loss, and nn is the sample size. The growth function ΠH(n)=max⁡∣C∣=n∣HC∣\Pi_{\mathcal H}(n)=\max_{\abs C=n}\abs{\mathcal H_C} is at most 2n2^n, with equality exactly when some nn-point set is shattered; so ΠH(n)=2n\Pi_{\mathcal H}(n)=2^n for n≤d=VCdim⁡(H)n\le d=\operatorname{VCdim}(\mathcal H). Write Φd(n)=∑i=0d(ni)\Phi_d(n)=\sum_{i=0}^d\binom ni for the number of subsets of an nn-set with at most dd elements.

DerivationProof by induction on n + d
  1. ∣HC∣≤Φd(n)=∑i=0d(ni)\abs{\mathcal H_C}\le\Phi_d(n)=\sum_{i=0}^d\binom ni

    Base cases. If d=0d=0, no point receives both labels, so all hypotheses agree on every point and a sample admits a single labeling. If n=1n=1 and d≥1d\ge1, there are at most two labelings, and Φd(1)=2\Phi_d(1)=2.

  2. ∣G∣=∣G1∣+∣G2∣\abs G=\abs{G_1}+\abs{G_2}

    Inductive step. Fix C={x1,…,xn}C=\{\mathbf x_1,\dots,\mathbf x_n\}, let G=HCG=\mathcal H_C and C′=C∖{xn}C'=C\setminus\{\mathbf x_n\}. Let G1G_1 be the set of label vectors on C′C' obtained by deleting the last coordinate from vectors in GG, and G2⊆G1G_2\subseteq G_1 the vectors on C′C' that occur in GG followed by a 0 and followed by a 1. Counting GG by its restrictions to C′C', each vector of G1G_1 accounts for one or two members of GG, so

  3. ∣G1∣≤Φd(n−1),∣G2∣≤Φd−1(n−1)\abs{G_1}\le\Phi_d(n-1),\qquad\abs{G_2}\le\Phi_{d-1}(n-1)

    G1=HC′G_1=\mathcal H_{C'} lives on n−1n-1 points with VC dimension at most dd. If G2G_2 shatters some Z⊆C′Z\subseteq C', the paired extensions supply both labels of xn\mathbf x_n, so GG shatters Z∪{xn}Z\cup\{\mathbf x_n\}; hence G2G_2 has VC dimension at most d−1d-1. The induction hypothesis applies to both:

  4. ∣G∣≤∑i=0d(n−1i)+∑i=0d(n−1i−1)=∑i=0d(ni)=Φd(n)\abs G\le\sum_{i=0}^d\binom{n-1}i+\sum_{i=0}^{d}\binom{n-1}{i-1}=\sum_{i=0}^d\binom ni=\Phi_d(n)

    Pascal's rule (n−1i)+(n−1i−1)=(ni)\binom{n-1}i+\binom{n-1}{i-1}=\binom ni (with (n−1−1)=0\binom{n-1}{-1}=0) closes the induction:

  5. Φd(n)≤(nd)d∑i=0d(ni)(dn)i≤(nd)d(1+dn)n≤(end)d\Phi_d(n)\le\Big(\frac nd\Big)^d\sum_{i=0}^d\binom ni\Big(\frac dn\Big)^i\le\Big(\frac nd\Big)^d\Big(1+\frac dn\Big)^n\le\Big(\frac{en}d\Big)^d

    Closed form. For n≥dn\ge d, multiply each term by (n/d)d−i≥1(n/d)^{d-i}\ge1, extend the sum to all ii, and use the binomial theorem and 1+x≤ex1+x\le e^x:

Predict before you look

Axis-aligned rectangles in the plane have VC dimension 4. Twenty points admit 220≈1.052^{20}\approx1.05 million labelings; what is the most that rectangles could produce, according to the Sauer–Shelah lemma?

Show the answer

6196 labelings

(200)+(201)+(202)+(203)+(204)=1+20+190+1140+4845=6,196\binom{20}0+\binom{20}1+\binom{20}2+\binom{20}3+\binom{20}4=1+20+190+1140+4845=6{,}196, about 0.6% of all labelings. The cruder (en/d)d=(5e)4≈34,100(en/d)^d=(5e)^4\approx34{,}100 is also polynomial.

Uniform convergence by a ghost sample

The difficulty is a supremum over an infinite class of deviations from an unknown distribution. Two tricks remove both obstacles. First, compare the training sample SS with an independent ghost sample S′S' of the same size, instead of with PP. Second, randomly swap the ii-th points of the two samples, which does not change their joint law. After conditioning on the 2n2n points, only finitely many labelings remain. This is symmetrization, the argument of Vapnik and Chervonenkis.

DerivationProof
  1. Pr⁡[sup⁡h(R(h)−R^S(h))>ε]≤2Pr⁡[sup⁡h(R^S′(h)−R^S(h))>ε2]\Pr\Big[\sup_h\big(R(h)-\hat R_S(h)\big)>\varepsilon\Big]\le2\Pr\Big[\sup_h\big(\hat R_{S'}(h)-\hat R_S(h)\big)>\frac\varepsilon2\Big]

    Ghost sample. Suppose sup⁡h(R(h)−R^S(h))>ε\sup_h(R(h)-\hat R_S(h))>\varepsilon, attained (up to an arbitrarily small slack) by some h^\hat h that depends on SS only. Given SS, R^S′(h^)\hat R_{S'}(\hat h) averages nn fresh Bernoulli variables with variance at most 1/41/4, so Chebyshev gives Pr⁡[R(h^)−R^S′(h^)≥ε/2∣S]≤1/(nε2)≤1/2\Pr[R(\hat h)-\hat R_{S'}(\hat h)\ge\varepsilon/2\mid S]\le1/(n\varepsilon^2)\le1/2. With conditional probability at least 1/21/2, therefore, R^S′(h^)−R^S(h^)>ε/2\hat R_{S'}(\hat h)-\hat R_S(\hat h)>\varepsilon/2:

  2. Pr⁡[sup⁡h1n∑i=1n(ℓh(zi′)−ℓh(zi))>ε2]=ES,S′ Pr⁡σ[sup⁡h1n∑i=1nσi(ℓh(zi′)−ℓh(zi))>ε2]\Pr\Big[\sup_h\frac1n\sum_{i=1}^n\big(\ell_h(z_i')-\ell_h(z_i)\big)>\frac\varepsilon2\Big]=\E_{S,S'}\,\Pr_{\boldsymbol\sigma}\Big[\sup_h\frac1n\sum_{i=1}^n\sigma_i\big(\ell_h(z_i')-\ell_h(z_i)\big)>\frac\varepsilon2\Big]

    Random swaps. Write ℓh(z)=1{h(x)≠y}\ell_h(z)=\mathbf 1\{h(\mathbf x)\ne y\}. Exchanging ziz_i with zi′z_i' leaves the joint law of (S,S′)(S,S') unchanged, so independent uniform signs σi∈{±1}\sigma_i\in\{\pm1\} can be inserted for free:

  3. Pr⁡σ[∑i=1nσiai>nε2]≤exp⁡(−2(nε/2)24n)=e−nε2/8\Pr_{\boldsymbol\sigma}\Big[\sum_{i=1}^n\sigma_ia_i>\frac{n\varepsilon}2\Big]\le\exp\Big(-\frac{2(n\varepsilon/2)^2}{4n}\Big)=e^{-n\varepsilon^2/8}

    Finitely many patterns. Given the 2n2n points, hh matters only through its labels on them: at most ΠH(2n)\Pi_{\mathcal H}(2n) loss vectors. For each one, ai=ℓh(zi′)−ℓh(zi)∈{−1,0,1}a_i=\ell_h(z_i')-\ell_h(z_i)\in\{-1,0,1\}, and Hoeffding's inequality over the signs (each term ranges over an interval of length 2∣ai∣≤22\abs{a_i}\le2) gives

  4. Pr⁡[sup⁡h(R(h)−R^n(h))>ε]≤2 ΠH(2n) e−nε2/8\Pr\Big[\sup_h\big(R(h)-\hat R_n(h)\big)>\varepsilon\Big]\le2\,\Pi_{\mathcal H}(2n)\,e^{-n\varepsilon^2/8}

    Combine. A union bound over the patterns and the factor 2 from the first step give the theorem. Setting the right side to δ\delta gives nε2=8ln⁡(2ΠH(2n)/δ)≥8ln⁡2>2n\varepsilon^2=8\ln(2\Pi_{\mathcal H}(2n)/\delta)\ge8\ln2>2, so the condition of the first step holds automatically; Sauer–Shelah supplies ln⁡ΠH(2n)≤dln⁡(2en/d)\ln\Pi_{\mathcal H}(2n)\le d\ln(2en/d).

Think first The Descent lesson quoted 2dln⁡(en/d)/n+ln⁡(1/δ)/(2n)\sqrt{2d\ln(en/d)/n}+\sqrt{\ln(1/\delta)/(2n)}, while this proof gives 8(dln⁡(2en/d)+ln⁡(2/δ))/n\sqrt{8(d\ln(2en/d)+\ln(2/\delta))/n}, roughly twice as large. Which is right?

Both. They come from different proofs: the one above loses a factor 2 to Chebyshev and halves ε\varepsilon in the symmetrization, which costs a factor 4 under the square root; the Rademacher route concentrates the supremum with McDiarmid's inequality and bounds its mean with Massart's lemma (Rademacher Complexity). Neither set of constants is sharp. What is robust is the rate dlog⁡(n/d)/n\sqrt{d\log(n/d)/n}, and even its logarithm is an artifact: chaining removes it.

Removing the logarithm. Chaining, through Dudley's entropy integral, combined with the covering-number bound N(H,L2(μ),ε)≤(2/ε)CdN(\mathcal H,L_2(\mu),\varepsilon)\le(2/\varepsilon)^{Cd} for a class of VC dimension dd, gives Esup⁡h∣R(h)−R^n(h)∣≤Cd/n\E\sup_h\abs{R(h)-\hat R_n(h)}\le C\sqrt{d/n} for an absolute constant CC (Vershynin 2018, Theorems 8.3.18 and 8.3.23; the loss class 1{h(x)≠y}\mathbf 1\{h(\mathbf x)\ne y\} has the same growth function as H\mathcal H). With a concentration step (McDiarmid) this yields the agnostic upper bound O((d+ln⁡(1/δ))/ε2)\order{(d+\ln(1/\delta))/\varepsilon^2} of the fundamental theorem. Shalev-Shwartz & Ben-David (2014, §28.1) prove only the slightly weaker O((dln⁡(d/ε)+ln⁡(1/δ))/ε2)\order{(d\ln(d/\varepsilon)+\ln(1/\delta))/\varepsilon^2}, by the route of this lesson, and leave the chaining argument out.

Check your understanding

Which step of the proof turns a supremum over an infinite class into a finite union bound?

  1. Chebyshev's inequality on the ghost sample
  2. Conditioning on the 2n2n points of S∪S′S\cup S', on which H\mathcal H realizes at most ΠH(2n)\Pi_{\mathcal H}(2n) labelings
  3. Hoeffding's inequality over the random signs
  4. Taking expectations over the training sample
Show the answer

B. Conditioning on the 2n2n points of S∪S′S\cup S', on which H\mathcal H realizes at most ΠH(2n)\Pi_{\mathcal H}(2n) labelings

Once the 2n2n points are fixed, two hypotheses with the same labels on them have identical losses, so the supremum is a maximum over at most ΠH(2n)\Pi_{\mathcal H}(2n) patterns. Before symmetrization, the deviation R(h)−R^n(h)R(h)-\hat R_n(h) depends on hh everywhere on X\mathcal X, through R(h)R(h).

Lower bounds: the rates cannot be beaten

DerivationWhy d/ε examples are needed (sketch of the realizable construction)
  1. D(x0)=1−8ε,D(xj)=8εd−1(j=1,…,d−1)D(\mathbf x_0)=1-8\varepsilon,\qquad D(\mathbf x_j)=\frac{8\varepsilon}{d-1}\quad(j=1,\dots,d-1)

    Take a shattered set {x0,…,xd−1}\{\mathbf x_0,\dots,\mathbf x_{d-1}\}. Put mass 1−8ε1-8\varepsilon on x0\mathbf x_0 and spread 8ε8\varepsilon evenly over the d−1d-1 rare points. Draw the target uniformly among the 2d−12^{d-1} labelings of the rare points; all are realized by H\mathcal H because the set is shattered.

  2. E[#rare points seen]≤8εn=d−14\E\big[\#\text{rare points seen}\big]\le8\varepsilon n=\frac{d-1}4

    With n=(d−1)/(32ε)n=(d-1)/(32\varepsilon) examples, the expected number of draws that land on rare points is 8εn=(d−1)/48\varepsilon n=(d-1)/4, so in expectation at least three quarters of the rare points are never seen.

  3. E[R(hS)]≥12⋅6ε=3ε\E\big[R(h_S)\big]\ge\frac12\cdot6\varepsilon=3\varepsilon

    On an unseen point the target's label is a fair coin independent of the sample, so any learner errs there with probability 1/21/2. The unseen points carry mass at least 34⋅8ε=6ε\tfrac34\cdot8\varepsilon=6\varepsilon:

  4. An expected error of 3ε3\varepsilon against a random target forces some fixed target in H\mathcal H to cause error above ε\varepsilon with constant probability (the probabilistic method); the careful accounting gives the constants (d−1)/(32n)(d-1)/(32n) and 1/1001/100.

The agnostic construction uses noise instead of unseen points. Each of dd shattered points carries mass 1/d1/d and a label that is a coin of bias (1±α)/2(1\pm\alpha)/2, the sign chosen at random. The best hypothesis predicts each point's majority label, and every wrong guess costs α/d\alpha/d of excess risk. Telling a coin of bias (1+α)/2(1+\alpha)/2 from one of bias (1−α)/2(1-\alpha)/2 takes about 1/α21/\alpha^2 flips, but each point receives only about n/dn/d; with α≈d/n\alpha\approx\sqrt{d/n} a constant fraction of the guesses is wrong, for excess risk of order d/n\sqrt{d/n}.

Check your understanding

In the realizable construction, why can no learner, however clever, predict the labels of the unseen rare points?

  1. Because the learner is restricted to empirical risk minimization
  2. Because the labels of the rare points are noisy
  3. Because the set is shattered: every labeling of the unseen points is consistent with the sample and realized by some hypothesis in H\mathcal H, so the sample says nothing about them
  4. Because the rare points lie far from x0\mathbf x_0
Show the answer

C. Because the set is shattered: every labeling of the unseen points is consistent with the sample and realized by some hypothesis in H\mathcal H, so the sample says nothing about them

Shattering means the labels on unseen points are unconstrained by the labels on seen ones. With the target drawn at random, those labels are independent fair coins given the sample, and every learner is reduced to guessing. This is the no-free-lunch argument run inside a single class.

The VC dimension of neural networks

Depth matters, and how much depends on the activation: the dependence on depth is absent for piecewise-constant activations (threshold units), linear for piecewise-linear ones, and at most quadratic for piecewise-polynomial ones (Bartlett et al., 2019). Roughly, every weight can store about log⁡W\log W bits, and depth lets later layers extract them, the "bit extraction" idea behind the lower-bound construction.

Think first Dziugaite & Roy (2017) trained fully connected networks with 0.3 to 2.4 million parameters on 55,000 MNIST images relabeled into two classes, reaching test errors below 2%. Their table lists best-known VC upper bounds of 26 to 187 million for these architectures. What can a VC bound say about these networks?

Nothing useful. A VC bound needs an upper bound on dd, and the best available ones exceed n=55,000n=55{,}000 by a factor of hundreds or more: the polynomial regime of Sauer–Shelah never starts, ln⁡ΠH(n)\ln\Pi_{\mathcal H}(n) may be as large as nln⁡2n\ln2, and every resulting bound exceeds 1. Nor is this a failure of loose constants alone: Zhang, Bengio, Hardt, Recht & Vinyals (2017) showed that standard networks fit randomly relabeled training sets, so whatever certifies generalization on real labels must look beyond the class, at the data and the trained weights. Dziugaite & Roy's own bound, computed with PAC-Bayes, was nonvacuous (Stability, Compression & PAC-Bayes).

Key takeaways

  • Sauer–Shelah: ΠH(n)≤∑i≤d(ni)≤(en/d)d\Pi_{\mathcal H}(n)\le\sum_{i\le d}\binom ni\le(en/d)^d, so growth functions are either 2n2^n or polynomial, and the bound is attained.
  • Symmetrization with a ghost sample and random swaps gives Pr⁡[sup⁡h(R(h)−R^n(h))>ε]≤2ΠH(2n)e−nε2/8\Pr[\sup_h(R(h)-\hat R_n(h))>\varepsilon]\le2\Pi_{\mathcal H}(2n)e^{-n\varepsilon^2/8} for nε2≥2n\varepsilon^2\ge2, hence a gap of order dln⁡(n/d)/n\sqrt{d\ln(n/d)/n}; chaining removes the logarithm.
  • Lower bounds match: any learner can be forced to error above (d−1)/(32n)(d-1)/(32n) in the realizable case and excess risk above d/(320n)\sqrt{d/(320n)} in the agnostic case, so the rates d/εd/\varepsilon and d/ε2d/\varepsilon^2 are tight up to constants.
  • ReLU networks with WW weights and LL layers have VC dimension O(WLlog⁡W)\order{WL\log W}, and some reach Ω(WLlog⁡(W/L))\Omega(WL\log(W/L)); for modern networks d≫nd\gg n, and class-level bounds say nothing.

Check yourself

In the interactive lesson these are scored with your confidence, and what you miss comes back for review.

Question 1

Thresholds x↦1{x≥a}x\mapsto\mathbf 1\{x\ge a\} on the line have VC dimension 1. How many labelings can they produce on nn distinct points, compared with the Sauer–Shelah bound Φ1(n)\Phi_1(n)?

  1. 2n2^n, far above the bound
  2. nn, one below the bound
  3. n+1n+1, exactly the bound Φ1(n)=1+n\Phi_1(n)=1+n
  4. 2n2n, twice the bound
Show the answer

C. n+1n+1, exactly the bound Φ1(n)=1+n\Phi_1(n)=1+n

Sort the points: a threshold labels a suffix with 1, and the suffix can start before the first point, between any two neighbors, or after the last one, which gives n+1n+1 labelings. That equals (n0)+(n1)=Φ1(n)\binom n0+\binom n1=\Phi_1(n), so the Sauer–Shelah bound is attained and cannot be improved in general.

Question 2

Which of these cannot be the growth function of any class of binary classifiers?

  1. Π(n)=2n\Pi(n)=2^n for all nn
  2. Π(n)=n+1\Pi(n)=n+1
  3. Π(n)=2⌈n ⌉\Pi(n)=2^{\lceil\sqrt n\,\rceil}
  4. Π(n)=1+n+(n2)\Pi(n)=1+n+\binom n2
Show the answer

C. Π(n)=2⌈n ⌉\Pi(n)=2^{\lceil\sqrt n\,\rceil}

2⌈n⌉2^{\lceil\sqrt n\rceil} equals 2n2^n for n=1,2n=1,2 but not n=3n=3, so the VC dimension would be 2, and Sauer–Shelah would cap growth at 1+n+(n2)=O(n2)1+n+\binom n2=\order{n^2}; yet 2⌈n⌉2^{\lceil\sqrt n\rceil} eventually exceeds every polynomial. The other three are realized by a class of infinite VC dimension, by thresholds, and by intervals.

Question 3

What does the ghost sample S′S' accomplish in the proof of the VC inequality?

  1. It replaces the unknown risk R(h)R(h) by an empirical average on independent data, so the deviation depends only on 2n2n observed points
  2. It doubles the training set, which halves the error
  3. It provides a validation set for choosing the hypothesis
  4. It removes the need for a union bound
Show the answer

A. It replaces the unknown risk R(h)R(h) by an empirical average on independent data, so the deviation depends only on 2n2n observed points

R(h)R(h) depends on the whole distribution, so the supremum over hh cannot be reduced to finitely many cases. After symmetrization everything depends on S∪S′S\cup S', and H\mathcal H restricted to those 2n2n points has at most ΠH(2n)\Pi_{\mathcal H}(2n) behaviors.

Question 4

Two ReLU architectures have the same number WW of weights; one has 2 layers and the other 20. What do the Bartlett–Harvey–Liaw–Mehrabian results say about their VC dimensions?

  1. They are equal, because VC dimension depends only on the number of weights
  2. The deeper one can be larger, by up to a factor of about the depth: the upper bound grows like WLlog⁡WWL\log W, and constructions reach WLlog⁡(W/L)WL\log(W/L) up to a constant
  3. The deeper one is smaller, because each layer has fewer weights
  4. Both are infinite, because ReLU networks are universal approximators
Show the answer

B. The deeper one can be larger, by up to a factor of about the depth: the upper bound grows like WLlog⁡WWL\log W, and constructions reach WLlog⁡(W/L)WL\log(W/L) up to a constant

For piecewise-linear activations the VC dimension can grow linearly with depth at a fixed number of weights, and the lower-bound construction shows this growth really happens. For threshold units, by contrast, depth does not enter.

Further reading

  • V. N. Vapnik & A. Ya. Chervonenkis, "On the uniform convergence of relative frequencies of events to their probabilities," Theory of Probability and Its Applications 16(2), 264–280 (1971).
  • N. Sauer, "On the density of families of sets," Journal of Combinatorial Theory, Series A 13(1), 145–147 (1972).
  • A. Ehrenfeucht, D. Haussler, M. Kearns & L. Valiant, "A general lower bound on the number of examples needed for learning," Information and Computation 82(3), 247–261 (1989).
  • P. L. Bartlett, N. Harvey, C. Liaw & A. Mehrabian, "Nearly-tight VC-dimension and pseudodimension bounds for piecewise linear neural networks," Journal of Machine Learning Research 20(63), 1–17 (2019).
  • S. Shalev-Shwartz & S. Ben-David, Understanding Machine Learning: From Theory to Algorithms (Cambridge University Press, 2014), chapters 6 and 28.