Simple Algorithm
Machine Learning · Convergence · 28 min

Margin-Based Generalization

Why large margins generalize, whatever the dimension.

An RBF-kernel SVM separates its data with a hyperplane in an infinite-dimensional feature space, where hyperplanes have infinite VC dimension. It generalizes anyway. The explanation is the margin: for norm-bounded linear predictors, what controls generalization is the ratio of the data's radius to the margin, (R/γ)2(R/\gamma)^2, and the dimension never enters.

What you’ll learn

  • Prove the perceptron's (R/γ)2(R/\gamma)^2 mistake bound and explain how it yields generalization guarantees.
  • Show that norm-bounded linear predictors have Rademacher complexity at most BR/mBR/\sqrt m, in any dimension and in any RKHS.
  • Prove the margin bound R(h)≤R^γ(h)+2BRγm+ln⁡(1/δ)2mR(h) \le \hat R_\gamma(h) + \frac{2BR}{\gamma\sqrt m} + \sqrt{\frac{\ln(1/\delta)}{2m}} with the ramp loss and the contraction lemma, and make it uniform over γ\gamma.
  • Define the fat-shattering dimension, prove fat⁡γ≤(BR/γ)2\operatorname{fat}_\gamma \le (BR/\gamma)^2 for linear functions in the simplest case, and relate it to learnability.
  • Assess what margin theory explains about SVMs, gradient descent and deep networks, as of the mid-2020s.

Counting parameters fails; margins do not

Half-spaces in Rd\R^d have VC dimension d+1d + 1, so the VC bound on the gap between training and test error scales like d/m\sqrt{d/m} for mm examples, and says nothing once d≥md \ge m. Kernel SVMs live in that regime by design: the RBF kernel's feature space is infinite-dimensional. A different quantity is needed, and the oldest argument already finds it. Labels are y∈{−1,+1}y \in \{-1, +1\} throughout, and, as in Mohri et al. and Shalev-Shwartz & Ben-David, mm denotes the number of training examples (the nn of the other lessons).

DerivationProof
  1. u⊤wk=u⊤wk−1+yt u⊤xt≥u⊤wk−1+γ⟹u⊤wk≥kγ\mathbf u^\top\mathbf w_k = \mathbf u^\top\mathbf w_{k-1} + y_t\,\mathbf u^\top\mathbf x_t \ge \mathbf u^\top\mathbf w_{k-1} + \gamma \quad\Longrightarrow\quad \mathbf u^\top\mathbf w_k \ge k\gamma

    After the kk-th mistake, the projection on u\mathbf u has grown by at least γ\gamma per mistake:

  2. ∥wk∥2=∥wk−1∥2+2ytwk−1⊤xt+∥xt∥2≤∥wk−1∥2+R2⟹∥wk∥2≤kR2\norm{\mathbf w_k}^2 = \norm{\mathbf w_{k-1}}^2 + 2y_t\mathbf w_{k-1}^\top\mathbf x_t + \norm{\mathbf x_t}^2 \le \norm{\mathbf w_{k-1}}^2 + R^2 \quad\Longrightarrow\quad \norm{\mathbf w_k}^2 \le kR^2

    A mistake means ytwk−1⊤xt≤0y_t\mathbf w_{k-1}^\top\mathbf x_t \le 0, so the squared norm grows by at most R2R^2 per mistake:

  3. kγ≤k R⟹k≤(Rγ)2k\gamma \le \sqrt k\,R \quad\Longrightarrow\quad k \le \Big(\frac R\gamma\Big)^2

    Combine with Cauchy–Schwarz, u⊤wk≤∥wk∥\mathbf u^\top\mathbf w_k \le \norm{\mathbf w_k}:

The perceptron needs only inner products, since w\mathbf w is a sum of mistaken examples, so it runs with any kernel, and the bound holds in the feature space with R2=max⁡tk(xt,xt)R^2 = \max_t k(\mathbf x_t, \mathbf x_t). Mistake bounds become generalization bounds. Cycling through a separable training set until no mistakes remain gives a classifier determined by at most (R/γ)2(R/\gamma)^2 of the examples, a sample compression scheme (Stability, Compression & PAC-Bayes). Freund and Schapire (1999) turned the mistake bound into generalization bounds of order (R/γ)2/m(R/\gamma)^2/m for the voted perceptron, and extended the mistake bound to inseparable data, replacing RR by R+DR + D where DD measures how far the data fall short of margin γ\gamma.

Predict before you look

Inputs have norm at most R=1R = 1 and are separable with margin γ=0.1\gamma = 0.1 by a unit vector. At most how many mistakes can the perceptron make, in a space of dimension one million?

Show the answer

100 mistakes

(R/γ)2=(1/0.1)2=100(R/\gamma)^2 = (1/0.1)^2 = 100, whatever the dimension. The ratio (R/γ)2(R/\gamma)^2 acts as an effective dimension; the theory below shows it controls generalization for SVMs too.

Rademacher complexity of linear predictors

Recall from Rademacher Complexity that for a class F\mathcal F of real functions and a sample S=(x1,…,xm)S = (\mathbf x_1, \dots, \mathbf x_m), the empirical Rademacher complexity is R^S(F)=Eσsup⁡f∈F1m∑iσif(xi)\hat{\mathfrak R}_S(\mathcal F) = \E_{\boldsymbol\sigma}\sup_{f \in \mathcal F}\frac1m\sum_i\sigma_if(\mathbf x_i) with independent uniform signs σi\sigma_i: how well the class can correlate with noise. Take the norm-bounded linear class HB={x↦⟨w,φ(x)⟩:∥w∥≤B}\mathcal H_B = \{\mathbf x \mapsto \langle\mathbf w, \varphi(\mathbf x)\rangle : \norm{\mathbf w} \le B\} in a Hilbert space.

DerivationDimension-free complexity
  1. sup⁡∥w∥≤B1m∑iσi⟨w,φ(xi)⟩=Bm ∥∑iσiφ(xi)∥\sup_{\norm{\mathbf w} \le B}\frac1m\sum_i\sigma_i\langle\mathbf w, \varphi(\mathbf x_i)\rangle = \frac Bm\,\Big\lVert\sum_i\sigma_i\varphi(\mathbf x_i)\Big\rVert

    The supremum of a linear function over a ball is attained in the direction of the vector it is applied to (Cauchy–Schwarz):

  2. R^S(HB)≤BmEσ∥∑iσiφ(xi)∥2=Bm∑i∥φ(xi)∥2=BmTr⁡K\hat{\mathfrak R}_S(\mathcal H_B) \le \frac Bm\sqrt{\E_{\boldsymbol\sigma}\Big\lVert\sum_i\sigma_i\varphi(\mathbf x_i)\Big\rVert^2} = \frac Bm\sqrt{\sum_i\norm{\varphi(\mathbf x_i)}^2} = \frac Bm\sqrt{\Tr K}

    Jensen's inequality moves the expectation inside the square root, and the cross terms vanish because Eσiσj=0\E\sigma_i\sigma_j = 0 for i≠ji \ne j:

  3. R^S(HB)  ≤  BRm\hat{\mathfrak R}_S(\mathcal H_B) \;\le\; \frac{BR}{\sqrt m}

    With ∥φ(xi)∥2=k(xi,xi)≤R2\norm{\varphi(\mathbf x_i)}^2 = k(\mathbf x_i, \mathbf x_i) \le R^2, the trace is at most mR2mR^2:

No dimension appears. For the RBF kernel, k(x,x)=1k(\mathbf x, \mathbf x) = 1 for every input, so R=1R = 1 and the complexity is simply B/mB/\sqrt m: everything rides on the norm of w\mathbf w in feature space, the inverse of the margin. The data-dependent form BmTr⁡K\frac Bm\sqrt{\Tr K} can be computed from the Gram matrix of the actual sample (Bartlett & Mendelson, 2002).

The margin bound

The 0–1 loss of a score ff is not Lipschitz, so Rademacher bounds cannot use it directly. Interpose the ramp loss at margin level γ>0\gamma > 0:

ϕγ(u)=min⁡(1,max⁡(0,1−uγ)),1{u≤0}  ≤  ϕγ(u)  ≤  1{u<γ},\phi_\gamma(u) = \min\Big(1, \max\big(0, 1 - \tfrac u\gamma\big)\Big),\qquad \mathbf 1\{u \le 0\} \;\le\; \phi_\gamma(u) \;\le\; \mathbf 1\{u < \gamma\},

a function of the margin u=yf(x)u = yf(\mathbf x). It is 1/γ1/\gamma-Lipschitz, and it is sandwiched between the 0–1 loss and the margin loss that also counts correct predictions with margin below γ\gamma. Write R^γ(f)=1m∑i1{yif(xi)<γ}\hat R_\gamma(f) = \frac1m\sum_i\mathbf 1\{y_if(\mathbf x_i) < \gamma\}.

DerivationProof
  1. E g  ≤  E^S g+2 Rm(G)+ln⁡(1/δ)2m\E\,g \;\le\; \hat\E_S\,g + 2\,\mathfrak R_m(\mathcal G) + \sqrt{\frac{\ln(1/\delta)}{2m}}

    For a class G\mathcal G of [0,1][0,1]-valued functions, with probability at least 1−δ1 - \delta, uniformly over g∈Gg \in \mathcal G (symmetrization plus McDiarmid; see Rademacher Complexity):

  2. Rm(G)  ≤  1γ Rm({(x,y)↦yf(x)})=1γ Rm(HB)  ≤  BRγm\mathfrak R_m(\mathcal G) \;\le\; \frac1\gamma\,\mathfrak R_m\big(\{(\mathbf x, y) \mapsto yf(\mathbf x)\}\big) = \frac1\gamma\,\mathfrak R_m(\mathcal H_B) \;\le\; \frac{BR}{\gamma\sqrt m}

    Apply it to G={(x,y)↦ϕγ(yf(x))}\mathcal G = \{(\mathbf x, y) \mapsto \phi_\gamma(yf(\mathbf x))\}. Talagrand's contraction lemma (Ledoux & Talagrand, 1991) strips the 1/γ1/\gamma-Lipschitz ramp, and the label disappears because σiyi\sigma_iy_i has the same distribution as σi\sigma_i:

  3. P(yf(x)≤0)≤E ϕγ(yf(x)),E^S ϕγ(yf(x))≤R^γ(f)P\big(yf(\mathbf x) \le 0\big) \le \E\,\phi_\gamma\big(yf(\mathbf x)\big),\qquad \hat\E_S\,\phi_\gamma\big(yf(\mathbf x)\big) \le \hat R_\gamma(f)

    Sandwich: the 0–1 risk is at most E ϕγ\E\,\phi_\gamma, and the empirical ramp loss is at most R^γ(f)\hat R_\gamma(f). Substituting gives the theorem.

What it says about SVMs. For a hard-margin SVM in canonical form, every training point has yif(xi)≥1y_if(\mathbf x_i) \ge 1 and the geometric margin is γgeo=1/∥w∥\gamma_{\text{geo}} = 1/\norm{\mathbf w}. Taking the level 11 and B=∥w∥B = \norm{\mathbf w} (legitimate with the uniform version), the empirical term vanishes and the complexity term is 2R/(γgeom)2R/(\gamma_{\text{geo}}\sqrt m): the effective dimension is (R/γgeo)2(R/\gamma_{\text{geo}})^2, the same quantity as in the perceptron bound. For soft margins, the hinge loss dominates the ramp at level 1, so

P(yf(x)≤0)≤1m∑i[1−yif(xi)]++2∥w∥Rm+…,P\big(yf(\mathbf x) \le 0\big) \le \frac1m\sum_i\big[1 - y_if(\mathbf x_i)\big]_+ + \frac{2\norm{\mathbf w}R}{\sqrt m} + \dots,

and the soft-margin objective, average hinge loss plus a penalty on ∥w∥2\norm{\mathbf w}^2, is a regularized surrogate for the right-hand side. This is the structural-risk-minimization reading of the SVM; making it rigorous for a margin that is only known after seeing the data was the contribution of Shawe-Taylor, Bartlett, Williamson and Anthony (1998).

Predict before you look

A classifier has R/γ=10R/\gamma = 10 and zero margin errors. How many training examples make the complexity term 2R/(γm)2R/(\gamma\sqrt m) at most 0.050.05?

Show the answer

160000 examples

2×10/m≤0.052 \times 10/\sqrt m \le 0.05 requires m≥400\sqrt m \ge 400, so m≥160,000m \ge 160{,}000. The worst-case constants make margin bounds conservative, but the scaling, (R/γ)2/ε2(R/\gamma)^2/\varepsilon^2 examples, is independent of the dimension.

Fat-shattering and the scale of learnability

DerivationLinear functions: $operatorname{fat}(gamma) le (BR/gamma)^2$ (zero witnesses)
  1. mγ  ≤  ∑ibi wb⊤xi=wb⊤(∑ibixi)  ≤  B ∥∑ibixi∥m\gamma \;\le\; \sum_i b_i\,\mathbf w_{\mathbf b}^\top\mathbf x_i = \mathbf w_{\mathbf b}^\top\Big(\sum_i b_i\mathbf x_i\Big) \;\le\; B\,\Big\lVert\sum_i b_i\mathbf x_i\Big\rVert

    Suppose {x↦w⊤x:∥w∥≤B}\{\mathbf x \mapsto \mathbf w^\top\mathbf x : \norm{\mathbf w} \le B\} γ\gamma-shatters x1,…,xm\mathbf x_1, \dots, \mathbf x_m with ∥xi∥≤R\norm{\mathbf x_i} \le R and all witnesses 00. For each pattern b\mathbf b pick its wb\mathbf w_{\mathbf b} and sum the mm inequalities:

  2. mγ  ≤  B Eb∥∑ibixi∥  ≤  B∑i∥xi∥2  ≤  Bm R⟹m≤(BRγ)2m\gamma \;\le\; B\,\E_{\mathbf b}\Big\lVert\sum_i b_i\mathbf x_i\Big\rVert \;\le\; B\sqrt{\sum_i\norm{\mathbf x_i}^2} \;\le\; B\sqrt m\,R \quad\Longrightarrow\quad m \le \Big(\frac{BR}\gamma\Big)^2

    This holds for every b\mathbf b, so it holds on average over uniformly random signs, where the same computation as for the Rademacher complexity applies:

  3. General witnesses need an extra combinatorial step, but the bound (BR/γ)2(BR/\gamma)^2 survives (Bartlett & Shawe-Taylor, 1999).

Fat-shattering plays the role for real-valued classes that the VC dimension plays for binary ones: a class of [0,1][0,1]-valued functions has uniform convergence of empirical means, at every accuracy and for every distribution, exactly when fat⁡F(γ)\operatorname{fat}_{\mathcal F}(\gamma) is finite for every γ>0\gamma > 0 (Alon, Ben-David, Cesa-Bianchi & Haussler, 1997).

Bartlett (1998) used these tools for neural networks, in a paper whose title states its conclusion: the size of the weights is more important than the size of the network. For networks whose units have weight vectors of bounded ℓ1\ell_1 norm, the misclassification probability is bounded by the fraction of training points with margin below γ\gamma plus a term that depends on the weight bound, the margin, the depth and (only logarithmically) the input dimension, but not on the number of weights. A huge network trained to have small weights and large margins can generalize, which parameter counting cannot explain.

What margins explain today

Tightness for SVMs. The classic bounds have been refined repeatedly; Grønlund, Kamma and Larsen (2020) improved the margin-based upper bound for SVMs and proved a nearly matching lower bound, so the margin story for linear classifiers is close to settled.

Implicit maximum margins. Margins also appear without being asked for. Soudry, Hoffer, Nacson, Gunasekar and Srebro (2018) proved that gradient descent on the logistic loss over linearly separable data, with no regularization at all, converges in direction to the hard-margin SVM solution, though only at rate 1/log⁡t1/\log t. Margin theory thus applies to plain unregularized training; The Implicit Bias of Gradient Descent develops this.

Deep networks. Bartlett, Foster and Telgarsky (2017) proved margin bounds for neural networks that scale with a "spectral complexity", the product of the layers' spectral norms times a correction factor, and found it correlated with excess risk when training on true versus random labels. Numerically, such norm-based bounds are typically vacuous for large networks, and whether they capture why networks generalize is unsettled. Dziugaite and Roy (2017) obtained the first nonvacuous bounds for deep stochastic networks by directly optimizing a PAC-Bayes bound, and a large empirical study of over 40 complexity measures across more than 10,000 networks (Jiang et al., 2020) found surprising failures among them.

Check your understanding

For an RBF-kernel SVM, every feature vector has norm k(x,x)=1\sqrt{k(\mathbf x, \mathbf x)} = 1. What, then, controls the complexity term of its margin bound?

  1. The dimension of the input space
  2. Nothing: the bound is the same for every RBF SVM
  3. The number of support vectors only
  4. The norm ∥w∥\norm{\mathbf w} in feature space, the inverse of the margin, relative to m\sqrt m
Show the answer

D. The norm ∥w∥\norm{\mathbf w} in feature space, the inverse of the margin, relative to m\sqrt m

With R=1R = 1 the complexity term is 2∥w∥/m2\norm{\mathbf w}/\sqrt m at margin level 1. Settings that need a large ∥w∥\norm{\mathbf w} to fit the data, such as a very large γ\gamma, have a small feature-space margin and a weak bound, even though the dimension of the feature space never changes.

Key takeaways

  • The perceptron makes at most (R/γ)2(R/\gamma)^2 mistakes on data separable with margin γ\gamma, in any dimension; kernelized, it inherits the bound with R2=max⁡k(x,x)R^2 = \max k(\mathbf x, \mathbf x).
  • Norm-bounded linear predictors have Rademacher complexity at most BmTr⁡K≤BR/m\frac Bm\sqrt{\Tr K} \le BR/\sqrt m: dimension-free.
  • Margin bound: with probability 1−δ1 - \delta, P(yf≤0)≤R^γ(f)+2BR/(γm)+ln⁡(1/δ)/(2m)P(yf \le 0) \le \hat R_\gamma(f) + 2BR/(\gamma\sqrt m) + \sqrt{\ln(1/\delta)/(2m)}, by the ramp loss and contraction; uniform over γ\gamma at a log⁡log⁡\log\log cost. The SVM objective is a regularized surrogate for it.
  • Fat-shattering is the scale-sensitive VC dimension; linear functions have fat⁡(γ)≤(BR/γ)2\operatorname{fat}(\gamma) \le (BR/\gamma)^2, and finiteness at every scale characterizes uniform convergence (Alon et al., 1997).
  • Margins also explain the implicit bias of gradient descent on separable data, but whether margin-type bounds explain deep networks' generalization is unsettled.

Check yourself

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

Question 1

Inputs satisfy ∥x∥≤5\norm{\mathbf x} \le 5 and some unit vector separates them with margin 0.50.5. What does Novikoff's theorem guarantee?

  1. At most 10 perceptron mistakes
  2. At most 100 perceptron mistakes, on any ordering of any such sequence
  3. At most 100 mistakes, but only in dimension 100 or less
  4. Convergence, with no bound on the number of mistakes
Show the answer

B. At most 100 perceptron mistakes, on any ordering of any such sequence

(R/γ)2=(5/0.5)2=100(R/\gamma)^2 = (5/0.5)^2 = 100. The bound holds for every order of presentation and every dimension; the margin and the radius are all that matter.

Question 2

A linear class has ∥w∥≤2\norm{\mathbf w} \le 2, inputs satisfy ∥x∥≤3\norm{\mathbf x} \le 3, and the sample has m=900m = 900 points in dimension 10510^5. What bound holds for its empirical Rademacher complexity?

  1. 0.20.2
  2. About 105/900≈10.5\sqrt{10^5/900} \approx 10.5
  3. 66
  4. 0.00670.0067
Show the answer

A. 0.20.2

BR/m=2×3/30=0.2BR/\sqrt m = 2 \times 3/30 = 0.2. The dimension 10510^5 plays no role; a VC-style term d/m\sqrt{d/m} would be vacuous here.

Question 3

Why does the margin-bound proof use the ramp loss ϕγ\phi_\gamma instead of the 0–1 loss directly?

  1. Because the ramp loss is convex
  2. Because the 0–1 loss is not bounded
  3. Because SVMs minimize the ramp loss
  4. Because the ramp loss is 1/γ1/\gamma-Lipschitz, so the contraction lemma reduces its complexity to that of the linear scores, while it still upper-bounds the 0–1 loss
Show the answer

D. Because the ramp loss is 1/γ1/\gamma-Lipschitz, so the contraction lemma reduces its complexity to that of the linear scores, while it still upper-bounds the 0–1 loss

Contraction needs a Lipschitz function of the score; the 0–1 loss jumps at 00. The ramp is 1/γ1/\gamma-Lipschitz in the margin u=yf(x)u = yf(\mathbf x), lies above 1{u≤0}\mathbf 1\{u \le 0\} and below 1{u<γ}\mathbf 1\{u < \gamma\}, which turns the complexity of HB\mathcal H_B into the 2BR/(γm)2BR/(\gamma\sqrt m) term.

Question 4

Linear functions with ∥w∥≤1\norm{\mathbf w} \le 1 act on inputs with ∥x∥≤1\norm{\mathbf x} \le 1. At scale γ=0.25\gamma = 0.25, at most how many points can they γ\gamma-shatter?

  1. 4
  2. Infinitely many, in infinite dimensions
  3. d+1d + 1
  4. 16
Show the answer

D. 16

fat⁡(γ)≤(BR/γ)2=(1/0.25)2=16\operatorname{fat}(\gamma) \le (BR/\gamma)^2 = (1/0.25)^2 = 16, in any dimension, even an infinite-dimensional feature space. Requiring a margin caps how many patterns can be realized.

Further reading

  • A. B. J. Novikoff, "On convergence proofs on perceptrons" (1962).
  • P. L. Bartlett, "The sample complexity of pattern classification with neural networks: the size of the weights is more important than the size of the network," IEEE Transactions on Information Theory 44(2), 525–536 (1998).
  • N. Alon, S. Ben-David, N. Cesa-Bianchi & D. Haussler, "Scale-sensitive dimensions, uniform convergence, and learnability," Journal of the ACM 44(4), 615–631 (1997).
  • P. L. Bartlett & S. Mendelson, "Rademacher and Gaussian complexities: risk bounds and structural results," Journal of Machine Learning Research 3, 463–482 (2002).
  • M. Mohri, A. Rostamizadeh & A. Talwalkar, Foundations of Machine Learning, 2nd ed. (MIT Press, 2018), chapters 5 and 6; S. Shalev-Shwartz & S. Ben-David, Understanding Machine Learning (Cambridge University Press, 2014), chapters 15 and 26.