Lesson 34 · 110 min · advanced
RKHS, Representer & Mercer's Theorem
Why does the kernel trick work, and in which space do kernel machines actually learn? This lesson defines positive-definite kernels, builds their reproducing kernel Hilbert space from scratch (the Moore–Aronszajn construction, with well-definedness, the reproducing property, definiteness via the Cauchy–Schwarz inequality for semidefinite forms, and the completion), proves the representer theorem that reduces learning in a possibly infinite-dimensional to coefficients, states Mercer's eigen-expansion and proves its finite-sample version , and writes the explicit -dimensional feature map of . It ends by showing that the quantum fidelity kernel is a positive-definite kernel with the density matrix as feature map.
Prerequisites: Kernel Methods & Support Vector Machines, Spectral Theorem & Functions of Operators
Objectives and key results
State the definition of a (real or Hermitian) positive-definite kernel and prove that every feature-map inner product is one.
Construct the RKHS of a positive-definite kernel: prove that is well defined, reproducing, and definite, and describe the completion.
Prove the representer theorem and use it to solve kernel ridge regression in closed form, .
State Mercer's theorem precisely and prove the finite-sample factorisation with .
Derive the explicit feature map of and count the dimensions of a general polynomial kernel.
Show that the fidelity kernel is positive definite.
- definition · Positive-definite kernel
- theorem · Reproducing property (Moore–Aronszajn)
- theorem · Representer theorem
- theorem · Mercer's theorem and its finite-sample form
- formula · Quadratic feature map and polynomial dimension
Positive-definite kernels#
In the support-vector-machine lesson the dual problem and the decision function touched the data only through the numbers . Two questions were left open. First, which functions may be used — when is secretly an inner product of some feature vectors? Second, in which space does the learned function live, and what does the regulariser become when is infinite-dimensional? The answer to both is the same object: the reproducing kernel Hilbert space of a positive-definite kernel. Quantum kernels (Module 3.3) are positive-definite kernels whose feature vectors are quantum states, so everything proved here applies to them verbatim.
Definition
Positive-definite kernel (real case)
Let be a nonempty set. A function is a positive-definite kernel if (i) it is symmetric, for all , and (ii) for every , every choice of points and every coefficient vector , Equivalently: every Gram matrix is symmetric positive semidefinite, .
Definition
Hermitian positive-definite kernel (complex case)
A function is a Hermitian positive-definite kernel if for all , all and all . This condition already forces Hermitian symmetry : write the Gram matrix as with and , both Hermitian, so with both quadratic forms real; reality of for every gives for every , hence every eigenvalue of is and by the spectral theorem, i.e. . The overlap of quantum feature states is the prototype: it is complex-valued, Hermitian, and positive definite in this sense (proved in the last section).
Feature-map inner products are positive-definite kernels
Let be a real inner-product space and any map. Then is a positive-definite kernel.
Proof (4 steps)
- Step 1:A real inner product is symmetric, so is symmetric.
- Step 2:Insert the definition of into the quadratic form.
- Step 3:Bilinearity of the inner product pulls the finite sums and the real coefficients inside.
- Step 4:The inner product of a vector with itself is its squared norm, which is nonnegative.
∎
Diagonal bound
For a positive-definite kernel, and for all .
Proof (5 steps)
- Step 1:The definition with a single point.
- Step 2:The Gram matrix of the two points ; symmetric because is.
- Step 3:A real symmetric matrix has real eigenvalues with real unit eigenvectors; taking in the definition shows each eigenvalue is nonnegative.
- Step 4:The determinant is the product of the eigenvalues.
- Step 5:Expand the determinant using .
∎
Quick check
Which of these functions on is not a positive-definite kernel?
The Moore–Aronszajn construction of the RKHS#
Definition
Reproducing kernel Hilbert space
A reproducing kernel Hilbert space (RKHS) on is a Hilbert space whose elements are functions (with pointwise addition and scalar multiplication) together with a function such that (i) for every , and (ii) the reproducing property holds for every and . Here denotes the function . Two elements of are equal exactly when they are equal as functions at every point.
The construction runs in three stages. We start from the finite linear combinations of kernel sections , define an inner product on them that makes the reproducing property true by design, check that this definition makes sense, and finally add limits of Cauchy sequences. Only the defining inequality and the symmetry of are used — no topology on , no measure, no continuity.
Definition
The pre-Hilbert space H₀
Let , the set of all functions with , , . For and set The right-hand side is computed from a representation of , and a function has many representations: , and for the linear kernel on also . The first lemma shows that the number does not depend on the representation chosen.
Well-definedness and the reproducing property on H₀
is a well-defined, symmetric, bilinear, positive-semidefinite form on , and for every and . In particular .
Proof (8 steps)
- Step 1:Reorder the finite double sum and use ; the inner sum is , the value of the function at .
- Step 2:Summing in the other order, the inner sum is .
- Step 3:The first expression involves only through its values , so it cannot depend on how is written. Likewise the second expression shows independence from the representation of . Changing both representations one after the other leaves the number fixed: the form is well defined on pairs of functions.
- Step 4:Symmetry of .
- Step 5:Linearity in the first argument from the first expression, since functions are added and scaled pointwise; linearity in the second argument then follows from symmetry.
- Step 6:This is exactly the quadratic form of the definition of a positive-definite kernel with .
- Step 7:The first expression with the one-term representation of — the reproducing property.
- Step 8:Apply the reproducing property to evaluated at the point .
∎
Cauchy–Schwarz for positive-semidefinite forms
Let be a symmetric bilinear form on a real vector space with for all (definiteness is not assumed). Then for all .
Proof (5 steps)
- Step 1:Expand by bilinearity and symmetry; because the form is positive semidefinite.
- Step 2:Evaluate at its minimiser: .
- Step 3:Multiply by .
- Step 4:The quadratic term vanishes and is affine in .
- Step 5:If , letting makes the affine function negative; if , letting does. Both contradict , so and the inequality holds with equality.
∎
Point evaluations are bounded, so the form is definite
For every and , . Consequently implies , so is an inner product and is a pre-Hilbert space.
Proof (5 steps)
- Step 1:Reproducing property on .
- Step 2:Cauchy–Schwarz for the positive-semidefinite form — we may not yet assume it is definite, which is why the lemma was proved without that assumption.
- Step 3:by the previous lemma.
- Step 4:The bound holds at every point, and a function vanishing everywhere is the zero element of .
- Step 5:Together with symmetry, bilinearity and semidefiniteness, this is the definition of an inner product.
∎
Moore–Aronszajn theorem
For every positive-definite kernel on there is exactly one Hilbert space of functions on for which is a reproducing kernel. It consists of the pointwise limits of Cauchy sequences in , contains as a dense subspace, and satisfies .
Proof (8 steps)
- Step 1:The pointwise bound applied to . If is Cauchy in , then is a Cauchy sequence of real numbers for every fixed .
- Step 2:is complete, so each pointwise limit exists. contains (constant sequences) and is a vector space, because sums and multiples of Cauchy sequences are Cauchy and limits are linear.
- Step 3:Key lemma. Cauchy sequences are bounded, . Given pick with for and write . Then , and the finite sum tends to as . Hence for every .
- Step 4:The limit exists because . It does not depend on the sequences: if also converges pointwise to , then is Cauchy with pointwise limit , so by the key lemma, and the limits coincide.
- Step 5:Symmetry, bilinearity and semidefiniteness pass to the limit; definiteness follows from the pointwise bound, which also passes to the limit and gives on .
- Step 6:Use the constant sequence for and the reproducing property on : the reproducing property holds on all of .
- Step 7:So in norm and is dense. Completeness: the abstract completion of consists of equivalence classes of Cauchy sequences; sending a class to its pointwise limit is well defined and injective by the key lemma and isometric by construction, so is a copy of the (complete) completion.
- Step 8:Uniqueness. with the same inner product ( by the reproducing property), and its orthogonal complement is , so is dense in . Norm convergence in implies pointwise convergence (same bound), hence every is the pointwise limit of a Cauchy sequence in with the same norm: .
∎
Example: the RKHS of the linear kernel
- Step 1:Every element of is a linear function with ; every arises (take , ).
- Step 2:The definition of and bilinearity of the dot product; the result visibly depends only on the functions (through and ).
- Step 3:is -dimensional, hence already complete.
- Step 4:The reproducing property, checked directly: .
Result
Quick check
For the linear kernel on , let . What is ?
The representer theorem#
Regularised empirical-risk minimisation over an RKHS reads . For the Gaussian kernel is infinite-dimensional, so a priori this is an optimisation over a function space. The representer theorem says the optimiser always lies in the -dimensional subspace spanned by the kernel sections at the training points.
Representer theorem (Kimeldorf–Wahba; Schölkopf–Herbrich–Smola)
Let be an RKHS, , an arbitrary function and strictly increasing. Every minimiser of over has the form with . If is only nondecreasing, then whenever a minimiser exists, one of this form exists too.
Proof (7 steps)
- Step 1:is finite-dimensional and therefore closed, so the projection theorem gives a unique decomposition with and .
- Step 2:Reproducing property and linearity of the inner product.
- Step 3:and ; by the reproducing property the inner product is the value . The perpendicular part is invisible at every training point.
- Step 4:The data term depends on only through its values at the training points.
- Step 5:Expand the norm; the cross term vanishes because and (Pythagoras).
- Step 6:makes the norm strictly smaller; is strictly increasing; the data terms are equal.
- Step 7:Otherwise would have strictly smaller objective. For nondecreasing the same computation gives , so is a minimiser in .
∎
Kernel ridge regression in closed form
- Step 1:By the representer theorem it suffices to search over ; is the training Gram matrix.
- Step 2:The inner product of applied to with itself.
- Step 3:Squared loss and , which is strictly increasing on .
- Step 4:Differentiate the quadratic using .
- Step 5:It makes the gradient vanish; is invertible because its eigenvalues are . The Hessian is positive semidefinite, so is convex and is a global minimiser. Any other stationary differs from by some with , and then , so it represents the same function.
- Step 6:The prediction at a new point needs only kernel evaluations — the kernel trick, now justified for any positive-definite kernel.
Quick check
Kernel ridge regression with the Gaussian kernel (whose RKHS is infinite-dimensional) is trained on points in . How many real unknowns does the optimisation problem have after applying the representer theorem?
Mercer's theorem and its finite-sample form#
The RKHS already provides a feature map for every positive-definite kernel: the canonical feature map satisfies by the reproducing property. Together with the first proposition this proves: is positive definite if and only if it is an inner product of feature vectors. Mercer's theorem gives a more concrete version with coordinates: the feature vector becomes a square-summable sequence built from the eigenfunctions of an integral operator.
Theorem (Mercer, 1909). Let be a compact metric space, a finite Borel measure on whose support is all of , and a continuous, symmetric, positive-definite kernel. The integral operator on is compact, self-adjoint and positive. Its eigenvalues (finitely many, or tending to ) have eigenfunctions that are orthonormal in and can be taken continuous, and where the series converges absolutely and uniformly on . (If the support of is smaller than , the expansion holds on .) The proof combines the spectral theorem for compact self-adjoint operators with Dini's theorem on monotone convergence of continuous functions; see Mercer (1909) and Schölkopf & Smola (2002), §2.2.
The Mercer feature map
Under the hypotheses of Mercer's theorem, lies in , satisfies , and the eigenvalues obey the trace formula .
Proof (4 steps)
- Step 1:Mercer's expansion at ; the terms are nonnegative because . So is square-summable.
- Step 2:Definition of the inner product (absolutely convergent by Cauchy–Schwarz in ) and Mercer's expansion.
- Step 3:The series converges uniformly on and is finite, so it may be integrated term by term.
- Step 4:Orthonormality in : . The left side is finite because is continuous on the compact set .
∎
Finite-sample Mercer factorisation
Let be a positive-definite kernel, and . Then with orthogonal and , , and the vectors satisfy for all .
Proof (6 steps)
- Step 1:is symmetric because is. A real symmetric matrix is Hermitian, so the spectral theorem (lesson 7) gives real eigenvalues and an orthonormal eigenbasis, which can be chosen real; its vectors are the columns of .
- Step 2:and ; the double sum is the defining quadratic form with .
- Step 3:The square roots are real because every — this is exactly where positive definiteness of the kernel is used.
- Step 4:and .
- Step 5:, the spectral decomposition, and picks the entry.
- Step 6:. The -th feature is "square root of an eigenvalue times an eigenvector entry", the discrete analogue of .
∎
The finite theorem is Mercer for the empirical measure
- Step 1:On the sample, a function is determined by its value vector .
- Step 2:The integral against is an average over the sample: acts as the matrix .
- Step 3:Eigenvectors of are those of with eigenvalues divided by ; the factor normalises in : .
- Step 4:Mercer's expansion for is the spectral decomposition of the Gram matrix, and .
Worked example. Take and the three points , , . The inner products are , , , , , , so Its leading principal minors are , and , so is positive definite (Sylvester's criterion) and all three eigenvalues are strictly positive. The code below diagonalises with the simulator's Hermitian Jacobi eigensolver eigh, builds and checks for all nine pairs; it also checks the explicit polynomial feature map of the next section.
import { eigh, matrix } from '@/lib/quantum-simulator';
// Explicit feature map of k(x, x') = (x^T x' + 1)^2 on R^2: the 6 monomials of degree <= 2.
const phi = ([a, b]) => [1, Math.SQRT2 * a, Math.SQRT2 * b, a * a, b * b, Math.SQRT2 * a * b];
const k = (x, y) => (x[0] * y[0] + x[1] * y[1] + 1) ** 2;
const dot = (u, v) => u.reduce((s, ui, i) => s + ui * v[i], 0);
const X = [[1, 2], [3, -1], [0, 1]];
console.log('k(x1, x2) = ' + k(X[0], X[1]) + ' phi(x1).phi(x2) = ' + dot(phi(X[0]), phi(X[1])).toFixed(12));
// Gram matrix and its spectral decomposition K = V diag(lambda) V^T (Jacobi eigensolver).
const K = X.map((x) => X.map((y) => k(x, y)));
console.log('K = ' + JSON.stringify(K));
const { values, vectors } = eigh(matrix.fromRows(K));
console.log('eigenvalues = ' + Array.from(values, (l) => l.toFixed(6)).join(', '));
// Finite Mercer feature map: Phi(x_i)_r = sqrt(lambda_r) * V[i][r], so Phi(x_i).Phi(x_j) = K_ij.
const Phi = X.map((_, i) => Array.from(values, (l, r) => Math.sqrt(l) * matrix.get(vectors, i, r).re));
let err = 0;
for (let i = 0; i < 3; i++) for (let j = 0; j < 3; j++) err = Math.max(err, Math.abs(dot(Phi[i], Phi[j]) - K[i][j]));
// The signs of the eigenvectors are arbitrary, so print sign-independent quantities.
console.log('|Phi(x_i)|^2 = ' + Phi.map((p) => dot(p, p).toFixed(6)).join(', ') + ' (diagonal of K)');
console.log('sum of eigenvalues = ' + values.reduce((s, l) => s + l, 0).toFixed(6) + ' = Tr K');
console.log('max |Phi(x_i).Phi(x_j) - K_ij| < 1e-10: ' + (err < 1e-10));Expected output
k(x1, x2) = 4 phi(x1).phi(x2) = 4.000000000000 K = [[36,4,9],[4,121,0],[9,0,4]] eigenvalues = 1.633804, 38.176843, 121.189353 |Phi(x_i)|^2 = 36.000000, 121.000000, 4.000000 (diagonal of K) sum of eigenvalues = 161.000000 = Tr K max |Phi(x_i).Phi(x_j) - K_ij| < 1e-10: true
Quick check
A kernel has Gram matrix on two points, with eigenvalues and eigenvectors , . What is for the finite Mercer feature vector ?
Explicit polynomial feature maps#
The feature map of (xᵀx′ + 1)² on ℝ²
- Step 1:Write the inner product on in coordinates.
- Step 2:Square of a trinomial: three squares and three doubled cross terms.
- Step 3:Substitute back.
- Step 4:Split every coefficient symmetrically, , so that each term is the same function evaluated at and at .
- Step 5:Collect the six products as a dot product.
Result
Numerical check at x = (2, −1), x′ = (1, 3)
- Step 1:The kernel trick: one inner product in , one addition, one square.
- Step 2:Evaluate the six features at each point.
- Step 3:The six products , , , , , — the same value, so the two points have orthogonal feature vectors.
Feature map and dimension of a polynomial kernel
For , and , the kernel equals with one coordinate per multi-index , : There are coordinates, they are linearly independent functions, and ; no feature map of this kernel has fewer coordinates.
Proof (9 steps)
- Step 1:Absorb the constant as a zeroth coordinate.
- Step 2:Multinomial theorem.
- Step 3:and the multinomial coefficient is split as the square of its square root; .
- Step 4:Stars and bars: a multi-index is a row of stars cut into groups by bars, i.e. a choice of bar positions among slots.
- Step 5:The coordinates are scaled copies of the distinct monomials of degree at most ( is fixed by the others), one per multi-index.
- Step 6:A polynomial vanishing on all of has all coefficients zero, and the coefficients of distinct monomials vanish only if (here is used). Hence the vectors , , span with .
- Step 7:and the reach every ; the map is injective by the previous step. A finite-dimensional space is complete, so no completion is needed.
- Step 8:Every lies in a space of dimension at most , so the feature space of any feature map is at least as large as .
- Step 9:The coefficients are , reproducing from the derivation above.
∎
Lifting circles to a plane. The homogeneous kernel has the three-dimensional feature map (only the multi-indices with survive when ). A circle is mapped into the plane . Two concentric rings of radii , which no line in separates, land on the parallel planes and , so the linear classifier with separates them; pulled back to the input plane its decision boundary is the circle . The XOR pattern, labelled by , is separated by the plane . Rotate the lifted point clouds below and find the separating planes.
Circles become planes under the homogeneous quadratic map
- Step 1:Square and split the cross coefficient .
- Step 2:and , so the squared radius is a linear function of the features.
- Step 3:A hyperplane in feature space is a circle (a quadric in general) in input space.
- Step 4:: the XOR labels depend linearly on the second feature.
Quick check
What is the dimension of the RKHS of on ?
Building kernels, and the quantum fidelity kernel#
Closure properties of positive-definite kernels
If are positive-definite kernels on , and is any function, then , , and the pointwise product are positive-definite kernels. In particular is positive definite for every and .
Proof (6 steps)
- Step 1:A nonnegative multiple of a nonnegative number; symmetry is preserved by all four constructions.
- Step 2:Sum of two nonnegative quadratic forms.
- Step 3:Absorb into the coefficients.
- Step 4:Spectral decomposition of the Gram matrix of on the points ; its eigenvalues are nonnegative.
- Step 5:Schur product theorem: with (entrywise product), each and each .
- Step 6:has feature and the constant has feature ; apply the sum rule once and the product rule times.
∎
Quantum overlap and fidelity kernels are positive definite
Let be any data-encoding state preparation and . Then (a) is a Hermitian positive-definite kernel, and (b) the fidelity kernel equals , the Hilbert–Schmidt inner product of the feature vectors in the real -dimensional space of Hermitian matrices, and is a real positive-definite kernel.
Proof (6 steps)
- Step 1:The inner product is antilinear in the first slot, so moves inside the bra as ; this is the Hermitian definition with .
- Step 2:Write , ; pull out the scalar and use .
- Step 3:Conjugate symmetry .
- Step 4:For Hermitian : , and . It is symmetric and real-bilinear, hence a real inner product on Hermitian matrices.
- Step 5:The first proposition of this lesson with feature map .
- Step 6:real diagonal entries plus a real and an imaginary part for each of the entries above the diagonal (those below are determined). The quantum feature space is exponentially large in , yet each kernel value is a single overlap that a quantum circuit can estimate.
∎
References
- N. Aronszajn, Theory of reproducing kernels, Transactions of the American Mathematical Society 68(3), 337–404 (1950).doi:10.1090/S0002-9947-1950-0051437-7
- J. Mercer, Functions of positive and negative type, and their connection with the theory of integral equations, Philosophical Transactions of the Royal Society of London A 209, 415–446 (1909).doi:10.1098/rsta.1909.0016
- B. Schölkopf, R. Herbrich and A. J. Smola, A generalized representer theorem, in Computational Learning Theory (COLT 2001), Lecture Notes in Computer Science 2111, 416–426, Springer (2001).doi:10.1007/3-540-44581-1_27
- B. Schölkopf and A. J. Smola, Learning with Kernels: Support Vector Machines, Regularization, Optimization, and Beyond, MIT Press (2002), chapters 2 and 4.
Hands-on labs
The feature space of a polynomial kernel
1 step · auto-gradedOpen labRead off the explicit feature space of the inhomogeneous quadratic kernel on and evaluate the kernel at a pair of points, confirming that the kernel trick and the explicit inner product give the same number.