Simple Algorithm
Machine Learning · Convergence · 30 min

Reproducing Kernel Hilbert Spaces

Mercer’s theorem, the representer theorem and kernel norms.

Every kernel secretly defines a space of functions, and in that space evaluating a function is an inner product. That one property explains why kernel methods collapse infinite-dimensional problems to nn coefficients, what the regularizer ∥f∥\norm{f} actually penalizes, and which kernels can learn any continuous function.

What you’ll learn

  • Define positive-definite kernels and reproducing kernel Hilbert spaces, derive the continuity of point evaluation, and sketch the Moore–Aronszajn construction.
  • State Mercer's theorem and read the RKHS norm as a penalty on eigen-components, in examples (Brownian motion, the Laplacian and Gaussian kernels).
  • Prove the representer theorem and apply it to kernel ridge regression, SVMs and splines.
  • Explain universal kernels, and how eigenvalue decay and smoothness set the minimax rate n−bc/(bc+1)n^{-bc/(bc+1)} of kernel ridge regression.

Positive-definite kernels and their Hilbert spaces

Two consequences are immediate. Applying (ii) to f=k(z,⋅)f=k(z,\cdot) gives ⟨k(x,⋅),k(z,⋅)⟩H=k(x,z)\langle k(x,\cdot),k(z,\cdot)\rangle_{\mathcal H}=k(x,z), so φ(x)=k(x,⋅)\varphi(x)=k(x,\cdot) is a feature map for kk, the canonical one. And Cauchy–Schwarz gives

∣f(x)−g(x)∣=∣⟨f−g, k(x,⋅)⟩∣≤∥f−g∥Hk(x,x):\abs{f(x)-g(x)}=\abs{\langle f-g,\,k(x,\cdot)\rangle}\le\norm{f-g}_{\mathcal H}\sqrt{k(x,x)}:

functions that are close in the RKHS norm are close at every single point. This is what makes these spaces special. In L2[0,1]L^2[0,1] two functions at distance zero may differ at any given point, so "the value at xx" is not even defined, and no kernel can reproduce it. Conversely, by the Riesz representation theorem, any Hilbert space of functions on which every evaluation f↦f(x)f\mapsto f(x) is continuous is an RKHS.

DerivationConstruction (sketch)
  1. ⟨∑iaik(xi,⋅), ∑jbjk(zj,⋅)⟩H0=∑i,jaibj k(xi,zj)\Big\langle\sum_ia_ik(x_i,\cdot),\ \sum_jb_jk(z_j,\cdot)\Big\rangle_{\mathcal H_0}=\sum_{i,j}a_ib_j\,k(x_i,z_j)

    Start from finite combinations of kernel sections, H0={∑i=1naik(xi,⋅)}\mathcal H_0=\{\sum_{i=1}^na_ik(x_i,\cdot)\}, and define an inner product that makes the sections behave like feature vectors:

  2. ⟨f,k(x,⋅)⟩H0=∑iai k(xi,x)=f(x)\langle f,k(x,\cdot)\rangle_{\mathcal H_0}=\sum_ia_i\,k(x_i,x)=f(x)

    It is well defined: the right side equals ∑jbjf(zj)\sum_jb_jf(z_j) for f=∑iaik(xi,⋅)f=\sum_ia_ik(x_i,\cdot), which depends on the function ff and not on how it is written. The reproducing property holds by construction:

  3. ∣f(x)∣=∣⟨f,k(x,⋅)⟩∣≤⟨f,f⟩ k(x,x)=0for every x\abs{f(x)}=\abs{\langle f,k(x,\cdot)\rangle}\le\sqrt{\langle f,f\rangle}\,\sqrt{k(x,x)}=0\quad\text{for every }x

    It is positive definite: ⟨f,f⟩=a⊤Ka≥0\langle f,f\rangle=\mathbf a^\top K\mathbf a\ge0 because kk is, and if ⟨f,f⟩=0\langle f,f\rangle=0, Cauchy–Schwarz (valid for any semi-inner product) forces f=0f=0 pointwise:

  4. Hk=span⁡‾ {k(x,⋅):x∈X}\mathcal H_k=\overline{\operatorname{span}}\,\{k(x,\cdot):x\in\mathcal X\}

    Complete it. A Cauchy sequence in H0\mathcal H_0 is Cauchy at every point, by the same inequality, so it converges pointwise; Hk\mathcal H_k is the set of these pointwise limits with the limiting norm (Aronszajn checks that this is consistent). Any RKHS with kernel kk contains H0\mathcal H_0 as a dense subspace, because a function orthogonal to every k(x,⋅)k(x,\cdot) vanishes everywhere, hence equals this completion: uniqueness.

Mercer's theorem: the kernel's spectrum

Many texts, and the glossary, write these eigenvalues λj\lambda_j; this lesson writes μj\mu_j because λ\lambda is the regularization parameter of kernel ridge regression throughout.

The expansion is an explicit feature map, φ(x)=(μj ej(x))j≥1∈ℓ2\varphi(x)=(\sqrt{\mu_j}\,e_j(x))_{j\ge1}\in\ell^2, and an explicit description of the space (sums over μj>0\mu_j>0):

Hk={f=∑jajej : ∑jaj2μj<∞},∥f∥Hk2=∑jaj2μj.\mathcal H_k=\Big\{f=\sum_ja_je_j\ :\ \sum_j\frac{a_j^2}{\mu_j}<\infty\Big\},\qquad\norm{f}^2_{\mathcal H_k}=\sum_j\frac{a_j^2}{\mu_j}.

The RKHS norm charges each eigen-component by the inverse of its eigenvalue. For smooth kernels the eigenfunctions with small μj\mu_j oscillate fast, so a small norm means few fast oscillations: the RKHS norm measures roughness, in the currency of the kernel. (Mercer's theorem is the classical route; Moore–Aronszajn needs no topology or measure at all.)

For a translation-invariant kernel k(x,z)=κ(x−z)k(\mathbf x,\mathbf z)=\kappa(\mathbf x-\mathbf z) on Rd\R^d whose Fourier transform κ^\hat\kappa is integrable and positive, the same picture holds with frequencies in place of eigenfunctions:

∥f∥H2=1(2π)d∫Rd∣f^(ω)∣2κ^(ω) dω.\norm{f}^2_{\mathcal H}=\frac1{(2\pi)^d}\int_{\R^d}\frac{\abs{\hat f(\boldsymbol\omega)}^2}{\hat\kappa(\boldsymbol\omega)}\,d\boldsymbol\omega.

Frequencies that the kernel's spectrum makes rare are expensive. For the Laplacian kernel e−∣x−z∣e^{-\abs{x-z}} in one dimension, κ^(ω)=2/(1+ω2)\hat\kappa(\omega)=2/(1+\omega^2), so ∥f∥H2=12∫(f2+f′2)\norm f^2_{\mathcal H}=\tfrac12\int(f^2+f'^2), a Sobolev norm. For the Gaussian kernel with length scale ℓ\ell, κ^(ω)∝e−ω2ℓ2/2\hat\kappa(\omega)\propto e^{-\omega^2\ell^2/2}: high frequencies cost exponentially much, and every function in its RKHS is real-analytic. Infinite-dimensional, yet a very small space.

Check your understanding

A kernel has Mercer eigenvalues μj=2−j\mu_j=2^{-j}. Which function has the larger RKHS norm: f1=e1f_1=e_1 or f2=0.1 e10f_2=0.1\,e_{10}?

  1. f1f_1, because its L2L^2 norm is ten times larger
  2. They are equal, because both are single eigenfunctions
  3. f2f_2: ∥f2∥2=0.01⋅210≈10.2\norm{f_2}^2=0.01\cdot2^{10}\approx10.2, against ∥f1∥2=2\norm{f_1}^2=2
  4. They cannot be compared without the eigenfunctions' formulas
Show the answer

C. f2f_2: ∥f2∥2=0.01⋅210≈10.2\norm{f_2}^2=0.01\cdot2^{10}\approx10.2, against ∥f1∥2=2\norm{f_1}^2=2

∥f∥2=∑jaj2/μj\norm{f}^2=\sum_ja_j^2/\mu_j: 1/2−1=21/2^{-1}=2 for f1f_1 and 0.01/2−10=10.240.01/2^{-10}=10.24 for f2f_2. A small coefficient on a fast-decaying direction is expensive, which is how the norm penalizes roughness.

The representer theorem

DerivationProof
  1. f=fS+f⊥,fS∈S,⟨f⊥,k(xi,⋅)⟩H=0(i=1,…,n)f=f_S+f_\perp,\qquad f_S\in S,\qquad\langle f_\perp,k(x_i,\cdot)\rangle_{\mathcal H}=0\quad(i=1,\dots,n)

    Split any ff into its projection onto S=span⁡{k(x1,⋅),…,k(xn,⋅)}S=\operatorname{span}\{k(x_1,\cdot),\dots,k(x_n,\cdot)\} and the orthogonal rest:

  2. f(xi)=⟨fS+f⊥, k(xi,⋅)⟩=fS(xi)+0f(x_i)=\langle f_S+f_\perp,\,k(x_i,\cdot)\rangle=f_S(x_i)+0

    The rest is invisible at the data, by the reproducing property:

  3. J(f)=L(fS(x1),…,fS(xn))+Ω(∥fS∥2+∥f⊥∥2) ≥ J(fS)J(f)=L\big(f_S(x_1),\dots,f_S(x_n)\big)+\Omega\Big(\sqrt{\norm{f_S}^2+\norm{f_\perp}^2}\Big)\ \ge\ J(f_S)

    So the loss term is unchanged when f⊥f_\perp is dropped, while Pythagoras, ∥f∥2=∥fS∥2+∥f⊥∥2\norm f^2=\norm{f_S}^2+\norm{f_\perp}^2, can only lower the penalty:

  4. min⁡f∈HJ(f)=min⁡α∈Rn L(Kα)+Ω(α⊤Kα)\min_{f\in\mathcal H}J(f)=\min_{\boldsymbol\alpha\in\R^n}\ L(K\boldsymbol\alpha)+\Omega\Big(\sqrt{\boldsymbol\alpha^\top K\boldsymbol\alpha}\Big)

    With Ω\Omega strictly increasing the inequality is strict unless f⊥=0f_\perp=0, so every minimizer lies in SS. Writing f=∑iαik(xi,⋅)f=\sum_i\alpha_ik(x_i,\cdot) gives (f(x1),…,f(xn))=Kα(f(x_1),\dots,f(x_n))=K\boldsymbol\alpha and ∥f∥2=α⊤Kα\norm f^2=\boldsymbol\alpha^\top K\boldsymbol\alpha: a search over a space of functions has become a search over Rn\R^n.

Three consequences:

  • Kernel ridge regression. L=∑i(yi−f(xi))2L=\sum_i(y_i-f(x_i))^2 and Ω(t)=λt2\Omega(t)=\lambda t^2 give min⁡α∥y−Kα∥2+λα⊤Kα\min_{\boldsymbol\alpha}\norm{\mathbf y-K\boldsymbol\alpha}^2+\lambda\boldsymbol\alpha^\top K\boldsymbol\alpha, whose gradient 2K((K+λI)α−y)2K\big((K+\lambda I)\boldsymbol\alpha-\mathbf y\big) vanishes at α=(K+λI)−1y\boldsymbol\alpha=(K+\lambda I)^{-1}\mathbf y. This is the formula of The Kernel Trick, now justified for every kernel, including those with no finite feature map.
  • Support vector machines. The hinge loss with Ω(t)=t2/2\Omega(t)=t^2/2 gives the expansion over training points; the offset bb is unpenalized, which the semiparametric version of the theorem covers by adding a finite-dimensional unpenalized part (Schölkopf, Herbrich & Smola, 2001).
  • Splines. Kimeldorf and Wahba's original setting. Smoothing splines minimize ∑i(yi−f(xi))2+λ∫f′′2\sum_i(y_i-f(x_i))^2+\lambda\int f''^2, an RKHS seminorm whose null space, the straight lines, goes unpenalized; the minimizer is a natural cubic spline with knots at the data (Splines & Additive Models).

The representer theorem is the precise sense in which kernel methods fit "a linear model in feature space" without ever leaving the span of the data.

Predict before you look

Take the Brownian-motion kernel k(x,z)=min⁡(x,z)k(x,z)=\min(x,z) on [0,1][0,1]. Among all ff in its RKHS with f(0.5)=1f(0.5)=1, the representer theorem says the smallest norm is achieved by some f=αmin⁡(0.5,⋅)f=\alpha\min(0.5,\cdot). What is that smallest squared norm, ∫01f′(t)2 dt\int_0^1f'(t)^2\,dt?

Show the answer

2

f(0.5)=αk(0.5,0.5)=α/2=1f(0.5)=\alpha k(0.5,0.5)=\alpha/2=1 gives α=2\alpha=2, so f(x)=2min⁡(0.5,x)f(x)=2\min(0.5,x): a ramp of slope 2 up to x=0.5x=0.5, flat afterwards, with ∫00.54 dt=2=1/k(0.5,0.5)\int_0^{0.5}4\,dt=2=1/k(0.5,0.5). Any other function must still climb from 0 to 1 by x=0.5x=0.5, and by Cauchy–Schwarz ∫00.5f′2≥(∫00.5f′)2/0.5=2\int_0^{0.5}f'^2\ge\big(\int_0^{0.5}f'\big)^2/0.5=2. With several data points, sums of ramps give the piecewise-linear interpolant through the origin and the data.

Think first Show that the optimal value of kernel ridge regression, divided by λ\lambda, equals y⊤(K+λI)−1y\mathbf y^\top(K+\lambda I)^{-1}\mathbf y: that is, min⁡f∈H[λ−1∑i(yi−f(xi))2+∥f∥H2]=y⊤(K+λI)−1y\min_{f\in\mathcal H}\big[\lambda^{-1}\sum_i(y_i-f(x_i))^2+\norm f^2_{\mathcal H}\big]=\mathbf y^\top(K+\lambda I)^{-1}\mathbf y.

At the minimizer α=(K+λI)−1y\boldsymbol\alpha=(K+\lambda I)^{-1}\mathbf y the residuals are y−Kα=λ(K+λI)−1y\mathbf y-K\boldsymbol\alpha=\lambda(K+\lambda I)^{-1}\mathbf y and ∥f∥2=α⊤Kα\norm f^2=\boldsymbol\alpha^\top K\boldsymbol\alpha. Adding λ−1\lambda^{-1} times the squared residuals to the norm gives y⊤(K+λI)−1(λI+K)(K+λI)−1y=y⊤(K+λI)−1y\mathbf y^\top(K+\lambda I)^{-1}(\lambda I+K)(K+\lambda I)^{-1}\mathbf y=\mathbf y^\top(K+\lambda I)^{-1}\mathbf y. Gaussian processes report this quantity, multiplied by −12-\tfrac12 and with λ=σn2\lambda=\sigma_n^2, as the "data fit" part of their log marginal likelihood.

Universal kernels and learning rates

Universality is what makes kernel methods universally consistent: with a universal kernel and a regularization λn→0\lambda_n\to0 slowly enough as n→∞n\to\infty, SVMs and related regularized kernel classifiers reach the Bayes risk for every data distribution (Steinwart, 2005). It says nothing about speed, and by the no-free-lunch theorem no rate holds for all distributions. Rates need assumptions, and for kernel methods the natural ones are spectral: how fast the eigenvalues μj\mu_j of TkT_k decay (a measure of the space's size), and how smooth the target is relative to the kernel.

DerivationWhere the rate comes from (heuristic)
  1. a^j≈μjμj+λ aj+noisej\hat a_j\approx\frac{\mu_j}{\mu_j+\lambda}\,a_j+\text{noise}_j

    Kernel ridge regression is a spectral filter. In the eigenbasis of TkT_k, the jj-th coefficient aja_j of the target is kept with weight μj/(μj+λ)\mu_j/(\mu_j+\lambda): directions with μj≫λ\mu_j\gg\lambda pass, those with μj≪λ\mu_j\ll\lambda are suppressed.

  2. variance≈σ2n N(λ),N(λ)=∑jμjμj+λ≍λ−1/b  when μj≍j−b\text{variance}\approx\frac{\sigma^2}n\,\mathcal N(\lambda),\qquad\mathcal N(\lambda)=\sum_j\frac{\mu_j}{\mu_j+\lambda}\asymp\lambda^{-1/b}\ \text{ when }\mu_j\asymp j^{-b}

    Variance. Each passed direction carries noise of order σ2/n\sigma^2/n; the number of directions that pass is the effective dimension:

  3. bias2=∑j(λμj+λ)2aj2=∑j(λμj+λ)2μj c gj2μj≤λcR2\text{bias}^2=\sum_j\Big(\frac{\lambda}{\mu_j+\lambda}\Big)^2a_j^2=\sum_j\Big(\frac{\lambda}{\mu_j+\lambda}\Big)^2\mu_j^{\,c}\,\frac{g_j^2}{\mu_j}\le\lambda^cR^2

    Bias. What the filter removes. Writing aj=μj(c−1)/2gja_j=\mu_j^{(c-1)/2}g_j with ∑jgj2/μj≤R2\sum_jg_j^2/\mu_j\le R^2, and using (λ/(μ+λ))2μc≤λc(\lambda/(\mu+\lambda))^2\mu^c\le\lambda^c for 0≤c≤20\le c\le2:

  4. λ≍n−b/(bc+1)⟹∥f^−f⋆∥L22≍n−bc/(bc+1)\lambda\asymp n^{-b/(bc+1)}\quad\Longrightarrow\quad\norm{\hat f-f^\star}^2_{L^2}\asymp n^{-bc/(bc+1)}

    Balance λc\lambda^c against λ−1/b/n\lambda^{-1/b}/n. For a Sobolev space of smoothness ss in dd dimensions, b=2s/db=2s/d, and with c=1c=1 the rate is n−2s/(2s+d)n^{-2s/(2s+d)}, the classical minimax rate for ss-smooth regression, which collapses as dd grows (The Curse of Dimensionality).

Key takeaways

  • A positive-definite kernel and its RKHS determine each other (Moore–Aronszajn). The reproducing property f(x)=⟨f,k(x,⋅)⟩f(x)=\langle f,k(x,\cdot)\rangle makes point evaluation continuous: ∣f(x)∣≤∥f∥Hk(x,x)\abs{f(x)}\le\norm f_{\mathcal H}\sqrt{k(x,x)}.
  • Mercer: k(x,z)=∑jμjej(x)ej(z)k(x,z)=\sum_j\mu_je_j(x)e_j(z) and ∥f∥H2=∑jaj2/μj\norm f^2_{\mathcal H}=\sum_ja_j^2/\mu_j, so the norm penalizes components along small-eigenvalue, typically rough, directions; in Fourier terms it is ∫∣f^∣2/κ^\int\abs{\hat f}^2/\hat\kappa.
  • Representer theorem: any minimizer of a data loss plus a strictly increasing function of ∥f∥H\norm f_{\mathcal H} lies in span⁡{k(xi,⋅)}\operatorname{span}\{k(x_i,\cdot)\}, which turns kernel ridge regression, SVMs and smoothing splines into nn-dimensional problems.
  • Universal kernels such as the Gaussian approximate every continuous function, which yields universal consistency. Rates come from eigenvalue decay bb and smoothness cc: n−bc/(bc+1)n^{-bc/(bc+1)} for kernel ridge regression, n−2s/(2s+d)n^{-2s/(2s+d)} for Sobolev classes.

Check yourself

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

Question 1

In an RKHS, why does convergence in norm imply convergence at every point?

  1. Because ∣f(x)−g(x)∣≤∥f−g∥Hk(x,x)\abs{f(x)-g(x)}\le\norm{f-g}_{\mathcal H}\sqrt{k(x,x)}, by the reproducing property and Cauchy–Schwarz
  2. Because the RKHS norm is the supremum norm
  3. Because every function in an RKHS is differentiable
  4. It does not: like L2L^2, an RKHS only controls averages
Show the answer

A. Because ∣f(x)−g(x)∣≤∥f−g∥Hk(x,x)\abs{f(x)-g(x)}\le\norm{f-g}_{\mathcal H}\sqrt{k(x,x)}, by the reproducing property and Cauchy–Schwarz

f(x)−g(x)=⟨f−g,k(x,⋅)⟩f(x)-g(x)=\langle f-g,k(x,\cdot)\rangle, and Cauchy–Schwarz bounds it by ∥f−g∥ ∥k(x,⋅)∥=∥f−g∥k(x,x)\norm{f-g}\,\norm{k(x,\cdot)}=\norm{f-g}\sqrt{k(x,x)}. With a bounded kernel the convergence is even uniform.

Question 2

A kernel has eigenvalues μj=2−j\mu_j=2^{-j} and orthonormal eigenfunctions eje_j. Which f=∑jajejf=\sum_ja_je_j lies in its RKHS?

  1. aj=1/ja_j=1/j
  2. aj=2−j/2a_j=2^{-j/2}
  3. aj=1/j2a_j=1/j^2
  4. aj=2−ja_j=2^{-j}
Show the answer

D. aj=2−ja_j=2^{-j}

∑jaj2/μj=∑j4−j 2j=∑j2−j=1<∞\sum_ja_j^2/\mu_j=\sum_j4^{-j}\,2^{j}=\sum_j2^{-j}=1<\infty. Membership requires the coefficients to decay faster than μj\sqrt{\mu_j}; every other choice fails that, although all of them are in L2L^2.

Question 3

In the proof of the representer theorem, why is the loss term unchanged when the component f⊥f_\perp, orthogonal to every k(xi,⋅)k(x_i,\cdot), is removed?

  1. Because f⊥f_\perp has a small norm, so it barely moves the predictions
  2. Because the loss is convex, so its minimum lies in the span
  3. Because f⊥(xi)=⟨f⊥,k(xi,⋅)⟩=0f_\perp(x_i)=\langle f_\perp,k(x_i,\cdot)\rangle=0 at every training point
  4. Because f⊥f_\perp is the zero function
Show the answer

C. Because f⊥(xi)=⟨f⊥,k(xi,⋅)⟩=0f_\perp(x_i)=\langle f_\perp,k(x_i,\cdot)\rangle=0 at every training point

The reproducing property turns "orthogonal to k(xi,⋅)k(x_i,\cdot)" into "zero at xix_i". The loss sees only the values at the training points, so f⊥f_\perp costs norm and buys nothing. No convexity is needed: the theorem holds for any loss LL.

Question 4

Which kernel on [0,1][0,1] is universal, so that its RKHS is dense in the continuous functions?

  1. (1+xz)5(1+xz)^5
  2. exp⁡(−(x−z)2/(2ℓ2))\exp\big(-(x-z)^2/(2\ell^2)\big)
  3. min⁡(x,z)\min(x,z)
  4. xzxz
Show the answer

B. exp⁡(−(x−z)2/(2ℓ2))\exp\big(-(x-z)^2/(2\ell^2)\big)

The Gaussian kernel is universal on every compact subset of Rd\R^d (Steinwart, 2001). The others are not, for different reasons: two have finite-dimensional RKHSs, and the third has an infinite-dimensional RKHS whose functions all vanish at x=0x=0.

Further reading

  • N. Aronszajn, "Theory of reproducing kernels," Transactions of the American Mathematical Society 68(3), 337–404 (1950).
  • B. Schölkopf, R. Herbrich & A. J. Smola, "A generalized representer theorem," COLT 2001, Lecture Notes in Computer Science 2111, 416–426 (Springer, 2001).
  • I. Steinwart, "On the influence of the kernel on the consistency of support vector machines," Journal of Machine Learning Research 2, 67–93 (2001).
  • A. Caponnetto & E. De Vito, "Optimal rates for the regularized least-squares algorithm," Foundations of Computational Mathematics 7(3), 331–368 (2007).
  • I. Steinwart & A. Christmann, Support Vector Machines (Springer, 2008).