Module contents
Lesson 6 of 20Core 100 min

VC dimension and the Sauer-Shelah lemma

For infinite classes, count distinct labelings on n points instead of log|H|. Define shattering, growth function and VC dimension, calculate geometric examples including half-spaces via Radon, and prove Sauer-Shelah.

After this lesson you can

  • Define shattering, growth function Π_H(n) and VC dimension.
  • Calculate VC dimension of thresholds, intervals, rectangles and half-spaces in R^d, using Radon’s theorem for the latter.
  • Construct a one-parameter class with infinite VC dimension and explain why VC dimension is not parameter count.
  • Prove Sauer-Shelah by induction and derive Π_H(n) ≤ (en/d)^d for n ≥ d.
  • Calculate the growth function of a small class by brute force and verify Sauer numerically.

Before you start

Counting functions on a sample

Half-planes have infinitely many positions and orientations. Applying the finite-class bound directly with log⁡∣H∣\log|\mathcal H| is useless. On a finite set of points, however, only the distinct labelings produced there matter. That count can be small even for infinitely many rules.

Proving dimension dd requires two distinct pieces: exhibit one shattered set of dd points and prove that no set of d+1d+1 points is shattered. A degenerate configuration may not be shattered even though another of the same size is. Do not confuse the trace on one sample with the maximum over all samples.

For example, if a class realizes only vectors 000, 001 and 111 on three points, its trace there has size 3, even if it contains infinitely many distinct formulas. It does not shatter those three points because five labelings are missing. The growth function at three is the largest trace size among all three-point sets; another set may have more. If an nn-point set is shattered, each subset is shattered too: extend any labeling of the subset to the remaining points and use the corresponding witness.

Trace counting depends on the rule class and how boundaries are treated. Here a binary rule includes boundary points as positive; negatives must lie outside. On a finite separable sample there is positive slack relative to negatives, so the boundary can be shifted slightly to obtain strict separation between both groups. Figures use finite-precision coordinates and calculations; proofs are understood over real numbers.

In the game, drag three to six points and select a class. Each cell represents a labeling; existence of a witness is checked and drawn when one exists. For disks the set of feasible centers is clipped numerically, with points snapped to a grid and finite tolerance. For degenerate convex sets of one or two positives, their convex hull is shown: a sufficiently small convex neighborhood can avoid negatives outside it. The figure’s decisions are a finite experiment, not a proof for all sets.

Each cell number encodes its labeling: add 2i−12^{i-1} for each positive point ii. For example, with four points, cell 5 makes points 1 and 3 positive. At the vertices of a convex quadrilateral, the two diagonals cross; that pattern and its complement cannot be separated by a line. Move one point inside the triangle formed by the other three and another certificate appears: a half-plane cannot include all three vertices while excluding the interior point.

InteractiveThe shattering game
1234
Blue: label 1; orange: 0. Empty or constant witnesses need no boundary. A degenerate hull denotes a small convex neighborhood.
Class
4
Labelings: select a cell
Realizable labelings14 / 16
Shatters these points?no
Chosen labelingimpossible
Change the class and click a cell to select a labeling. Drag points; a boundary or region shows a witness when the labeling is realizable.

Geometric bounds

For thresholds ht(x)=1{x≥t}h_t(x)=\mathbf1\{x\ge t\} on R\mathbb R, one point is shattered, but two ordered points cannot realize pattern 1,0: VC = 1. Intervals shatter two points, while three ordered points cannot realize 1,0,1: VC = 2. These classes include the empty rule through an appropriate choice or as an explicit case.

For axis-aligned rectangles in the plane, the four points (±1,0)(\pm1,0) and (0,±1)(0,\pm1) are shattered: each omitted point is extreme in some coordinate, so the rectangle fitted to positives excludes it. For five points, select one representative of each minimum and maximum along both coordinates. With at most four representatives, one point remains inside the rectangle enclosing the others. The labeling excluding only that point is unrealizable; therefore VC = 4, even with coordinate ties.

Planar disks have VC = 3. Three vertices of an equilateral triangle are shattered: small disks isolate one, a disk with one side as diameter contains its endpoints and excludes the third, and disks exist for all or none. For four points pip_i, there is a nontrivial affine dependence ∑iaipi=0\sum_i a_i p_i=0, ∑iai=0\sum_i a_i=0, with coefficients of both signs. Membership in a disk is determined by the sign of si=r2−∥pi−c∥2s_i=r^2-\|p_i-c\|^2. Summing with those coefficients,

∑iaisi=−∑iai∥pi∥2,\sum_i a_i s_i=-\sum_i a_i\|p_i\|^2,

a constant independent of the disk. The two complementary labelings that assign 1 to positive coefficients and 0 to negative coefficients, or the reverse, would require strictly opposite signs for that sum. At least one is impossible. Zero coefficients receive arbitrary labels. Thus no four-point set is shattered.

Planar convex sets with no vertex limit have infinite VC dimension: for each nn choose nn distinct points on a circle. The hull of any subset of positives excludes the remaining circle points; empty and singleton subsets are handled with small regions. Limiting the number of sides changes the class and needs a different bound; no exact dimension follows from one picture.

The difference between disks and convex sets illustrates why counting “smooth geometric families” is insufficient. Every disk is convex, but not every convex polygon is a disk. The first class shatters no four-point set; the second, if allowed as many vertices as needed, can select any subset of points in convex position. Class inclusion only guarantees the smaller class’s growth function does not exceed the larger one’s.

Half-spaces and Radon

Affine half-spaces in Rd\mathbb R^d have VC dimension d+1d+1. For the lower bound, choose d+1d+1 affinely independent points. For any sign assignment an affine function takes those values on the points: solve an invertible system with d+1d+1 unknowns. Its sign realizes the labeling.

For the upper bound, take any d+2d+2 points. Their augmented vectors (pi,1)(p_i,1) are linearly dependent, so there are nonzero coefficients with ∑iaipi=0\sum_i a_i p_i=0 and ∑iai=0\sum_i a_i=0. There are positive and negative coefficients. Normalize each group by the sum of its coefficient magnitudes: both groups give the same point as a convex combination. Zero coefficients may be assigned anywhere. This is Radon’s partition. An affine function cannot be positive on one group and negative on the other when their hulls intersect, because it would take incompatible signs at the common point. Thus no d+2d+2-point set is shattered.

InteractiveRadon’s partition in action
1234
Blue and orange: Radon groups; green: common point of their hulls.
Blue group1, 3
Orange group2, 4
Hullsintersect
Drag four points. The green point belongs to the blue and orange hulls: opposite labels cannot be separated by a line.

The figure seeks a partition and an intersection of hulls; degenerate configurations can have several valid ones. Numerical precision limits belong to the visual implementation. The algebraic argument also covers repeated or collinear points.

Sauer-Shelah lemma

If VC⁡(H)=d<∞\operatorname{VC}(\mathcal H)=d<\infty, the Sauer-Shelah lemma states

ΠH(n)≤∑i=0d(ni),ΠH(n)≤(end)d(n≥d≥1).\Pi_{\mathcal H}(n)\le\sum_{i=0}^{d}\binom ni, \qquad \Pi_{\mathcal H}(n)\le\left(\frac{en}{d}\right)^d\quad(n\ge d\ge1).

To prove the first inequality, take a family F\mathcal F of subsets of {1,…,n}\{1,\ldots,n\} with VC dimension at most dd. Project each subset onto the first n−1n-1 indices and call the family of distinct projections AA. Call BB the projections occurring with both possibilities for the last index. Each projection contributes once to AA and, if it has two extensions, once more to BB: ∣F∣=∣A∣+∣B∣|\mathcal F|=|A|+|B|.

The dimension of AA is at most dd. That of BB is at most d−1d-1: if BB shattered dd indices, both extensions of each trace would shatter those indices plus the last in F\mathcal F. By induction on n+dn+d, with bases n=0n=0 or d=0d=0,

∣F∣≤∑i=0d(n−1i)+∑i=0d−1(n−1i)=∑i=0d(ni).|\mathcal F|\le\sum_{i=0}^{d}\binom{n-1}{i}+\sum_{i=0}^{d-1}\binom{n-1}{i}=\sum_{i=0}^{d}\binom ni.

For the second inequality take q=d/n≤1q=d/n\le1. Since qi−d≥1q^{i-d}\ge1 for i≤di\le d,

∑i=0d(ni)≤q−d(1+q)n≤(n/d)denq=(en/d)d.\sum_{i=0}^{d}\binom ni\le q^{-d}(1+q)^n\le(n/d)^d e^{nq}=(en/d)^d.

The dichotomy concerns the growth function of a fixed class: if its VC dimension is infinite, it shatters sets of every size and Π(n)=2n\Pi(n)=2^n; if finite, the lemma gives at most polynomial growth in nn for fixed dd. It does not claim every finite-dimensional class attains the bound or every particular trace has that size.

The sum equals 2n2^n when n≤dn\le d, since it then includes all binomial coefficients. When n>dn>d, some are omitted and growth is controlled by a polynomial of degree dd. For d=0d=0, a nonempty class realizes only one trace on each set and is treated separately from (en/d)d(en/d)^d, which divides by dd.

The figure uses exact formulas for intervals and affine half-planes in general position. For rectangles it enumerates all distinct coordinate orders up to n=7n=7 and shows the maximum found among those generic configurations; this is an enumeration result, not a proof for degenerate sets. The vertical scale is base-2 logarithmic and Sauer is a bound, not necessarily an attained curve.

On a line with nn ordered points, an interval selects a consecutive block: there are n(n+1)/2n(n+1)/2 nonempty blocks and one empty trace. For affine half-planes in the plane, points in general position give n2−n+2n^2-n+2 labelings for n≥1n\ge1. The expressions describe different classes although both are infinite. The graph compares their logarithms to show when the 2n2^n curve separates from available counts.

InteractiveExponential up to d, polynomial afterwards
  • exact growth
  • Sauer bound
  • all labelings
Class
VC dimension2
Labelings for n=729
Sauer bound for n=729
Compare each class with 2ⁿ and the Sauer sum. Change class and distinguish the enumerated maximum for rectangles from the stated exact formulas.
[ ]Half-plane traces by feasibilityBrowser
import numpy as np
from itertools import product
from math import comb
from scipy.optimize import linprog

def halfplane_realizable(X, labels):
    sign=2*np.asarray(labels)-1
    A=-sign[:,None]*np.column_stack((X,np.ones(len(X))))
    # Una separación estricta finita puede reescalarse a margen 1.
    return linprog(np.zeros(3),A_ub=A,b_ub=-np.ones(len(X)),bounds=[(None,None)]*3,method='highs').success
def trace_count(X,oracle):
    return sum(oracle(X,y) for y in product([0,1],repeat=len(X)))
rng=np.random.default_rng(1306)
for n in range(1,7):
    X=rng.normal(size=(n,2))
    observed=trace_count(X,halfplane_realizable)
    sauer=sum(comb(n,i) for i in range(min(3,n)+1))
    print('n',n,'trazas',observed,'Sauer',sauer,'2ⁿ',2**n)
    assert observed <= sauer

The program counts traces on the generated set; it does not automatically maximize over all possible positions. Margin 1 is legitimate for strict separation of a finite set because it can be rescaled. A negative result from the numerical optimizer must be interpreted with its tolerance; it does not replace Radon’s proof.

[ ]Search for shattered setsBrowser
import numpy as np
from itertools import product
from scipy.optimize import linprog
from scipy.spatial import ConvexHull

def rectangle_realizable(X,y):
    P=X[np.asarray(y,dtype=bool)]; N=X[~np.asarray(y,dtype=bool)]
    if not len(P): return True
    lo,hi=P.min(axis=0),P.max(axis=0)
    return not np.any(np.all((N>=lo)&(N<=hi),axis=1))
def disk_realizable(X,y):
    P=X[np.asarray(y,dtype=bool)]; N=X[~np.asarray(y,dtype=bool)]
    if not len(P) or not len(N): return True
    pairs=[(p,q) for p in P for q in N]
    A=np.array([-2*(p-q) for p,q in pairs])
    b=np.array([-(p@p-q@q)-1e-7 for p,q in pairs])
    return linprog(np.zeros(2),A_ub=A,b_ub=b,bounds=[(None,None)]*2,method='highs').success
def polygon_witness(X,y,k=3):
    P=X[np.asarray(y,dtype=bool)]; N=X[~np.asarray(y,dtype=bool)]
    if not len(P) or not len(N): return True
    if len(P)==1: return np.all(np.linalg.norm(N-P[0],axis=1)>1e-8)
    if len(P)==2:
        u=P[1]-P[0]; t=np.clip((N-P[0])@u/(u@u),0,1)
        return np.all(np.linalg.norm(N-(P[0]+t[:,None]*u),axis=1)>1e-8)
    hull=ConvexHull(P)
    if len(hull.vertices)>k: return False  # criterio suficiente, no oráculo completo
    return not np.any(np.all(N@hull.equations[:,:-1].T+hull.equations[:,-1]<=1e-8,axis=1))
def shattered(X,oracle):
    return all(oracle(X,y) for y in product([0,1],repeat=len(X)))
cross=np.array([[-1,0],[1,0],[0,-1],[0,1]],float)
triangle=np.array([[0,0],[1,0],[.5,.8660254]])
print('rectángulo, cuatro extremos:',shattered(cross,rectangle_realizable))
print('discos, triángulo:',shattered(triangle,disk_realizable))
print('triángulos convexos, tres puntos:',shattered(triangle,polygon_witness))
rng=np.random.default_rng(1306)
candidates=[rng.normal(size=(4,2)) for _ in range(10)]
print('búsqueda de 4 puntos: rectángulo / disco / testigo poligonal',
      *(sum(shattered(X,f) for X in candidates) for f in [rectangle_realizable,disk_realizable,polygon_witness]))

The preceding polygon check is sufficient, not complete: if the positive hull has more than kk vertices, another polygon of kk vertices might contain it and avoid negatives. With one or two positives, provided no negative lies in their hull, a sufficiently narrow triangle can be chosen around it. Thus a found witness proves a lower bound; a failed attempt does not prove impossibility. The program avoids attributing an exact VC dimension to that search.

One parameter can have infinite capacity

Consider hω(x)=1{sin⁡(ωx)>0}h_\omega(x)=\mathbf1\{\sin(\omega x)>0\} with one parameter ω≥0\omega\ge0. For any kk, take xi=10−ix_i=10^{-i} and choose digits di=2d_i=2 for label 1, or di=7d_i=7 for label 0. Define integer N=∑i=1kdi10i−1N=\sum_{i=1}^{k}d_i10^{i-1} and ω=2πN\omega=2\pi N. The fractional part of N/10iN/10^i lies between 0.2 and 0.3 if di=2d_i=2, and between 0.7 and 0.8 if di=7d_i=7. The sine is respectively positive or negative. Adding a more significant digit leaves earlier phases unchanged because it adds an integer to each. Thus sets of any size are shattered: VC dimension is infinite with one parameter.

InteractiveOne parameter, infinite capacity
x = 10⁻1
target: 1
pending
x = 10⁻2
target: 0
pending
x = 10⁻3
target: 1
pending
x = 10⁻4
target: 0
pending
x = 10⁻5
target: 1
pending
x = 10⁻6
target: 0
pending

Each curve is a local phase window around a point; they do not share a horizontal x scale.

0 of 6 signs fixed
Integer N0
Frequency ω = 2πN0.00
Signs fixed0 / 6
Choose six labels and replay the construction of N. Each window shows the sine around an already fixed point; the algebraic proof covers any finite k.

The figure uses six digits and finite-precision arithmetic. The mathematical proof allows arbitrarily large integers and does not guarantee that a fixed-precision computer represents unlimited frequencies. Parameter count alone does not determine VC dimension. For ReLU networks, Bartlett, Harvey, Liaw and Mehrabian prove an upper bound O(WLlog⁡W)O(WL\log W) and lower constructions Ω(WLlog⁡(W/L))\Omega(WL\log(W/L)) under their conditions on weights and depth; these are not a universal equality for every architecture.

Exercises

Proof
Prove: Prove that affine half-spaces in Rᵈ have VC dimension d+1.
0
Use a simplex for the lower bound and an affine dependence for the upper bound.

Step 1 of 2. Why can d+1 affinely independent points receive arbitrary signs?

Proof
Prove: Prove Sauer-Shelah by projection and double extension.
0
Project traces onto n-1 indices: A contains the projections and B those with both extensions.

Step 1 of 2. How are the sizes related?

Numeric
For n=20 and VC dimension d=3, calculate the Sauer sum Σᵢ₌₀³ C(20,i).
CodeShattering with an oracle
Implement is_shattered(points, realizable): realizable(points, labels) returns a Boolean for a labeling; check every labeling. Implement vc_lower_bound(sampler, realizable, k_max): sampler(k) provides a candidate set of k points, and return the largest tested k that is shattered, or 0. Search failure is not an upper bound.
def is_shattered(points, realizable):
  pass
def vc_lower_bound(sampler, realizable, k_max):
  pass
Shift+Enter to run

Summary

Key idea
Shattering requires every labeling of a set; VC dimension seeks the largest possible size. Radon bounds half-spaces and Sauer-Shelah bounds growth when VC dimension is finite. A single parameter can encode infinite VC dimension.