Rademacher complexity
Build Rademacher complexity as a measure of correlation with pure noise. Derive a generalization bound through McDiarmid and ghost-sample symmetrization, Massart’s finite-class lemma and structural properties including Talagrand’s contraction lemma.
After this lesson you can
- Define empirical and expected Rademacher complexity for a function class and its loss class.
- Prove E[sup_h (R(h) - R̂(h))] ≤ 2ℜ_n(loss ∘ H) using symmetrization with a ghost sample.
- Use McDiarmid to prove a high-probability version including computable empirical complexity.
- Prove Massart’s lemma and apply it to finite classes.
- Use scaling, sums, convex hulls and contraction to bound composite classes.
- Estimate empirical Rademacher complexity of concrete classes using Monte Carlo.
Before you start
Capacity to fit noise
A class may contain infinitely many functions and still be unable to follow arbitrary labels on a sample. VC dimension counts possible labelings; Rademacher complexity asks a quantitative question: how much correlation can the class achieve with independent signs carrying no signal? Noise fitting is a property of the class on observed points, not a direct measure of one function’s error.
The supremum is chosen after seeing the signs. If contains one fixed function, its sum has expectation zero; capacity arises because one can choose among alternatives. For binary functions , maximum correlation equals times optimal sign accuracy minus . The class of all functions on distinct points attains correlation 1. A class’s ability to fit noise does not show all its algorithms fail to generalize; the algorithm and distribution matter too.
Oriented thresholds produce patterns, intervals produce , and a polynomial of degree at most three has at most three sign changes on ordered points. Conversely, placing roots between changes yields every pattern with up to three changes. Constants and empty output are included. For this finite class on the sample, Massart gives for thresholds. An average over a few rounds can exceed that expectation bound without contradicting it.
A sharper bound gives order without the logarithm. If with , the best threshold has sum . The mean of is zero and, by Doob’s maximal inequality in , . Therefore threshold complexity is at most . This order bound uses the ordered structure, not Massart alone.
Each function corresponds to vector . The supremum is the support function of the vector set evaluated in direction , divided by . Its average is a normalized random width. If the class is not symmetric, this mean support should not be confused with a bilateral geometric width without an additional factor.
Symmetrization and a ghost sample
Assume are i.i.d. and . Write and . Let be an independent copy of . For the one-sided deviation ,
The first inequality exchanges supremum and expectation. In the following equality, each pair has the same distribution when swapped; introducing independent signs performs those swaps. The last line separates the supremum of a sum and uses sign symmetry. This is the symmetrization argument; it does not remove the factor 2.
A simultaneous guarantee
Changing one observation of changes by at most because functions lie between 0 and 1. By McDiarmid and symmetrization, with probability at least , simultaneously for every ,
also changes by at most when one observation is replaced. A second one-sided application of McDiarmid gives with failure at most . Applying the first inequality with and taking a union over failures gives the empirical generalization bound
It applies to the loss class in and holds for a hypothesis chosen after seeing the sample because the event is simultaneous. For losses in , concentration terms are multiplied by . To use a Monte Carlo complexity estimate inside the guarantee, add an upper bound on its error and allocate an additional part of ; the average alone is not a certified bound.
Massart: a maximum of sub-Gaussian sums
Let finite and . For , Jensen, the exponential sum and give
Minimizing at , Massart’s lemma gives
If or , complexity is zero and the limiting case is used. For values in , . In binary classification, is the number of sample traces and is at most the growth function . This recovers control by or by Sauer when VC dimension is finite. The bound may exceed 1: still true, but uninformative.
Properties for building bounds
For nonempty classes and , structural properties of empirical complexity include:
- Scaling: . For use sign symmetry and factor .
- Class sums: if all pairs are independently allowed. For a coupled sum only an upper bound is guaranteed.
- Convex hull: , because a linear functional has the same supremum over a class and its convex combinations.
- Translation by a fixed function: adding it does not change the expectation, although it changes each realization of the supremum.
If each is -Lipschitz, the contraction lemma states
To see the mechanism, condition on all signs except one and group the remaining terms as . Averaging the last sign gives half of . Combining suprema, . Swapping and when necessary permits replacement by the average with and the corresponding sign. Repeating coordinate by coordinate proves the result. Constants vanish in expectation; they need not be zero in this version without an exterior absolute value. The 0-1 loss is not Lipschitz as a function of a real margin, so this step cannot be applied directly.
For , Cauchy-Schwarz resolves the supremum:
The inequality uses Jensen and zero expected cross terms. It does not explicitly depend on dimension if input norms are controlled. Applying contraction to ramp loss gives a bound for ramp loss, which in turn dominates 0-1 error when .
The figure uses one nested training sample and 2000 independent test points generated with seed 1307. The learned vector points in the mean direction of and is scaled to norm ; it is not exact ERM. The curve uses the deterministic empirical bound , not an uncorrected sign average. The test line is an observed proportion, not population risk. is fixed for one chosen class; exploring many classes and selecting one after observing bounds requires splitting confidence or another argument.
Estimating complexity
For a finite class stored as a matrix, each draw calculates an exact maximum. For the linear ball use the formula above; for one-dimensional stumps enumerate thresholds and orientations. The standard error below quantifies only Monte Carlo variation conditional on , not sampling uncertainty of or a guaranteed upper bound.
import numpy as np
rng=np.random.default_rng(1307)
n=40; draws=4000
x=np.sort(rng.uniform(-1,1,n))
stumps=np.array([s*np.where(x>=t,1,-1) for s in (-1,1) for t in np.r_[-2,(x[:-1]+x[1:])/2,2]])
signs=rng.choice([-1,1],size=(draws,n))
values=np.max(signs@stumps.T,axis=1)/n
massart=np.sqrt(2*np.log(len(stumps))/n)
print('stumps:',round(values.mean(),4),'error estándar MC:',round(values.std(ddof=1)/np.sqrt(draws),4),'Massart:',round(massart,4))
X=np.column_stack((x,x*x)); B=2
linear=B*np.linalg.norm(signs@X,axis=1)/n
print('bola lineal:',round(linear.mean(),4),'error estándar MC:',round(linear.std(ddof=1)/np.sqrt(draws),4),'cota Jensen:',round(B*np.sqrt((X*X).sum())/n,4))
assert values.mean() <= massart + .03Gaussian complexity replaces each sign with a standard normal and measures the same kind of supremum in Gaussian directions. Comparisons exist under appropriate conditions and constants; they are not identical sample by sample. To reproduce an estimate, fix sample and seed, report draw count and standard error, and check that the maximum is actually solved for the chosen class.
The next experiment uses random labels and scikit-learn models. Training accuracy transformed into correlation measures the fitting procedure’s capacity in those rounds; if the optimizer does not find its class maximum, it is a lower estimate, not necessarily exact complexity. It does not turn random training error into a universal generalization diagnostic.
import numpy as np
from sklearn.tree import DecisionTreeClassifier
from sklearn.neighbors import KNeighborsClassifier
rng=np.random.default_rng(1308)
X=rng.normal(size=(120,4)); scores={str(k):[] for k in (1,3,8)}; scores['1-NN']=[]
for trial in range(20):
y=rng.choice([-1,1],size=len(X))
for depth in (1,3,8):
model=DecisionTreeClassifier(max_depth=depth,random_state=trial).fit(X,y)
scores[str(depth)].append(2*model.score(X,y)-1)
model=KNeighborsClassifier(n_neighbors=1).fit(X,y)
scores['1-NN'].append(2*model.score(X,y)-1)
for name,v in scores.items(): print(name,'correlación media',round(np.mean(v),3),'error estándar',round(np.std(v,ddof=1)/np.sqrt(len(v)),3))Exercises
Step 1 of 2. Why does the supremum move after the ghost expectation?
Step 1 of 2. What bound holds for the moment-generating function of a vector a?
def empirical_rademacher(loss_matrix, n_draws, rng):
pass
def linear_rademacher(X, B, n_draws, rng):
passSummary
The proofs and conventions draw on Bartlett and Mendelson and Chapter 3 of Mohri, Rostamizadeh and Talwalkar.