Module contents
Lesson 13 of 20Core 110 min

Reproducing kernel Hilbert spaces and the representer theorem

Develop kernel theory through RKHS construction, continuous evaluation and reproduction, the representer theorem, Mercer spectral decomposition and Rademacher bounds for RKHS balls.

After this lesson you can

  • Characterize an RKHS through continuous evaluations and obtain its kernel using Riesz representation.
  • Construct the RKHS of a kernel by Moore-Aronszajn and use reproduction to evaluate and bound functions.
  • Prove the representer theorem for arbitrary losses and a norm-increasing regularizer.
  • State Mercer’s theorem and interpret eigenvalue decay as smoothness.
  • Prove the empirical Rademacher bound B√(tr K)/n for an RKHS ball.

Before you start

A function space for the kernel

A symmetric kernel k:X×X→Rk:X\times X\to\mathbb R is positive semidefinite if for any finite list x1,…,xnx_1,\ldots,x_n and a∈Rna\in\mathbb R^n, a⊤Ka≥0a^\top Ka\ge0, with Kij=k(xi,xj)K_{ij}=k(x_i,x_j). The kernel trick computes products between features without writing them down. To understand learned functions and their regularization, we need a Hilbert space: a vector space with an inner product complete in its norm. Completeness guarantees, among other things, that a Cauchy sequence converges inside the space; a closed subspace admits orthogonal projection.

A reproducing kernel Hilbert space H\mathcal H is a space of functions where every evaluation Ex:f↦f(x)E_x:f\mapsto f(x) is continuous. By Riesz there is a unique kx∈Hk_x\in\mathcal H such that f(x)=⟨f,kx⟩Hf(x)=\langle f,k_x\rangle_\mathcal H. Define k(x,y)=⟨kx,ky⟩k(x,y)=\langle k_x,k_y\rangle. It is positive semidefinite because a⊤Ka=∥∑iaikxi∥2≥0a^\top Ka=\|\sum_i a_i k_{x_i}\|^2\ge0. Conversely, if a section kx=k(x,⋅)∈Hk_x=k(x,\cdot)\in\mathcal H exists with that identity, Cauchy-Schwarz gives ∣f(x)∣≤∥f∥k(x,x)|f(x)|\le\|f\|\sqrt{k(x,x)} and evaluation is continuous. This is the reproducing property.

Build it from a Gram matrix

The Moore-Aronszajn theorem constructs a unique RKHS for each positive semidefinite kernel. Begin with finite combinations f=∑iαik(xi,⋅)f=\sum_i\alpha_i k(x_i,\cdot) and define

⟨∑iαik(xi,⋅),∑jβjk(yj,⋅)⟩=∑i,jαiβjk(xi,yj).\left\langle\sum_i\alpha_i k(x_i,\cdot),\sum_j\beta_j k(y_j,\cdot)\right\rangle =\sum_{i,j}\alpha_i\beta_j k(x_i,y_j).

Positivity guarantees nonnegative norm. If different representations have a zero-norm difference, Cauchy-Schwarz shows that difference evaluates to zero everywhere, so they represent the same function. Identify those null differences and complete the pre-Hilbert space. Evaluations extend to the completion and the reproducing identity persists. Gram matrices need not all be invertible: semidefiniteness allows zero eigenvalues and nonunique representations.

Cauchy-Schwarz applied to kx−kx′k_x-k_{x'} yields

∣f(x)−f(x′)∣≤∥f∥Hk(x,x)−2k(x,x′)+k(x′,x′).|f(x)-f(x')|\le\|f\|_\mathcal H\sqrt{k(x,x)-2k(x,x')+k(x',x')}.

For a ball of radius BB, this controls variation in the geometry induced by the kernel. If also k(0,0)=1k(0,0)=1 and f(0)=af(0)=a with ∣a∣≤B|a|\le B, decompose f=ak0+gf=ak_0+g with g⊥k0g\perp k_0. The exact pointwise envelope is ak(x,0)±B2−a2k(x,x)−k(x,0)2ak(x,0)\pm\sqrt{B^2-a^2}\sqrt{k(x,x)-k(x,0)^2}. Each endpoint at a point can be attained by a different function; no single function is promised to follow the whole envelope.

InteractiveWhat the norm permits
  • upper envelope
  • lower envelope
  • minimum projection
Kernel
0.5
1.0
Fixed value f(0)0.6
Available orthogonal norm0.800
Compare Gaussian and Laplace: the envelope simultaneously imposes the norm and the value f(0)=0.6.

On the real line, Laplace kernel e−∣x−y∣/ℓe^{-|x-y|/\ell} has spectral density proportional to (ℓ−2+ω2)−1(\ell^{-2}+\omega^2)^{-1}; its RKHS is equivalent to Sobolev space H1H^1 with a norm depending on ℓ\ell. Gaussian e−(x−y)2/(2ℓ2)e^{-(x-y)^2/(2\ell^2)} weights high frequencies exponentially in its Fourier norm, under suitable transformability conditions. Smoothness here means belonging to a ball of that RKHS, not that every smooth function has small norm. Changing kernel width also changes the space and the function associated with fixed coefficients.

InteractiveBuild a function and pay its norm
Kernel
0.5
1.0
-1.0
1.0
Squared norm2.459
Norm1.568
Adjust three coefficients; the function and exact norm αᵀKα are shown.

The Gaussian RKHS is dense in C(X)C(X) for compact XX: a continuous function can be approximated uniformly as closely as desired. Density does not imply membership or bound the approximation’s norm. On a nontrivial real interval, for example, a nonzero constant does not belong to the restricted Gaussian RKHS, although it can be approximated uniformly. For a finite set the situation changes; do not extrapolate that exclusion to every compact set.

Project while preserving the data

Let V=span⁡{k(xi,⋅):1≤i≤n}V=\operatorname{span}\{k(x_i,\cdot):1\le i\le n\} and decompose f=f∥+f⊥f=f_\parallel+f_\perp with f⊥⊥Vf_\perp\perp V. By reproduction, f⊥(xi)=0f_\perp(x_i)=0 for every datum; by Pythagoras, ∥f∥2=∥f∥∥2+∥f⊥∥2\|f\|^2=\|f_\parallel\|^2+\|f_\perp\|^2. In an objective

L(f(x1),…,f(xn))+Ω(∥f∥H),L(f(x_1),\ldots,f(x_n))+\Omega(\|f\|_\mathcal H),

the loss does not change under projection. If Ω\Omega is nondecreasing, a projected minimizer in VV exists whenever any minimizer exists; if it is strictly increasing, every minimizer belongs to VV. The loss can be nonconvex or arbitrary provided the objective is well defined. This is the representer theorem. Coefficients α\alpha need not be unique when Gram is singular, even if the projected function is.

InteractiveWhy the data suffice
  • full function
  • projection
Orthogonal component: 1.0
Projection norm²0.884
Orthogonal norm²0.190
Changes at data points0
Remove a component orthogonal to the representers: values at −1, 0 and 1 stay fixed while the norm falls.

The figure calculates the projection of k(0.5,⋅)k(0.5,\cdot) by solving a three-center Gram system. An orthogonal component can change the function away from the data; it cannot improve the stated objective if it only increases an increasing norm penalty.

Mercer and spectral features

If XX is compact, kk is continuous and positive semidefinite, and μ\mu is a finite full-support measure, the integral operator Tf(x)=∫k(x,y)f(y)dμ(y)Tf(x)=\int k(x,y)f(y)d\mu(y) is compact and self-adjoint. The Mercer theorem gives eigenvalues λj≥0\lambda_j\ge0 and orthonormal eigenfunctions in L2(μ)L^2(\mu) with

k(x,y)=∑jλjϕj(x)ϕj(y),Φ(x)=(λjϕj(x))j.k(x,y)=\sum_j\lambda_j\phi_j(x)\phi_j(y),\qquad \Phi(x)=(\sqrt{\lambda_j}\phi_j(x))_j.

Under these assumptions the expansion is uniform; zero-eigenvalue modes are omitted. In the spectral basis, a function f=∑jajϕjf=\sum_j a_j\phi_j in the corresponding class has squared RKHS norm ∑jaj2/λj\sum_j a_j^2/\lambda_j when the sum is finite. Modes with small λj\lambda_j are costly. Interpreting them as frequencies or smoothness depends on kernel and measure; an eigenvector of a finite matrix is not automatically the exact continuous eigenfunction.

InteractiveMercer eigenfunctions and spectrum
  • eigenfunction 1
  • eigenfunction 2
  • eigenfunction 3
  • eigenfunction 4
Width ℓ
First eigenvalue0.3433
Trace of K/811
Nyström on 81 uniform points in [−1,1]; change kernel width and compare modes.

Matrix K/81K/81 approximates the operator for a discretized uniform measure. Eigenvector signs are arbitrary and fixed by convention for plotting. Values below 10−1410^{-14} are clipped only on the logarithmic scale. The generate_mercer.py generator calculates eigenpairs and the trace is 1 because k(x,x)=1k(x,x)=1.

Capacity of an RKHS ball

For FB={f:∥f∥H≤B}\mathcal F_B=\{f:\|f\|_\mathcal H\le B\}, reproduction and Cauchy-Schwarz give

R^S(FB)=BnEσ∥∑iσikxi∥H≤Bn∑ik(xi,xi)=Btr⁡Kn.\widehat{\mathfrak R}_S(\mathcal F_B)=\frac Bn\mathbb E_\sigma\left\|\sum_i\sigma_i k_{x_i}\right\|_\mathcal H \le\frac Bn\sqrt{\sum_i k(x_i,x_i)}=\frac{B\sqrt{\operatorname{tr}K}}n.

Jensen is used and cross-products vanish when signs are averaged. This Rademacher bound for RKHS balls combines with contraction and a Lipschitz loss for generalization; for SVM, norm and margin must be controlled. Although feature space is infinite, if k(x,x)≤κ2k(x,x)\le\kappa^2 the bound is Bκ/nB\kappa/\sqrt n. This does not make any kernel choice free: predictor norm and diagonal can grow.

[ ]Gram, interpolation and projectionBrowser
import numpy as np
from collections import Counter
def gaussian(X,Y,ell=.5):
    X=np.asarray(X).reshape(-1,1);Y=np.asarray(Y).reshape(-1,1)
    return np.exp(-((X-Y.T)**2)/(2*ell**2))
def laplace(X,Y,ell=.5):
    X=np.asarray(X).reshape(-1,1);Y=np.asarray(Y).reshape(-1,1)
    return np.exp(-np.abs(X-Y.T)/ell)
def spectrum(strings,k=2):
    counts=[Counter(s[i:i+k] for i in range(len(s)-k+1)) for s in strings]
    return np.array([[sum(v*b.get(key,0) for key,v in a.items()) for b in counts] for a in counts],float)
X=np.array([-1.,-.3,.4,1.]); y=np.array([.2,-.5,.8,.1]); K=gaussian(X,X); alpha=np.linalg.solve(K,y)
print('interpolación máximo error',np.max(np.abs(K@alpha-y)),'norma²',round(alpha@K@alpha,6))
for name,G in [('gaussiano',K),('Laplace',laplace(X,X)),('2-gramas',spectrum(['for x','for y','if x']))]:
    print(name,'autovalor mínimo',round(np.linalg.eigvalsh(G).min(),10))
centers=np.r_[X,[-.75,0,.7,1.5]]; Kcc=gaussian(centers,centers); Kxc=gaussian(X,centers); lam=.05
coef=np.linalg.solve(Kxc.T@Kxc/len(X)+lam*Kcc,Kxc.T@y/len(X))
small=np.linalg.solve(K+len(X)*lam*np.eye(len(X)),y)
def objective(c,G,A): return np.mean((A@c-y)**2)+lam*c@G@c
print('máx coef extra',np.max(np.abs(coef[len(X):])),'objetivos',round(objective(coef,Kcc,Kxc),8),round(objective(small,K,K),8))

The Gaussian dictionary uses distinct centers and invertible Gram in this example: extra coefficients are therefore numerically zero. With dependencies, nonzero extra coefficients can represent the same function; the theorem states subspace membership, not coefficient uniqueness. For repeated data or wide bandwidths, inspect conditioning and use regularization or an appropriate pseudoinverse. The k-gram kernel is positive semidefinite because it is a product of count vectors; an arbitrary similarity does not acquire that property by being called a kernel.

[ ]Nyström and Gaussian measureBrowser
import numpy as np
from numpy.polynomial.hermite import hermgauss
ell=.8; ratio=1/ell**2
t=2*ratio/(2*ratio+1+np.sqrt(4*ratio+1))
exact=np.array([(1-t)*t**j for j in range(5)])
for n in (16,32,64):
    nodes,weights=hermgauss(n); x=np.sqrt(2)*nodes; weights=weights/np.sqrt(np.pi)
    K=np.exp(-((x[:,None]-x[None,:])**2)/(2*ell**2))
    M=np.sqrt(weights[:,None])*K*np.sqrt(weights[None,:])
    eigen=np.linalg.eigvalsh(M)[::-1][:5]
    print('n',n,'primeros',np.round(eigen,6),'error máximo',round(np.max(np.abs(eigen-exact)),8))
print('espectro analítico',np.round(exact,6))

Here the measure is N(0,1)\mathcal N(0,1) and Gauss-Hermite weights approximate the integral; it is not the figure’s uniform measure. For this Gaussian kernel the eigenvalues are (1−t)tj(1-t)t^j, with t/(1−t)2=1/ℓ2t/(1-t)^2=1/\ell^2. The spectral sum is 1. The numerical comparison and closed form appear in the Gaussian-kernel analysis of Rasmussen and Williams.

Exercises

Proof
Prove: Prove the representer theorem.
0
Decompose f into its projection onto the representers and its orthogonal complement.

Step 1 of 2. Why does empirical loss not change when the orthogonal component is removed?

Proof
Prove: Characterize RKHSs by continuous evaluations.
0
Apply Riesz to each functional E_x.

Step 1 of 2. What does Riesz provide?

Quiz
For a nontrivial compact interval, which property does the Gaussian RKHS have?
Numeric
With k(x,x)=1, B=5 and n=400, calculate B√(tr K)/n.
CodeMinimum-norm interpolant
Implement min_norm_interpolant(X,y,kernel), returning (alpha,norm), and evaluate(alpha,X,kernel,x_new). kernel(X,Y) returns a Gram matrix. Use a pseudoinverse and reject labels outside the range of K with ValueError.
def min_norm_interpolant(X, y, kernel):
  pass
def evaluate(alpha, X, kernel, x_new):
  pass
Shift+Enter to run

Summary

Key idea
An RKHS is a Hilbert space of functions with continuous evaluations. Reproduction turns evaluations into inner products; projection proves the representer theorem, and the Gram trace controls ball complexity.

Sources: generalized representer theorem and spectral analysis of kernels.