Foundations to Frontier
Tests
B. Statistical Learning Theory › B3 Kernel methods

Positive Definite Kernels and Mercer's Theorem

Which similarity functions are secretly inner products? Exactly the positive (semi)definite ones: every Gram matrix they produce has non-negative eigenvalues. This topic gives the definition and how to test it, the closure rules (sums, products, limits, exponentials) that build new kernels from old, the classic failures (the sigmoid 'kernel', plain distances), and Mercer's theorem, which writes a continuous kernel as a sum of eigenvalue-weighted eigenfunctions. That spectrum explains smoothness and approximability. In the research exercise you recover Mercer eigenvalues and eigenfunctions numerically (Nyström) and compare them with exact formulas.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Not every similarity is a kernel

You could invent any “similarity score” between data points, but only some of them behave like real geometry: like measuring angles and lengths in some (possibly enormous) space. Those are kernels. The test is simple to state: write all pairwise similarities in a table (the Gram matrix). If the table never says that some combination of points has a negative squared length, the similarity is a legitimate kernel.

Is it a kernel? Gram matrices, eigenvalues and Mercer eigenfunctions
1e01e-21e-41e-61e-8|λᵢ| / |λ|max (log), orange = negativetop 3 eigenfunctions (√n · eigenvector)
✅ positive semidefinite: all 40 eigenvalues ≥ 0 · λ₁ = 0.2410 · top-5 share of the trace 85.9%
Left: the Gram matrix K/n (blue positive, orange negative). Middle: its eigenvalues on a log scale. Right: the leading eigenvectors, which approximate the Mercer eigenfunctions. A function is a kernel exactly when every such Gram matrix is positive semidefinite. Smooth kernels (RBF) have eigenvalues that collapse geometrically, rough ones (Laplace, Brownian) decay polynomially, and |x − y| and the sigmoid fail the test. Brownian motion's eigenfunctions are √2 sin((j − ½)πx).
Why engineers care

Using a function that isn’t positive definite in an SVM or a Gaussian process breaks the optimization (the problem stops being convex) or produces negative variances, which means nonsense uncertainty for a robot’s terrain model. Knowing the rules also lets you design kernels that encode physics: periodicity for orbits, smoothness for trajectories.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A valid kernel's Gram matrix has…
  2. 2. Is every similarity score a kernel?
  3. 3. A kernel corresponds to an inner product in…

Level 1: Beginner

★★☆☆☆ Basic⏱ 25 minSecondary-school mathematics: arithmetic and elementary algebra.

Definition

A symmetric function k is positive (semi)definite if, for every finite set x1,…,xmx_1, \dots, x_m and every vector c∈Rmc\in\mathbb R^m,

∑i,jcicjk(xi,xj)≥0,\sum_{i,j}c_ic_jk(x_i, x_j)\ge0,

so every Gram matrix is PSD. Feature-map kernels qualify: the sum equals ∥∑iciφ(xi)∥2≥0\|\sum_ic_i\varphi(x_i)\|^2\ge0.

Quick tests

  • The diagonal must be non-negative: k(x,x)≥0k(x, x)\ge0.
  • Cauchy–Schwarz: k(x,z)2≤k(x,x) k(z,z)k(x, z)^2\le k(x, x)\,k(z, z).
  • For two points, (1aa1)\begin{pmatrix}1 & a\\ a & 1\end{pmatrix} is PSD exactly when |a| ≤ 1.

The plain distance |x − z| fails at once: its 2×2 Gram matrix has zero diagonal and eigenvalues ±|x − z|.

📝 Quick check (Level 1)
0/3 answered
  1. 1. Eigenvalues of [[0, 3], [3, 0]]:
  2. 2. If k(x, x) = 4 and k(z, z) = 9, then |k(x, z)| is at most…
  3. 3. Feature-map kernels are PSD because Σcᵢcⱼk(xᵢ, xⱼ) equals…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 40 minUndergraduate students and practising engineers.

Closure rules

If k1,k2k_1, k_2 are kernels, a ≥ 0, f is any function and p is a polynomial with non-negative coefficients, then these are kernels:

  • ak1+k2ak_1 + k_2 (sum)
  • k1k2k_1k_2 (product, by the Schur product theorem)
  • f(x)k1(x,z)f(z)f(x)k_1(x, z)f(z) (rescaling)
  • p(k1)p(k_1) and exp⁡(k1)\exp(k_1) (limits of sums and products)
  • k1/k1(x,x)k1(z,z)k_1/\sqrt{k_1(x, x)k_1(z, z)} (normalization)

Example: e−∥x−z∥2/2=e−∥x∥2/2 ex⋅z e−∥z∥2/2e^{-\|x - z\|^2/2} = e^{-\|x\|^2/2}\,e^{x\cdot z}\,e^{-\|z\|^2/2} is a rescaled exp⁡(x⋅z)\exp(x\cdot z), so the RBF is a kernel.

Classic non-kernels

  • tanh⁡(ax⋅z+c)\tanh(ax\cdot z + c): the “sigmoid kernel” of early SVMs. It is PSD only for some parameters and data.
  • ∥x−z∥\|x - z\| and −∥x−z∥-\|x - z\|.
  • exp⁡(−∥x−z∥p)\exp(-\|x - z\|^p) with p greater than 2.
🐍 Exercise 1: which of these are kernels?
Build Gram matrices on 40 random 2-D points for eight candidate similarity functions, compute the smallest eigenvalue relative to the largest, and classify each as PSD or not. Then show that two points already expose the distance 'kernel'.
📝 Quick check (Level 2)
0/3 answered
  1. 1. The product of two kernels is a kernel by…
  2. 2. exp(x·z) is a kernel because…
  3. 3. The sigmoid tanh(a x·z + c) is…

Level 3: Advanced

★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.

Mercer’s theorem

Let k be a continuous PSD kernel on a compact set with a measure p. The integral operator (Tkf)(x)=∫k(x,x′)f(x′)p(x′) dx′(T_kf)(x) = \int k(x, x')f(x')p(x')\,dx' is compact, self-adjoint and positive. Its eigenpairs (λj,ϕj)(\lambda_j, \phi_j), with λj≥0\lambda_j\ge0 and the ϕj\phi_j orthonormal in L2(p)L^2(p), give

k(x,z)=∑jλjϕj(x)ϕj(z),k(x, z) = \sum_j\lambda_j\phi_j(x)\phi_j(z),

converging absolutely and uniformly. So φ(x)=(λjϕj(x))j\varphi(x) = (\sqrt{\lambda_j}\phi_j(x))_j is an explicit feature map, and ∑jλj=∫k(x,x)p(x) dx\sum_j\lambda_j = \int k(x, x)p(x)\,dx.

Examples

  • Brownian motion min⁡(x,z)\min(x, z) on [0, 1]: λj=1/((j−12)2π2)\lambda_j = 1/((j - \tfrac12)^2\pi^2), ϕj=2sin⁡((j−12)πx)\phi_j = \sqrt2\sin((j - \tfrac12)\pi x). Polynomial decay: rough sample paths.
  • RBF with Gaussian p: geometric decay λj∝Bj\lambda_j\propto B^j. Smooth functions, low effective dimension.

Nyström

Sampling x1,…,xm∼px_1, \dots, x_m\sim p, the eigenvalues of K/m approximate the λj\lambda_j, and m\sqrt m times the eigenvectors approximate ϕj\phi_j at the samples.

📝 Quick check (Level 3)
0/3 answered
  1. 1. Mercer's eigenvalues sum to…
  2. 2. Faster eigenvalue decay means…
  3. 3. The Nyström estimate of λⱼ is…

Level 4: Expert

★★★★★ Expert⏱ 35 minResearchers: original papers and open problems.

Mercer, measured

Exercise 1. The smallest/largest eigenvalue ratios are: RBF ≈ 1e-10, cubic polynomial ≈ 0 (it has rank 10 in 2-D), Laplace 0.008, RBF × quadratic ≈ 1e-9, exp(x·z) ≈ 5e-12. All are PSD up to round-off. The sigmoid (−0.74), distance (−0.31) and negative distance (−1) fail clearly.

Exercise 2. With 800 samples, Nyström gives λ₁ = 0.422 for Brownian motion (exact 4/π² = 0.405), and its top eigenvector matches √2 sin(πx/2) with correlation above 0.999. For the RBF kernel (ℓ = σ = 1), the estimates 0.630, 0.233, 0.086 and 0.031 track the exact 0.618, 0.236, 0.090 and 0.034, a geometric series with ratio (3 − √5)/2 ≈ 0.382. The top 10 eigenvalues capture all but 7 × 10⁻⁵ of the RBF trace, but miss 2% of the Brownian trace. Smooth kernels are effectively low-rank, which is why Nyström and random-feature approximations work so well for them.

🐍 Exercise 2 (research): Mercer eigenpairs by Nyström
Estimate Mercer eigenvalues and eigenfunctions of the Brownian-motion kernel min(x, y) under the uniform measure and of the RBF kernel under a Gaussian measure, compare them with the exact formulas, and measure how much of the trace the top 10 eigenvalues capture.

Kernel design in AI, robotics and aerospace

  • GP kernels with physics: periodic kernels for orbital or gait data, sums for multi-scale signals, products for interactions.
  • Kernel validity checks before deploying GP-based safe-control (barrier) methods.
  • Spectral truncation for fast GP inference on embedded hardware.
  • Graph and string kernels for structured data such as molecular graphs and command sequences.

References

  1. J. Mercer (1909). “Functions of positive and negative type, and their connection with the theory of integral equations.” Philosophical Transactions of the Royal Society A, 209.
  2. C. E. Rasmussen, C. K. I. Williams (2006). Gaussian Processes for Machine Learning. MIT Press (ch. 4).
  3. B. Schölkopf, A. J. Smola (2002). Learning with Kernels. MIT Press (ch. 2).
  4. C. K. I. Williams, M. Seeger (2001). “Using the Nyström method to speed up kernel machines.” NeurIPS.
  5. I. Steinwart, A. Christmann (2008). Support Vector Machines. Springer (ch. 4).