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
- 13Rademacher complexity of norm-bounded linear classesRegularized loss minimizationRademacher generalization bound
- 11Common kernels and construction rulesKernel trickGaussian RBF kernel
- 02Positive definite matrixLoewner order and PSD coneOrthogonal projectionOrthogonality
- 03Complete metric spaceL2 function space and orthogonality
A function space for the kernel
A symmetric kernel is positive semidefinite if for any finite list and , , with . 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 is a space of functions where every evaluation is continuous. By Riesz there is a unique such that . Define . It is positive semidefinite because . Conversely, if a section exists with that identity, Cauchy-Schwarz gives 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 and define
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 yields
For a ball of radius , this controls variation in the geometry induced by the kernel. If also and with , decompose with . The exact pointwise envelope is . Each endpoint at a point can be attained by a different function; no single function is promised to follow the whole envelope.
On the real line, Laplace kernel has spectral density proportional to ; its RKHS is equivalent to Sobolev space with a norm depending on . Gaussian 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.
The Gaussian RKHS is dense in for compact : 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 and decompose with . By reproduction, for every datum; by Pythagoras, . In an objective
the loss does not change under projection. If is nondecreasing, a projected minimizer in exists whenever any minimizer exists; if it is strictly increasing, every minimizer belongs to . The loss can be nonconvex or arbitrary provided the objective is well defined. This is the representer theorem. Coefficients need not be unique when Gram is singular, even if the projected function is.
The figure calculates the projection of 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 is compact, is continuous and positive semidefinite, and is a finite full-support measure, the integral operator is compact and self-adjoint. The Mercer theorem gives eigenvalues and orthonormal eigenfunctions in with
Under these assumptions the expansion is uniform; zero-eigenvalue modes are omitted. In the spectral basis, a function in the corresponding class has squared RKHS norm when the sum is finite. Modes with small 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.
Matrix approximates the operator for a discretized uniform measure. Eigenvector signs are arbitrary and fixed by convention for plotting. Values below are clipped only on the logarithmic scale. The generate_mercer.py generator calculates eigenpairs and the trace is 1 because .
Capacity of an RKHS ball
For , reproduction and Cauchy-Schwarz give
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 the bound is . This does not make any kernel choice free: predictor norm and diagonal can grow.
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.
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 and Gauss-Hermite weights approximate the integral; it is not the figure’s uniform measure. For this Gaussian kernel the eigenvalues are , with . The spectral sum is 1. The numerical comparison and closed form appear in the Gaussian-kernel analysis of Rasmussen and Williams.
Exercises
Step 1 of 2. Why does empirical loss not change when the orthogonal component is removed?
Step 1 of 2. What does Riesz provide?
def min_norm_interpolant(X, y, kernel):
pass
def evaluate(alpha, X, kernel, x_new):
passSummary
Sources: generalized representer theorem and spectral analysis of kernels.