Skip to content
nonconvexcard

Kernels, RKHS and the Representer Theorem

Positive definite kernels, the reproducing property, a complete proof of the representer theorem, and kernel ridge regression.

Classical MLGraduate⏱ 1 day13 min readkernelrkhspositive definiterepresenter theoremkernel ridge
6 problems →

Positive definite kernels

DefinitionPositive definite kernel

K:X×X→RK:\Xcal\times\Xcal\to\R is a positive definite kernel if it is symmetric, K(x,x′)=K(x′,x)K(x,x')=K(x',x), and for every finite {x1,…,xn}⊆X\{x_1,\dots,x_n\}\subseteq\Xcal the Gram matrix Kij=K(xi,xj)\mathbf{K}_{ij}=K(x_i,x_j) is positive semidefinite.

TheoremPositive definite iff an inner product of features

KK is a positive definite kernel if and only if there is a Hilbert space H\Hcal and a map ϕ:X→H\phi:\Xcal\to\Hcal with

K(x,x′)=⟨ϕ(x),ϕ(x′)⟩Hfor all x,x′.K(x,x') = \ip{\phi(x)}{\phi(x')}_\Hcal \qquad\text{for all } x,x' .
TheoremConstruction of the RKHS (Moore–Aronszajn)

Let KK be a positive definite kernel on X\Xcal. There is a unique Hilbert space HK\Hcal_K of real-valued functions on X\Xcal such that

  1. K(x,⋅)∈HKK(x,\cdot)\in\Hcal_K for every xx;
  2. span⁡{K(x,⋅):x∈X}\operatorname{span}\{K(x,\cdot):x\in\Xcal\} is dense in HK\Hcal_K;
  3. reproducing property: f(x)=⟨f,K(x,⋅)⟩HKf(x) = \ip{f}{K(x,\cdot)}_{\Hcal_K} for every f∈HKf\in\Hcal_K and x∈Xx\in\Xcal.

Key idea

The two halves of the reproducing property are worth separating. It says (a) evaluation at xx is a continuous linear functional on HK\Hcal_K — which is the defining property of an RKHS and is false in, say, L2L^2, where pointwise values are not even defined; and (b) that functional is represented by K(x,⋅)K(x,\cdot). Everything computational about kernels follows from (b), and everything about well-posedness of pointwise learning follows from (a).

The representer theorem

TheoremRepresenter theorem

Let HK\Hcal_K be the RKHS of KK, let Ω:[0,∞)→R\Omega:[0,\infty)\to\R be strictly increasing, and let c:Rn→Rc:\R^n\to\R be arbitrary. Then any minimiser of

J(f)=c(f(x1),…,f(xn))+Ω(∥f∥HK)J(f) = c\big(f(x_1),\dots,f(x_n)\big) + \Omega\big(\norm{f}_{\Hcal_K}\big)

over f∈HKf\in\Hcal_K admits a representation

f⋆=∑i=1nαiK(xi,⋅),α∈Rn.f^\star = \sum_{i=1}^n\alpha_iK(x_i,\cdot), \qquad \alpha\in\R^n .

Key idea

An infinite-dimensional optimisation problem has been reduced to nn real numbers, and the reduction is exact, not an approximation. Note precisely what made it work: the loss depends on ff only through its values at the nn data points, and the penalty is a strictly increasing function of the norm. Both hypotheses are essential — a penalty like ∥f′∥L2\norm{f'}_{L^2} that is not a function of ∥f∥HK\norm{f}_{\Hcal_K}, or a loss involving ff at unseen points, breaks the conclusion.

Run it: Kernel ridge regressionThe fitted function of kernel ridge regression as bandwidth and regularisation vary.
PropositionKernel ridge regression in closed form

For the squared loss with regularisation λ\lambda,

f^=arg min⁡f∈HK{1n∑i=1n(yi−f(xi))2+λ∥f∥HK2}=∑i=1nαiK(xi,⋅),α=(K+nλI)−1y.\hat f = \argmin_{f\in\Hcal_K}\left\{\frac1n\sum_{i=1}^n\big(y_i-f(x_i)\big)^2 + \lambda\norm f_{\Hcal_K}^2\right\} = \sum_{i=1}^n\alpha_iK(x_i,\cdot), \qquad \alpha = (\mathbf{K}+n\lambda I)^{-1}y .

Building kernels

PropositionOperations preserving positive definiteness

Let K1,K2K_1,K_2 be positive definite kernels on X\Xcal, c>0c>0, f:X→Rf:\Xcal\to\R, and ψ:X′→X\psi:\Xcal'\to\Xcal. Then the following are positive definite:

cK1,K1+K2,K1K2,f(x)f(x′),K1(ψ(x),ψ(x′)),exp⁡(K1),lim⁡nKn (pointwise, if it exists).cK_1,\quad K_1+K_2,\quad K_1K_2,\quad f(x)f(x'),\quad K_1(\psi(x),\psi(x')),\quad \exp(K_1),\quad \lim_n K_n \text{ (pointwise, if it exists)} .

The Gaussian kernel is positive definite

  1. K(x,x′)=exp⁡(−∥x−x′∥222σ2)=exp⁡(−∥x∥22σ2)exp⁡(⟨x,x′⟩σ2)exp⁡(−∥x′∥22σ2).K(x,x') = \exp\left(-\frac{\norm{x-x'}_2^2}{2\sigma^2}\right) = \exp\left(-\frac{\norm x^2}{2\sigma^2}\right)\exp\left(\frac{\ip{x}{x'}}{\sigma^2}\right)\exp\left(-\frac{\norm{x'}^2}{2\sigma^2}\right).

    Expand the exponent.

  2. ⟨x,x′⟩/σ2\ip{x}{x'}/\sigma^2 is PD (it is an inner product of features, namely x/σx/\sigma), and exp⁡\exp of a PD kernel is PD.

    The middle factor is the exponential of the linear kernel, hence PD by the closure proposition.

  3. With f(x)=exp⁡(−∥x∥2/2σ2)f(x)=\exp(-\norm x^2/2\sigma^2), K=f(x)f(x′)⋅exp⁡(⟨x,x′⟩/σ2)K = f(x)f(x')\cdot\exp(\ip{x}{x'}/\sigma^2) is a product of two PD kernels.

    The outer factors form a rank-one kernel f(x)f(x'), which is PD, and the product of PD kernels is PD.

Standard kernels and the feature spaces they correspond to:

KernelFormulaFeature space
Linear⟨x,x′⟩\ip{x}{x'}Rd\R^d itself
Polynomial(1+⟨x,x′⟩)m(1+\ip{x}{x'})^mall monomials of degree ≤m\le m, dimension (d+mm)\binom{d+m}{m}
Gaussian (RBF)exp⁡(−∥x−x′∥2/2σ2)\exp(-\norm{x-x'}^2/2\sigma^2)infinite-dimensional
Laplaceexp⁡(−∥x−x′∥1/σ)\exp(-\norm{x-x'}_1/\sigma)infinite-dimensional
Cosine similarity⟨x,x′⟩/(∥x∥∥x′∥)\ip{x}{x'}/(\norm x\norm{x'})normalised Rd\R^d

The cost

PropositionKernel methods cost O(n²) memory and O(n³) time

Forming K\mathbf{K} requires n2n^2 kernel evaluations and n2n^2 storage; solving (K+nλI)α=y(\mathbf{K}+n\lambda I)\alpha = y by Cholesky costs 13n3\tfrac13n^3 flops. Prediction at a new point costs nn kernel evaluations.

What this does not say

This is the reason kernel methods are not used at the scale deep learning operates at: n=107n = 10^7 makes n2=1014n^2 = 10^{14} entries impossible. The standard remedies are

  • Nyström approximation: sample m≪nm \ll n landmarks and approximate K≈KnmKmm−1Kmn\mathbf{K}\approx \mathbf{K}_{nm}\mathbf{K}_{mm}^{-1}\mathbf{K}_{mn}, reducing cost to O(nm2)O(nm^2).
  • Random features (Rahimi–Recht): for a shift-invariant kernel, K(x,x′)=Eω[zω(x)zω(x′)]K(x,x') = \E_\omega[z_\omega(x)z_\omega(x')] by Bochner's theorem, so sampling mm frequencies gives an explicit mm-dimensional feature map with O(nm)O(nm) cost.
  • Structured kernels with fast transforms.

None of these changes the statistical guarantees materially for moderate mm, and all of them make the method a finite-dimensional linear model again — which is worth noticing, because the same observation connects kernels to the neural tangent kernel picture on the deep learning theory page.

Problems

The Gaussian kernel is positive definiteProof · Intermediate · 30 min Prove the representer theoremProof · Graduate · 1 hour The reproducing property and its consequencesProof · Advanced · 30 min Kernel ridge regression in closed formProof · Intermediate · 30 min Implement kernel ridge regressionCoding · Intermediate · 1 hour The Schur product theoremProof · Advanced · 30 min

References

  • BookBernhard Schölkopf and Alexander J. Smola (2002). Learning with Kernels
  • PaperNachman Aronszajn (1950). Theory of Reproducing Kernels
  • BookIngo Steinwart and Andreas Christmann (2008). Support Vector MachinesThe most careful modern treatment of RKHS theory for learning.
  • PaperAli Rahimi and Benjamin Recht (2007). Random Features for Large-Scale Kernel Machines

These works are cited as sources to read, not reproduced. All exposition, examples and problems on this site are written independently; where an argument is standard, the citation points to a canonical treatment.

Results stated on this page

Experiments

Problems (6)

All problems

Papers that use this mathematics