QuantumCore

Lesson 34 · 110 min · advanced

RKHS, Representer & Mercer's Theorem

Loading progress…

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 Hk\mathcal H_k 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 Hk\mathcal H_k to mm coefficients, states Mercer's eigen-expansion and proves its finite-sample version Φ(xi)=Λ1/2V⊤ei\Phi(x_i)=\Lambda^{1/2}V^\top e_i, and writes the explicit 66-dimensional feature map of (x⊤x′+1)2(x^\top x'+1)^2. It ends by showing that the quantum fidelity kernel ∣⟨ψ(x)∣ψ(x′)⟩∣2\lvert\langle\psi(x)\vert\psi(x')\rangle\rvert^2 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 ⟨ϕ(x),ϕ(x′)⟩\langle\phi(x),\phi(x')\rangle is one.

  • Construct the RKHS Hk\mathcal H_k of a positive-definite kernel: prove that ⟨∑iaik(⋅,xi),∑jbjk(⋅,yj)⟩=∑ijaibjk(xi,yj)\langle\sum_ia_ik(\cdot,x_i),\sum_jb_jk(\cdot,y_j)\rangle=\sum_{ij}a_ib_jk(x_i,y_j) 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, α∗=(K+λI)−1y\alpha^\ast=(K+\lambda I)^{-1}y.

  • State Mercer's theorem precisely and prove the finite-sample factorisation Kij=Φ(xi)⊤Φ(xj)K_{ij}=\Phi(x_i)^\top\Phi(x_j) with Φ(xi)=Λ1/2V⊤ei\Phi(x_i)=\Lambda^{1/2}V^\top e_i.

  • Derive the explicit feature map ϕ(x)=(1,2x1,2x2,x12,x22,2x1x2)\phi(x)=(1,\sqrt2x_1,\sqrt2x_2,x_1^2,x_2^2,\sqrt2x_1x_2) of (x⊤x′+1)2(x^\top x'+1)^2 and count the (d+pp)\binom{d+p}{p} dimensions of a general polynomial kernel.

  • Show that the fidelity kernel ∣⟨ψ(x)∣ψ(x′)⟩∣2=Tr ρ(x)ρ(x′)\lvert\langle\psi(x)\vert\psi(x')\rangle\rvert^2=\mathrm{Tr}\,\rho(x)\rho(x') is positive definite.

definition · Positive-definite kernel
k(x,x′)=k(x′,x),∑i,j=1mcicj k(xi,xj)≥0∀m, ∀x1,…,xm∈X, ∀c∈Rmk(x,x')=k(x',x),\qquad\sum_{i,j=1}^mc_ic_j\,k(x_i,x_j)\ge0\quad\forall m,\ \forall x_1,\dots,x_m\in\mathcal X,\ \forall c\in\mathbb R^m
theorem · Reproducing property (Moore–Aronszajn)
⟨f,k(⋅,x)⟩Hk=f(x),∣f(x)∣≤∥f∥Hkk(x,x)\langle f,k(\cdot,x)\rangle_{\mathcal H_k}=f(x),\qquad\lvert f(x)\rvert\le\lVert f\rVert_{\mathcal H_k}\sqrt{k(x,x)}
theorem · Representer theorem
min⁡f∈Hk L(f(x1),…,f(xm))+g(∥f∥Hk) is attained only at f∗=∑i=1mαik(⋅,xi)\min_{f\in\mathcal H_k}\ L\big(f(x_1),\dots,f(x_m)\big)+g\big(\lVert f\rVert_{\mathcal H_k}\big)\ \text{is attained only at}\ f^\ast=\sum_{i=1}^m\alpha_ik(\cdot,x_i)
theorem · Mercer's theorem and its finite-sample form
k(x,x′)=∑jμjφj(x)φj(x′),K=VΛV⊤ ⇒ Φ(xi)=Λ1/2V⊤ei,  Φ(xi)⊤Φ(xj)=Kijk(x,x')=\sum_j\mu_j\varphi_j(x)\varphi_j(x'),\qquad K=V\Lambda V^\top\ \Rightarrow\ \Phi(x_i)=\Lambda^{1/2}V^\top e_i,\ \ \Phi(x_i)^\top\Phi(x_j)=K_{ij}
formula · Quadratic feature map and polynomial dimension
(x⊤x′+1)2=ϕ(x)⊤ϕ(x′),ϕ(x)=(1,2x1,2x2,x12,x22,2x1x2),dim⁡H(x⊤x′+c)p=(d+pp)(x^\top x'+1)^2=\phi(x)^\top\phi(x'),\quad\phi(x)=(1,\sqrt2x_1,\sqrt2x_2,x_1^2,x_2^2,\sqrt2x_1x_2),\quad\dim\mathcal H_{(x^\top x'+c)^p}=\binom{d+p}{p}

Positive-definite kernels#

In the support-vector-machine lesson the dual problem and the decision function f(x)=∑iαiyik(xi,x)+bf(x)=\sum_i\alpha_iy_ik(x_i,x)+b touched the data only through the numbers k(xi,xj)k(x_i,x_j). Two questions were left open. First, which functions k:X×X→Rk:\mathcal X\times\mathcal X\to\mathbb R may be used — when is kk secretly an inner product ⟨ϕ(x),ϕ(x′)⟩\langle\phi(x),\phi(x')\rangle of some feature vectors? Second, in which space does the learned function ff live, and what does the regulariser ∥w∥2\lVert w\rVert^2 become when ϕ\phi 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 X\mathcal X be a nonempty set. A function k:X×X→Rk:\mathcal X\times\mathcal X\to\mathbb R is a positive-definite kernel if (i) it is symmetric, k(x,x′)=k(x′,x)k(x,x')=k(x',x) for all x,x′∈Xx,x'\in\mathcal X, and (ii) for every m∈Nm\in\mathbb N, every choice of points x1,…,xm∈Xx_1,\dots,x_m\in\mathcal X and every coefficient vector c∈Rmc\in\mathbb R^m, ∑i=1m∑j=1mcicj k(xi,xj) ≥ 0.\sum_{i=1}^m\sum_{j=1}^mc_ic_j\,k(x_i,x_j)\ \ge\ 0. Equivalently: every Gram matrix Kij=k(xi,xj)K_{ij}=k(x_i,x_j) is symmetric positive semidefinite, c⊤Kc≥0c^\top Kc\ge0.

Definition

Hermitian positive-definite kernel (complex case)

A function k:X×X→Ck:\mathcal X\times\mathcal X\to\mathbb C is a Hermitian positive-definite kernel if ∑i,jci‾ cj k(xi,xj)≥0\sum_{i,j}\overline{c_i}\,c_j\,k(x_i,x_j)\ge0 for all mm, all x1,…,xmx_1,\dots,x_m and all c∈Cmc\in\mathbb C^m. This condition already forces Hermitian symmetry k(x′,x)=k(x,x′)‾k(x',x)=\overline{k(x,x')}: write the Gram matrix as K=A+iBK=A+iB with A=12(K+K†)A=\tfrac12(K+K^\dagger) and B=12i(K−K†)B=\tfrac1{2i}(K-K^\dagger), both Hermitian, so c†Kc=c†Ac+i c†Bcc^\dagger Kc=c^\dagger Ac+i\,c^\dagger Bc with both quadratic forms real; reality of c†Kcc^\dagger Kc for every cc gives c†Bc=0c^\dagger Bc=0 for every cc, hence every eigenvalue of BB is 00 and B=0B=0 by the spectral theorem, i.e. K=K†K=K^\dagger. The overlap ⟨ψ(x)∣ψ(x′)⟩\langle\psi(x)\vert\psi(x')\rangle of quantum feature states is the prototype: it is complex-valued, Hermitian, and positive definite in this sense (proved in the last section).

Proposition

Feature-map inner products are positive-definite kernels

Let (F,⟨⋅,⋅⟩F)(\mathcal F,\langle\cdot,\cdot\rangle_{\mathcal F}) be a real inner-product space and ϕ:X→F\phi:\mathcal X\to\mathcal F any map. Then k(x,x′)=⟨ϕ(x),ϕ(x′)⟩Fk(x,x')=\langle\phi(x),\phi(x')\rangle_{\mathcal F} is a positive-definite kernel.

Proof (4 steps)
  1. Step 1:
    k(x′,x)=⟨ϕ(x′),ϕ(x)⟩F=⟨ϕ(x),ϕ(x′)⟩F=k(x,x′)k(x',x)=\langle\phi(x'),\phi(x)\rangle_{\mathcal F}=\langle\phi(x),\phi(x')\rangle_{\mathcal F}=k(x,x')
    A real inner product is symmetric, so kk is symmetric.
  2. Step 2:
    ∑i,jcicj k(xi,xj)=∑i,jcicj ⟨ϕ(xi),ϕ(xj)⟩F\sum_{i,j}c_ic_j\,k(x_i,x_j)=\sum_{i,j}c_ic_j\,\langle\phi(x_i),\phi(x_j)\rangle_{\mathcal F}
    Insert the definition of kk into the quadratic form.
  3. Step 3:
    =⟨∑iciϕ(xi),∑jcjϕ(xj)⟩F=\Big\langle\sum_ic_i\phi(x_i),\sum_jc_j\phi(x_j)\Big\rangle_{\mathcal F}
    Bilinearity of the inner product pulls the finite sums and the real coefficients inside.
  4. Step 4:
    =∥∑iciϕ(xi)∥F2 ≥ 0=\Big\lVert\sum_ic_i\phi(x_i)\Big\rVert_{\mathcal F}^2\ \ge\ 0
    The inner product of a vector with itself is its squared norm, which is nonnegative.

∎

Lemma

Diagonal bound

For a positive-definite kernel, k(x,x)≥0k(x,x)\ge0 and k(x,x′)2≤k(x,x) k(x′,x′)k(x,x')^2\le k(x,x)\,k(x',x') for all x,x′∈Xx,x'\in\mathcal X.

Proof (5 steps)
  1. Step 1:
    m=1, c=1:c2k(x,x)=k(x,x)≥0m=1,\ c=1:\quad c^2k(x,x)=k(x,x)\ge0
    The definition with a single point.
  2. Step 2:
    K=(k(x,x)k(x,x′)k(x′,x)k(x′,x′))=K⊤K=\begin{pmatrix}k(x,x)&k(x,x')\\k(x',x)&k(x',x')\end{pmatrix}=K^\top
    The Gram matrix of the two points x,x′x,x'; symmetric because kk is.
  3. Step 3:
    Kv=λv, ∥v∥=1 ⇒ λ=v⊤Kv≥0Kv=\lambda v,\ \lVert v\rVert=1\ \Rightarrow\ \lambda=v^\top Kv\ge0
    A real symmetric matrix has real eigenvalues with real unit eigenvectors; taking c=vc=v in the definition shows each eigenvalue is nonnegative.
  4. Step 4:
    det⁡K=λ1λ2≥0\det K=\lambda_1\lambda_2\ge0
    The determinant is the product of the eigenvalues.
  5. Step 5:
    k(x,x)k(x′,x′)−k(x,x′)2≥0k(x,x)k(x',x')-k(x,x')^2\ge0
    Expand the 2×22\times2 determinant using k(x′,x)=k(x,x′)k(x',x)=k(x,x').

∎

Quick check

Which of these functions on R×R\mathbb R\times\mathbb R is not a positive-definite kernel?

Select one answer

The Moore–Aronszajn construction of the RKHS#

Definition

Reproducing kernel Hilbert space

A reproducing kernel Hilbert space (RKHS) on X\mathcal X is a Hilbert space H\mathcal H whose elements are functions f:X→Rf:\mathcal X\to\mathbb R (with pointwise addition and scalar multiplication) together with a function k:X×X→Rk:\mathcal X\times\mathcal X\to\mathbb R such that (i) k(⋅,x)∈Hk(\cdot,x)\in\mathcal H for every x∈Xx\in\mathcal X, and (ii) the reproducing property ⟨f,k(⋅,x)⟩H=f(x)\langle f,k(\cdot,x)\rangle_{\mathcal H}=f(x) holds for every f∈Hf\in\mathcal H and x∈Xx\in\mathcal X. Here k(⋅,x)k(\cdot,x) denotes the function y↦k(y,x)y\mapsto k(y,x). Two elements of H\mathcal H 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 k(⋅,x)k(\cdot,x), 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 ∑cicjk(xi,xj)≥0\sum c_ic_jk(x_i,x_j)\ge0 and the symmetry of kk are used — no topology on X\mathcal X, no measure, no continuity.

Definition

The pre-Hilbert space H₀

Let H0=span⁡{k(⋅,x):x∈X}\mathcal H_0=\operatorname{span}\{k(\cdot,x):x\in\mathcal X\}, the set of all functions f=∑i=1maik(⋅,xi)f=\sum_{i=1}^ma_ik(\cdot,x_i) with m∈Nm\in\mathbb N, ai∈Ra_i\in\mathbb R, xi∈Xx_i\in\mathcal X. For f=∑i=1maik(⋅,xi)f=\sum_{i=1}^ma_ik(\cdot,x_i) and g=∑j=1nbjk(⋅,yj)g=\sum_{j=1}^nb_jk(\cdot,y_j) set ⟨f,g⟩0=∑i=1m∑j=1naibj k(xi,yj).\langle f,g\rangle_0=\sum_{i=1}^m\sum_{j=1}^na_ib_j\,k(x_i,y_j). The right-hand side is computed from a representation (ai,xi)(a_i,x_i) of ff, and a function has many representations: k(⋅,x)=12k(⋅,x)+12k(⋅,x)k(\cdot,x)=\tfrac12k(\cdot,x)+\tfrac12k(\cdot,x), and for the linear kernel on R2\mathbb R^2 also k(⋅,(2,0))=2 k(⋅,(1,0))k(\cdot,(2,0))=2\,k(\cdot,(1,0)). The first lemma shows that the number does not depend on the representation chosen.

Lemma

Well-definedness and the reproducing property on H₀

⟨⋅,⋅⟩0\langle\cdot,\cdot\rangle_0 is a well-defined, symmetric, bilinear, positive-semidefinite form on H0\mathcal H_0, and ⟨f,k(⋅,x)⟩0=f(x)\langle f,k(\cdot,x)\rangle_0=f(x) for every f∈H0f\in\mathcal H_0 and x∈Xx\in\mathcal X. In particular ⟨k(⋅,x),k(⋅,x′)⟩0=k(x,x′)\langle k(\cdot,x),k(\cdot,x')\rangle_0=k(x,x').

Proof (8 steps)
  1. Step 1:
    ⟨f,g⟩0=∑j=1nbj∑i=1mai k(yj,xi)=∑j=1nbj f(yj)\langle f,g\rangle_0=\sum_{j=1}^nb_j\sum_{i=1}^ma_i\,k(y_j,x_i)=\sum_{j=1}^nb_j\,f(y_j)
    Reorder the finite double sum and use k(xi,yj)=k(yj,xi)k(x_i,y_j)=k(y_j,x_i); the inner sum is f(yj)=∑iaik(yj,xi)f(y_j)=\sum_ia_ik(y_j,x_i), the value of the function ff at yjy_j.
  2. Step 2:
    ⟨f,g⟩0=∑i=1mai∑j=1nbj k(xi,yj)=∑i=1mai g(xi)\langle f,g\rangle_0=\sum_{i=1}^ma_i\sum_{j=1}^nb_j\,k(x_i,y_j)=\sum_{i=1}^ma_i\,g(x_i)
    Summing in the other order, the inner sum is g(xi)=∑jbjk(xi,yj)g(x_i)=\sum_jb_jk(x_i,y_j).
  3. Step 3:
    (ai,xi) and (ai′,xi′) represent the same f ⇒ ∑jbjf(yj) is unchanged(a_i,x_i)\ \text{and}\ (a'_i,x'_i)\ \text{represent the same}\ f\ \Rightarrow\ \sum_jb_jf(y_j)\ \text{is unchanged}
    The first expression involves ff only through its values f(yj)f(y_j), so it cannot depend on how ff is written. Likewise the second expression shows independence from the representation of gg. Changing both representations one after the other leaves the number fixed: the form is well defined on pairs of functions.
  4. Step 4:
    ⟨g,f⟩0=∑j,ibjai k(yj,xi)=∑i,jaibj k(xi,yj)=⟨f,g⟩0\langle g,f\rangle_0=\sum_{j,i}b_ja_i\,k(y_j,x_i)=\sum_{i,j}a_ib_j\,k(x_i,y_j)=\langle f,g\rangle_0
    Symmetry of kk.
  5. Step 5:
    ⟨αf+βf′,g⟩0=∑jbj(αf(yj)+βf′(yj))=α⟨f,g⟩0+β⟨f′,g⟩0\langle\alpha f+\beta f',g\rangle_0=\sum_jb_j\big(\alpha f(y_j)+\beta f'(y_j)\big)=\alpha\langle f,g\rangle_0+\beta\langle f',g\rangle_0
    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.
  6. Step 6:
    ⟨f,f⟩0=∑i,j=1maiaj k(xi,xj) ≥ 0\langle f,f\rangle_0=\sum_{i,j=1}^ma_ia_j\,k(x_i,x_j)\ \ge\ 0
    This is exactly the quadratic form of the definition of a positive-definite kernel with c=ac=a.
  7. Step 7:
    g=k(⋅,x) (n=1, b1=1, y1=x):⟨f,k(⋅,x)⟩0=b1f(y1)=f(x)g=k(\cdot,x)\ (n=1,\ b_1=1,\ y_1=x):\quad\langle f,k(\cdot,x)\rangle_0=b_1f(y_1)=f(x)
    The first expression with the one-term representation of k(⋅,x)k(\cdot,x) — the reproducing property.
  8. Step 8:
    ⟨k(⋅,x),k(⋅,x′)⟩0=k(x′,x)=k(x,x′)\langle k(\cdot,x),k(\cdot,x')\rangle_0=k(x',x)=k(x,x')
    Apply the reproducing property to f=k(⋅,x)f=k(\cdot,x) evaluated at the point x′x'.

∎

Lemma

Cauchy–Schwarz for positive-semidefinite forms

Let ⟨⋅,⋅⟩\langle\cdot,\cdot\rangle be a symmetric bilinear form on a real vector space with ⟨h,h⟩≥0\langle h,h\rangle\ge0 for all hh (definiteness is not assumed). Then ⟨f,g⟩2≤⟨f,f⟩ ⟨g,g⟩\langle f,g\rangle^2\le\langle f,f\rangle\,\langle g,g\rangle for all f,gf,g.

Proof (5 steps)
  1. Step 1:
    q(t)=⟨f+tg,f+tg⟩=⟨f,f⟩+2t⟨f,g⟩+t2⟨g,g⟩ ≥0∀t∈Rq(t)=\langle f+tg,f+tg\rangle=\langle f,f\rangle+2t\langle f,g\rangle+t^2\langle g,g\rangle\ \ge0\quad\forall t\in\mathbb R
    Expand by bilinearity and symmetry; q(t)≥0q(t)\ge0 because the form is positive semidefinite.
  2. Step 2:
    ⟨g,g⟩>0:t=−⟨f,g⟩⟨g,g⟩ ⇒ q(t)=⟨f,f⟩−⟨f,g⟩2⟨g,g⟩≥0\langle g,g\rangle>0:\quad t=-\frac{\langle f,g\rangle}{\langle g,g\rangle}\ \Rightarrow\ q(t)=\langle f,f\rangle-\frac{\langle f,g\rangle^2}{\langle g,g\rangle}\ge0
    Evaluate qq at its minimiser: ⟨f,f⟩−2⟨f,g⟩2⟨g,g⟩+⟨f,g⟩2⟨g,g⟩\langle f,f\rangle-2\frac{\langle f,g\rangle^2}{\langle g,g\rangle}+\frac{\langle f,g\rangle^2}{\langle g,g\rangle}.
  3. Step 3:
    ⇒ ⟨f,g⟩2≤⟨f,f⟩⟨g,g⟩\Rightarrow\ \langle f,g\rangle^2\le\langle f,f\rangle\langle g,g\rangle
    Multiply by ⟨g,g⟩>0\langle g,g\rangle>0.
  4. Step 4:
    ⟨g,g⟩=0:q(t)=⟨f,f⟩+2t⟨f,g⟩≥0∀t\langle g,g\rangle=0:\quad q(t)=\langle f,f\rangle+2t\langle f,g\rangle\ge0\quad\forall t
    The quadratic term vanishes and qq is affine in tt.
  5. Step 5:
    ⇒ ⟨f,g⟩=0 ⇒ ⟨f,g⟩2=0≤⟨f,f⟩⋅0\Rightarrow\ \langle f,g\rangle=0\ \Rightarrow\ \langle f,g\rangle^2=0\le\langle f,f\rangle\cdot0
    If ⟨f,g⟩>0\langle f,g\rangle>0, letting t→−∞t\to-\infty makes the affine function negative; if ⟨f,g⟩<0\langle f,g\rangle<0, letting t→+∞t\to+\infty does. Both contradict q≥0q\ge0, so ⟨f,g⟩=0\langle f,g\rangle=0 and the inequality holds with equality.

∎

Proposition

Point evaluations are bounded, so the form is definite

For every f∈H0f\in\mathcal H_0 and x∈Xx\in\mathcal X, ∣f(x)∣≤⟨f,f⟩0 k(x,x)\lvert f(x)\rvert\le\sqrt{\langle f,f\rangle_0}\,\sqrt{k(x,x)}. Consequently ⟨f,f⟩0=0\langle f,f\rangle_0=0 implies f≡0f\equiv0, so ⟨⋅,⋅⟩0\langle\cdot,\cdot\rangle_0 is an inner product and H0\mathcal H_0 is a pre-Hilbert space.

Proof (5 steps)
  1. Step 1:
    f(x)=⟨f,k(⋅,x)⟩0f(x)=\langle f,k(\cdot,x)\rangle_0
    Reproducing property on H0\mathcal H_0.
  2. Step 2:
    ∣f(x)∣2=∣⟨f,k(⋅,x)⟩0∣2≤⟨f,f⟩0 ⟨k(⋅,x),k(⋅,x)⟩0\lvert f(x)\rvert^2=\lvert\langle f,k(\cdot,x)\rangle_0\rvert^2\le\langle f,f\rangle_0\,\langle k(\cdot,x),k(\cdot,x)\rangle_0
    Cauchy–Schwarz for the positive-semidefinite form ⟨⋅,⋅⟩0\langle\cdot,\cdot\rangle_0 — we may not yet assume it is definite, which is why the lemma was proved without that assumption.
  3. Step 3:
    =⟨f,f⟩0 k(x,x)=\langle f,f\rangle_0\,k(x,x)
    ⟨k(⋅,x),k(⋅,x)⟩0=k(x,x)\langle k(\cdot,x),k(\cdot,x)\rangle_0=k(x,x) by the previous lemma.
  4. Step 4:
    ⟨f,f⟩0=0 ⇒ f(x)=0  ∀x∈X ⇒ f≡0\langle f,f\rangle_0=0\ \Rightarrow\ f(x)=0\ \ \forall x\in\mathcal X\ \Rightarrow\ f\equiv0
    The bound holds at every point, and a function vanishing everywhere is the zero element of H0\mathcal H_0.
  5. Step 5:
    ⟨f,f⟩0>0 for f≠0\langle f,f\rangle_0>0\ \text{for}\ f\ne0
    Together with symmetry, bilinearity and semidefiniteness, this is the definition of an inner product.

∎

Theorem

Moore–Aronszajn theorem

For every positive-definite kernel kk on X\mathcal X there is exactly one Hilbert space Hk\mathcal H_k of functions on X\mathcal X for which kk is a reproducing kernel. It consists of the pointwise limits of Cauchy sequences in H0\mathcal H_0, contains H0\mathcal H_0 as a dense subspace, and satisfies ∣f(x)∣≤∥f∥Hkk(x,x)\lvert f(x)\rvert\le\lVert f\rVert_{\mathcal H_k}\sqrt{k(x,x)}.

Proof (8 steps)
  1. Step 1:
    ∣fn(x)−fm(x)∣=∣⟨fn−fm,k(⋅,x)⟩0∣≤∥fn−fm∥0k(x,x)\lvert f_n(x)-f_m(x)\rvert=\lvert\langle f_n-f_m,k(\cdot,x)\rangle_0\rvert\le\lVert f_n-f_m\rVert_0\sqrt{k(x,x)}
    The pointwise bound applied to fn−fm∈H0f_n-f_m\in\mathcal H_0. If (fn)(f_n) is Cauchy in H0\mathcal H_0, then (fn(x))(f_n(x)) is a Cauchy sequence of real numbers for every fixed xx.
  2. Step 2:
    f(x):=lim⁡n→∞fn(x),Hk:={f: fn→f pointwise, (fn) Cauchy in H0}f(x):=\lim_{n\to\infty}f_n(x),\qquad\mathcal H_k:=\{f:\ f_n\to f\ \text{pointwise},\ (f_n)\ \text{Cauchy in}\ \mathcal H_0\}
    R\mathbb R is complete, so each pointwise limit exists. Hk\mathcal H_k contains H0\mathcal H_0 (constant sequences) and is a vector space, because sums and multiples of Cauchy sequences are Cauchy and limits are linear.
  3. Step 3:
    (fn) Cauchy, fn→0 pointwise ⇒ ∥fn∥0→0(f_n)\ \text{Cauchy},\ f_n\to0\ \text{pointwise}\ \Rightarrow\ \lVert f_n\rVert_0\to0
    Key lemma. Cauchy sequences are bounded, ∥fn∥0≤B\lVert f_n\rVert_0\le B. Given ε>0\varepsilon>0 pick NN with ∥fn−fN∥0<ε\lVert f_n-f_N\rVert_0<\varepsilon for n≥Nn\ge N and write fN=∑j=1rbjk(⋅,yj)f_N=\sum_{j=1}^rb_jk(\cdot,y_j). Then ∥fn∥02=⟨fn,fn−fN⟩0+⟨fn,fN⟩0≤Bε+∣∑jbjfn(yj)∣\lVert f_n\rVert_0^2=\langle f_n,f_n-f_N\rangle_0+\langle f_n,f_N\rangle_0\le B\varepsilon+\big\lvert\sum_jb_jf_n(y_j)\big\rvert, and the finite sum tends to 00 as n→∞n\to\infty. Hence lim sup⁡n∥fn∥02≤Bε\limsup_n\lVert f_n\rVert_0^2\le B\varepsilon for every ε\varepsilon.
  4. Step 4:
    ⟨f,g⟩Hk:=lim⁡n→∞⟨fn,gn⟩0\langle f,g\rangle_{\mathcal H_k}:=\lim_{n\to\infty}\langle f_n,g_n\rangle_0
    The limit exists because ∣⟨fn,gn⟩0−⟨fm,gm⟩0∣≤∥fn−fm∥0∥gn∥0+∥fm∥0∥gn−gm∥0\lvert\langle f_n,g_n\rangle_0-\langle f_m,g_m\rangle_0\rvert\le\lVert f_n-f_m\rVert_0\lVert g_n\rVert_0+\lVert f_m\rVert_0\lVert g_n-g_m\rVert_0. It does not depend on the sequences: if (fn′)(f'_n) also converges pointwise to ff, then fn−fn′f_n-f'_n is Cauchy with pointwise limit 00, so ∥fn−fn′∥0→0\lVert f_n-f'_n\rVert_0\to0 by the key lemma, and the limits coincide.
  5. Step 5:
    ⟨f,f⟩Hk=0 ⇒ ∣f(x)∣=lim⁡n∣fn(x)∣≤lim⁡n∥fn∥0k(x,x)=0\langle f,f\rangle_{\mathcal H_k}=0\ \Rightarrow\ \lvert f(x)\rvert=\lim_n\lvert f_n(x)\rvert\le\lim_n\lVert f_n\rVert_0\sqrt{k(x,x)}=0
    Symmetry, bilinearity and semidefiniteness pass to the limit; definiteness follows from the pointwise bound, which also passes to the limit and gives ∣f(x)∣≤∥f∥Hkk(x,x)\lvert f(x)\rvert\le\lVert f\rVert_{\mathcal H_k}\sqrt{k(x,x)} on Hk\mathcal H_k.
  6. Step 6:
    ⟨f,k(⋅,x)⟩Hk=lim⁡n⟨fn,k(⋅,x)⟩0=lim⁡nfn(x)=f(x)\langle f,k(\cdot,x)\rangle_{\mathcal H_k}=\lim_n\langle f_n,k(\cdot,x)\rangle_0=\lim_nf_n(x)=f(x)
    Use the constant sequence for k(⋅,x)k(\cdot,x) and the reproducing property on H0\mathcal H_0: the reproducing property holds on all of Hk\mathcal H_k.
  7. Step 7:
    ∥f−fn∥Hk=lim⁡m→∞∥fm−fn∥0≤ε(n≥N)\lVert f-f_n\rVert_{\mathcal H_k}=\lim_{m\to\infty}\lVert f_m-f_n\rVert_0\le\varepsilon\quad(n\ge N)
    So fn→ff_n\to f in norm and H0\mathcal H_0 is dense. Completeness: the abstract completion of H0\mathcal H_0 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 Hk\mathcal H_k is a copy of the (complete) completion.
  8. Step 8:
    G another RKHS with kernel k:  g⊥k(⋅,x) ∀x ⇒ g(x)=⟨g,k(⋅,x)⟩G=0\mathcal G\ \text{another RKHS with kernel}\ k:\ \ g\perp k(\cdot,x)\ \forall x\ \Rightarrow\ g(x)=\langle g,k(\cdot,x)\rangle_{\mathcal G}=0
    Uniqueness. G⊇H0\mathcal G\supseteq\mathcal H_0 with the same inner product (⟨k(⋅,x),k(⋅,y)⟩G=k(x,y)\langle k(\cdot,x),k(\cdot,y)\rangle_{\mathcal G}=k(x,y) by the reproducing property), and its orthogonal complement is {0}\{0\}, so H0\mathcal H_0 is dense in G\mathcal G. Norm convergence in G\mathcal G implies pointwise convergence (same bound), hence every g∈Gg\in\mathcal G is the pointwise limit of a Cauchy sequence in H0\mathcal H_0 with the same norm: G=Hk\mathcal G=\mathcal H_k.

∎

Derivation

Example: the RKHS of the linear kernel

  1. Step 1:
    k(x,x′)=x⊤x′ on Rd:f=∑iaik(⋅,xi)=(∑iaixi) ⁣⊤(⋅)=w⊤(⋅)k(x,x')=x^\top x'\ \text{on}\ \mathbb R^d:\quad f=\sum_ia_ik(\cdot,x_i)=\Big(\sum_ia_ix_i\Big)^{\!\top}(\cdot)=w^\top(\cdot)
    Every element of H0\mathcal H_0 is a linear function fw(x)=w⊤xf_w(x)=w^\top x with w=∑iaixiw=\sum_ia_ix_i; every w∈Rdw\in\mathbb R^d arises (take xi=eix_i=e_i, ai=wia_i=w_i).
  2. Step 2:
    ⟨fw,fv⟩=∑i,jaibj xi⊤yj=(∑iaixi) ⁣⊤(∑jbjyj)=w⊤v\langle f_w,f_v\rangle=\sum_{i,j}a_ib_j\,x_i^\top y_j=\Big(\sum_ia_ix_i\Big)^{\!\top}\Big(\sum_jb_jy_j\Big)=w^\top v
    The definition of ⟨⋅,⋅⟩0\langle\cdot,\cdot\rangle_0 and bilinearity of the dot product; the result visibly depends only on the functions (through ww and vv).
  3. Step 3:
    Hk={fw:w∈Rd},∥fw∥Hk=∥w∥2\mathcal H_k=\{f_w:w\in\mathbb R^d\},\qquad\lVert f_w\rVert_{\mathcal H_k}=\lVert w\rVert_2
    H0\mathcal H_0 is dd-dimensional, hence already complete.
  4. Step 4:
    ⟨fw,k(⋅,x)⟩Hk=w⊤x=fw(x)\langle f_w,k(\cdot,x)\rangle_{\mathcal H_k}=w^\top x=f_w(x)
    The reproducing property, checked directly: k(⋅,x)=fxk(\cdot,x)=f_x.

Result

ridge regularisation ∥w∥2 is the RKHS norm ∥fw∥Hk2\boxed{\text{ridge regularisation}\ \lVert w\rVert^2\ \text{is the RKHS norm}\ \lVert f_w\rVert^2_{\mathcal H_k}}

Quick check

For the linear kernel on R2\mathbb R^2, let f=2 k(⋅,(1,0))−k(⋅,(0,1))f=2\,k(\cdot,(1,0))-k(\cdot,(0,1)). What is ∥f∥Hk2\lVert f\rVert^2_{\mathcal H_k}?

tolerance ±0.001

The representer theorem#

Regularised empirical-risk minimisation over an RKHS reads min⁡f∈Hk 1m∑iℓ(f(xi),yi)+λ∥f∥Hk2\min_{f\in\mathcal H_k}\ \frac1m\sum_i\ell(f(x_i),y_i)+\lambda\lVert f\rVert^2_{\mathcal H_k}. For the Gaussian kernel Hk\mathcal H_k is infinite-dimensional, so a priori this is an optimisation over a function space. The representer theorem says the optimiser always lies in the mm-dimensional subspace spanned by the kernel sections at the training points.

Theorem

Representer theorem (Kimeldorf–Wahba; Schölkopf–Herbrich–Smola)

Let Hk\mathcal H_k be an RKHS, x1,…,xm∈Xx_1,\dots,x_m\in\mathcal X, L:Rm→R∪{+∞}L:\mathbb R^m\to\mathbb R\cup\{+\infty\} an arbitrary function and g:[0,∞)→Rg:[0,\infty)\to\mathbb R strictly increasing. Every minimiser of J(f)=L(f(x1),…,f(xm))+g(∥f∥Hk)J(f)=L\big(f(x_1),\dots,f(x_m)\big)+g\big(\lVert f\rVert_{\mathcal H_k}\big) over Hk\mathcal H_k has the form f∗=∑i=1mαik(⋅,xi)f^\ast=\sum_{i=1}^m\alpha_ik(\cdot,x_i) with α∈Rm\alpha\in\mathbb R^m. If gg is only nondecreasing, then whenever a minimiser exists, one of this form exists too.

Proof (7 steps)
  1. Step 1:
    V=span⁡{k(⋅,x1),…,k(⋅,xm)},Hk=V⊕V⊥V=\operatorname{span}\{k(\cdot,x_1),\dots,k(\cdot,x_m)\},\qquad\mathcal H_k=V\oplus V^\perp
    VV is finite-dimensional and therefore closed, so the projection theorem gives a unique decomposition f=f∥+f⊥f=f_\parallel+f_\perp with f∥∈Vf_\parallel\in V and f⊥⊥Vf_\perp\perp V.
  2. Step 2:
    f(xi)=⟨f,k(⋅,xi)⟩=⟨f∥,k(⋅,xi)⟩+⟨f⊥,k(⋅,xi)⟩f(x_i)=\langle f,k(\cdot,x_i)\rangle=\langle f_\parallel,k(\cdot,x_i)\rangle+\langle f_\perp,k(\cdot,x_i)\rangle
    Reproducing property and linearity of the inner product.
  3. Step 3:
    ⟨f⊥,k(⋅,xi)⟩=f⊥(xi)=0 ⇒ f(xi)=f∥(xi)\langle f_\perp,k(\cdot,x_i)\rangle=f_\perp(x_i)=0\ \Rightarrow\ f(x_i)=f_\parallel(x_i)
    k(⋅,xi)∈Vk(\cdot,x_i)\in V and f⊥⊥Vf_\perp\perp V; by the reproducing property the inner product is the value f⊥(xi)f_\perp(x_i). The perpendicular part is invisible at every training point.
  4. Step 4:
    L(f(x1),…,f(xm))=L(f∥(x1),…,f∥(xm))L\big(f(x_1),\dots,f(x_m)\big)=L\big(f_\parallel(x_1),\dots,f_\parallel(x_m)\big)
    The data term depends on ff only through its values at the training points.
  5. Step 5:
    ∥f∥2=∥f∥∥2+2⟨f∥,f⊥⟩+∥f⊥∥2=∥f∥∥2+∥f⊥∥2\lVert f\rVert^2=\lVert f_\parallel\rVert^2+2\langle f_\parallel,f_\perp\rangle+\lVert f_\perp\rVert^2=\lVert f_\parallel\rVert^2+\lVert f_\perp\rVert^2
    Expand the norm; the cross term vanishes because f∥∈Vf_\parallel\in V and f⊥⊥Vf_\perp\perp V (Pythagoras).
  6. Step 6:
    f⊥≠0 ⇒ ∥f∥∥<∥f∥ ⇒ g(∥f∥∥)<g(∥f∥) ⇒ J(f∥)<J(f)f_\perp\ne0\ \Rightarrow\ \lVert f_\parallel\rVert<\lVert f\rVert\ \Rightarrow\ g(\lVert f_\parallel\rVert)<g(\lVert f\rVert)\ \Rightarrow\ J(f_\parallel)<J(f)
    ∥f⊥∥>0\lVert f_\perp\rVert>0 makes the norm strictly smaller; gg is strictly increasing; the data terms are equal.
  7. Step 7:
    f∗ minimiser ⇒ f⊥∗=0 ⇒ f∗=f∥∗=∑i=1mαik(⋅,xi)f^\ast\ \text{minimiser}\ \Rightarrow\ f^\ast_\perp=0\ \Rightarrow\ f^\ast=f^\ast_\parallel=\sum_{i=1}^m\alpha_ik(\cdot,x_i)
    Otherwise f∥∗f^\ast_\parallel would have strictly smaller objective. For nondecreasing gg the same computation gives J(f∥∗)≤J(f∗)J(f^\ast_\parallel)\le J(f^\ast), so f∥∗f^\ast_\parallel is a minimiser in VV.

∎

Derivation

Kernel ridge regression in closed form

  1. Step 1:
    f=∑j=1mαjk(⋅,xj) ⇒ f(xi)=∑jαjk(xi,xj)=(Kα)if=\sum_{j=1}^m\alpha_jk(\cdot,x_j)\ \Rightarrow\ f(x_i)=\sum_j\alpha_jk(x_i,x_j)=(K\alpha)_i
    By the representer theorem it suffices to search over α∈Rm\alpha\in\mathbb R^m; KK is the training Gram matrix.
  2. Step 2:
    ∥f∥Hk2=∑i,jαiαjk(xi,xj)=α⊤Kα\lVert f\rVert^2_{\mathcal H_k}=\sum_{i,j}\alpha_i\alpha_jk(x_i,x_j)=\alpha^\top K\alpha
    The inner product of H0\mathcal H_0 applied to ff with itself.
  3. Step 3:
    J(α)=∥Kα−y∥2+λ α⊤Kα,λ>0J(\alpha)=\lVert K\alpha-y\rVert^2+\lambda\,\alpha^\top K\alpha,\qquad\lambda>0
    Squared loss and g(t)=λt2g(t)=\lambda t^2, which is strictly increasing on [0,∞)[0,\infty).
  4. Step 4:
    ∇αJ=2K(Kα−y)+2λKα=2K((K+λI)α−y)\nabla_\alpha J=2K(K\alpha-y)+2\lambda K\alpha=2K\big((K+\lambda I)\alpha-y\big)
    Differentiate the quadratic using K⊤=KK^\top=K.
  5. Step 5:
    α∗=(K+λI)−1y\alpha^\ast=(K+\lambda I)^{-1}y
    It makes the gradient vanish; K+λIK+\lambda I is invertible because its eigenvalues are λr+λ≥λ>0\lambda_r+\lambda\ge\lambda>0. The Hessian 2(K2+λK)=2V(Λ2+λΛ)V⊤2(K^2+\lambda K)=2V(\Lambda^2+\lambda\Lambda)V^\top is positive semidefinite, so JJ is convex and α∗\alpha^\ast is a global minimiser. Any other stationary α\alpha differs from α∗\alpha^\ast by some β\beta with Kβ=0K\beta=0, and then ∥∑jβjk(⋅,xj)∥2=β⊤Kβ=0\lVert\sum_j\beta_jk(\cdot,x_j)\rVert^2=\beta^\top K\beta=0, so it represents the same function.
  6. Step 6:
    f∗(x)=∑jαj∗k(x,xj)=k(x)⊤(K+λI)−1y,k(x)j=k(x,xj)f^\ast(x)=\sum_j\alpha^\ast_jk(x,x_j)=\mathbf k(x)^\top(K+\lambda I)^{-1}y,\qquad\mathbf k(x)_j=k(x,x_j)
    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 m=500m=500 points in R10\mathbb R^{10}. How many real unknowns does the optimisation problem have after applying the representer theorem?

Select one answer

Mercer's theorem and its finite-sample form#

The RKHS already provides a feature map for every positive-definite kernel: the canonical feature map Φ(x)=k(⋅,x)∈Hk\Phi(x)=k(\cdot,x)\in\mathcal H_k satisfies ⟨Φ(x),Φ(x′)⟩Hk=k(x,x′)\langle\Phi(x),\Phi(x')\rangle_{\mathcal H_k}=k(x,x') by the reproducing property. Together with the first proposition this proves: kk 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 X\mathcal X be a compact metric space, μ\mu a finite Borel measure on X\mathcal X whose support is all of X\mathcal X, and k:X×X→Rk:\mathcal X\times\mathcal X\to\mathbb R a continuous, symmetric, positive-definite kernel. The integral operator (Tkf)(x)=∫Xk(x,x′) f(x′) dμ(x′)(T_kf)(x)=\int_{\mathcal X}k(x,x')\,f(x')\,d\mu(x') on L2(X,μ)L^2(\mathcal X,\mu) is compact, self-adjoint and positive. Its eigenvalues μ1≥μ2≥⋯≥0\mu_1\ge\mu_2\ge\dots\ge0 (finitely many, or tending to 00) have eigenfunctions φj\varphi_j that are orthonormal in L2(X,μ)L^2(\mathcal X,\mu) and can be taken continuous, and k(x,x′)=∑jμj φj(x) φj(x′)for all x,x′∈X,k(x,x')=\sum_{j}\mu_j\,\varphi_j(x)\,\varphi_j(x')\qquad\text{for all}\ x,x'\in\mathcal X, where the series converges absolutely and uniformly on X×X\mathcal X\times\mathcal X. (If the support of μ\mu is smaller than X\mathcal X, the expansion holds on supp μ×supp μ\mathrm{supp}\,\mu\times\mathrm{supp}\,\mu.) 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.

Corollary

The Mercer feature map

Under the hypotheses of Mercer's theorem, Φ(x)=(μj φj(x))j≥1\Phi(x)=\big(\sqrt{\mu_j}\,\varphi_j(x)\big)_{j\ge1} lies in ℓ2\ell^2, satisfies ⟨Φ(x),Φ(x′)⟩ℓ2=k(x,x′)\langle\Phi(x),\Phi(x')\rangle_{\ell^2}=k(x,x'), and the eigenvalues obey the trace formula ∑jμj=∫Xk(x,x) dμ(x)<∞\sum_j\mu_j=\int_{\mathcal X}k(x,x)\,d\mu(x)<\infty.

Proof (4 steps)
  1. Step 1:
    ∑j(μjφj(x))2=∑jμjφj(x)2=k(x,x)<∞\sum_j\big(\sqrt{\mu_j}\varphi_j(x)\big)^2=\sum_j\mu_j\varphi_j(x)^2=k(x,x)<\infty
    Mercer's expansion at x′=xx'=x; the terms are nonnegative because μj≥0\mu_j\ge0. So Φ(x)\Phi(x) is square-summable.
  2. Step 2:
    ⟨Φ(x),Φ(x′)⟩ℓ2=∑jμjφj(x)μjφj(x′)=∑jμjφj(x)φj(x′)=k(x,x′)\langle\Phi(x),\Phi(x')\rangle_{\ell^2}=\sum_j\sqrt{\mu_j}\varphi_j(x)\sqrt{\mu_j}\varphi_j(x')=\sum_j\mu_j\varphi_j(x)\varphi_j(x')=k(x,x')
    Definition of the ℓ2\ell^2 inner product (absolutely convergent by Cauchy–Schwarz in ℓ2\ell^2) and Mercer's expansion.
  3. Step 3:
    ∫Xk(x,x) dμ(x)=∑jμj∫Xφj(x)2 dμ(x)\int_{\mathcal X}k(x,x)\,d\mu(x)=\sum_j\mu_j\int_{\mathcal X}\varphi_j(x)^2\,d\mu(x)
    The series ∑jμjφj(x)2\sum_j\mu_j\varphi_j(x)^2 converges uniformly on X\mathcal X and μ\mu is finite, so it may be integrated term by term.
  4. Step 4:
    =∑jμj⋅1=∑jμj=\sum_j\mu_j\cdot1=\sum_j\mu_j
    Orthonormality in L2(X,μ)L^2(\mathcal X,\mu): ∫φj2 dμ=1\int\varphi_j^2\,d\mu=1. The left side is finite because kk is continuous on the compact set X\mathcal X.

∎

Theorem

Finite-sample Mercer factorisation

Let kk be a positive-definite kernel, x1,…,xm∈Xx_1,\dots,x_m\in\mathcal X and Kij=k(xi,xj)K_{ij}=k(x_i,x_j). Then K=VΛV⊤K=V\Lambda V^\top with VV orthogonal and Λ=diag(λ1,…,λm)\Lambda=\mathrm{diag}(\lambda_1,\dots,\lambda_m), λr≥0\lambda_r\ge0, and the vectors Φ(xi)=Λ1/2V⊤ei∈Rm,Φ(xi)r=λr Vir,\Phi(x_i)=\Lambda^{1/2}V^\top e_i\in\mathbb R^m,\qquad\Phi(x_i)_r=\sqrt{\lambda_r}\,V_{ir}, satisfy Φ(xi)⊤Φ(xj)=Kij\Phi(x_i)^\top\Phi(x_j)=K_{ij} for all i,ji,j.

Proof (6 steps)
  1. Step 1:
    K⊤=K ⇒ K=VΛV⊤,V⊤V=VV⊤=IK^\top=K\ \Rightarrow\ K=V\Lambda V^\top,\qquad V^\top V=VV^\top=I
    KK is symmetric because kk 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 vrv_r are the columns of VV.
  2. Step 2:
    λr=vr⊤Kvr=∑i,j(vr)i(vr)j k(xi,xj) ≥ 0\lambda_r=v_r^\top Kv_r=\sum_{i,j}(v_r)_i(v_r)_j\,k(x_i,x_j)\ \ge\ 0
    Kvr=λrvrKv_r=\lambda_rv_r and vr⊤vr=1v_r^\top v_r=1; the double sum is the defining quadratic form with c=vrc=v_r.
  3. Step 3:
    Λ1/2=diag(λ1,…,λm),Λ1/2Λ1/2=Λ,(Λ1/2)⊤=Λ1/2\Lambda^{1/2}=\mathrm{diag}\big(\sqrt{\lambda_1},\dots,\sqrt{\lambda_m}\big),\qquad\Lambda^{1/2}\Lambda^{1/2}=\Lambda,\quad(\Lambda^{1/2})^\top=\Lambda^{1/2}
    The square roots are real because every λr≥0\lambda_r\ge0 — this is exactly where positive definiteness of the kernel is used.
  4. Step 4:
    Φ(xi)⊤Φ(xj)=(Λ1/2V⊤ei)⊤(Λ1/2V⊤ej)=ei⊤VΛ1/2Λ1/2V⊤ej\Phi(x_i)^\top\Phi(x_j)=\big(\Lambda^{1/2}V^\top e_i\big)^\top\big(\Lambda^{1/2}V^\top e_j\big)=e_i^\top V\Lambda^{1/2}\Lambda^{1/2}V^\top e_j
    (ABc)⊤=c⊤B⊤A⊤(ABc)^\top=c^\top B^\top A^\top and (V⊤)⊤=V(V^\top)^\top=V.
  5. Step 5:
    =ei⊤VΛV⊤ej=ei⊤Kej=Kij=e_i^\top V\Lambda V^\top e_j=e_i^\top Ke_j=K_{ij}
    Λ1/2Λ1/2=Λ\Lambda^{1/2}\Lambda^{1/2}=\Lambda, the spectral decomposition, and ei⊤Keje_i^\top Ke_j picks the (i,j)(i,j) entry.
  6. Step 6:
    Φ(xi)r=λr (V⊤ei)r=λr Vir\Phi(x_i)_r=\sqrt{\lambda_r}\,(V^\top e_i)_r=\sqrt{\lambda_r}\,V_{ir}
    (V⊤ei)r=(V⊤)ri=Vir(V^\top e_i)_r=(V^\top)_{ri}=V_{ir}. The rr-th feature is "square root of an eigenvalue times an eigenvector entry", the discrete analogue of μjφj(x)\sqrt{\mu_j}\varphi_j(x).

∎

Derivation

The finite theorem is Mercer for the empirical measure

  1. Step 1:
    μm=1m∑i=1mδxi,⟨f,g⟩L2(μm)=1m∑i=1mf(xi)g(xi)\mu_m=\frac1m\sum_{i=1}^m\delta_{x_i},\qquad\langle f,g\rangle_{L^2(\mu_m)}=\frac1m\sum_{i=1}^mf(x_i)g(x_i)
    On the sample, a function is determined by its value vector (f(x1),…,f(xm))(f(x_1),\dots,f(x_m)).
  2. Step 2:
    (Tkf)(xi)=∫k(xi,x′)f(x′) dμm(x′)=1m∑jk(xi,xj)f(xj)=(Kmf)i(T_kf)(x_i)=\int k(x_i,x')f(x')\,d\mu_m(x')=\frac1m\sum_jk(x_i,x_j)f(x_j)=\Big(\frac Km\mathbf f\Big)_i
    The integral against μm\mu_m is an average over the sample: TkT_k acts as the matrix K/mK/m.
  3. Step 3:
    φr(xi)=m Vir,μr=λrm\varphi_r(x_i)=\sqrt m\,V_{ir},\qquad\mu_r=\frac{\lambda_r}{m}
    Eigenvectors of K/mK/m are those of KK with eigenvalues divided by mm; the factor m\sqrt m normalises in L2(μm)L^2(\mu_m): 1m∑im Vir2=1\frac1m\sum_im\,V_{ir}^2=1.
  4. Step 4:
    ∑rμrφr(xi)φr(xj)=∑rλrm m VirVjr=(VΛV⊤)ij=Kij\sum_r\mu_r\varphi_r(x_i)\varphi_r(x_j)=\sum_r\frac{\lambda_r}{m}\,m\,V_{ir}V_{jr}=(V\Lambda V^\top)_{ij}=K_{ij}
    Mercer's expansion for μm\mu_m is the spectral decomposition of the Gram matrix, and μrφr(xi)=λrVir=Φ(xi)r\sqrt{\mu_r}\varphi_r(x_i)=\sqrt{\lambda_r}V_{ir}=\Phi(x_i)_r.

Worked example. Take k(x,x′)=(x⊤x′+1)2k(x,x')=(x^\top x'+1)^2 and the three points x1=(1,2)x_1=(1,2), x2=(3,−1)x_2=(3,-1), x3=(0,1)x_3=(0,1). The inner products are x1⊤x1=5x_1^\top x_1=5, x1⊤x2=1x_1^\top x_2=1, x1⊤x3=2x_1^\top x_3=2, x2⊤x2=10x_2^\top x_2=10, x2⊤x3=−1x_2^\top x_3=-1, x3⊤x3=1x_3^\top x_3=1, so K=(364941210904).K=\begin{pmatrix}36&4&9\\4&121&0\\9&0&4\end{pmatrix}. Its leading principal minors are 36>036>0, 36⋅121−16=4340>036\cdot121-16=4340>0 and det⁡K=36⋅484−4⋅16+9⋅(−1089)=7559>0\det K=36\cdot484-4\cdot16+9\cdot(-1089)=7559>0, so KK is positive definite (Sylvester's criterion) and all three eigenvalues are strictly positive. The code below diagonalises KK with the simulator's Hermitian Jacobi eigensolver eigh, builds Φ(xi)=Λ1/2V⊤ei\Phi(x_i)=\Lambda^{1/2}V^\top e_i and checks Φ(xi)⊤Φ(xj)=Kij\Phi(x_i)^\top\Phi(x_j)=K_{ij} for all nine pairs; it also checks the explicit polynomial feature map of the next section.

TypeScriptrunnable
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 K=(2112)K=\begin{pmatrix}2&1\\1&2\end{pmatrix} on two points, with eigenvalues 1,31,3 and eigenvectors 12(1,−1)\tfrac1{\sqrt2}(1,-1), 12(1,1)\tfrac1{\sqrt2}(1,1). What is ∥Φ(x1)∥2\lVert\Phi(x_1)\rVert^2 for the finite Mercer feature vector Φ(x1)=Λ1/2V⊤e1\Phi(x_1)=\Lambda^{1/2}V^\top e_1?

tolerance ±0.001

Explicit polynomial feature maps#

Derivation

The feature map of (xᵀx′ + 1)² on ℝ²

  1. Step 1:
    k(x,x′)=(x1x1′+x2x2′+1)2=(u+v+w)2,u=x1x1′, v=x2x2′, w=1k(x,x')=\big(x_1x'_1+x_2x'_2+1\big)^2=(u+v+w)^2,\quad u=x_1x'_1,\ v=x_2x'_2,\ w=1
    Write the inner product on R2\mathbb R^2 in coordinates.
  2. Step 2:
    (u+v+w)2=u2+v2+w2+2uv+2uw+2vw(u+v+w)^2=u^2+v^2+w^2+2uv+2uw+2vw
    Square of a trinomial: three squares and three doubled cross terms.
  3. Step 3:
    =x12x1′2+x22x2′2+1+2x1x2x1′x2′+2x1x1′+2x2x2′=x_1^2x_1'^2+x_2^2x_2'^2+1+2x_1x_2x'_1x'_2+2x_1x'_1+2x_2x'_2
    Substitute u,v,wu,v,w back.
  4. Step 4:
    =1⋅1+(2x1)(2x1′)+(2x2)(2x2′)+(x12)(x1′2)+(x22)(x2′2)+(2x1x2)(2x1′x2′)=1\cdot1+(\sqrt2x_1)(\sqrt2x'_1)+(\sqrt2x_2)(\sqrt2x'_2)+(x_1^2)(x_1'^2)+(x_2^2)(x_2'^2)+(\sqrt2x_1x_2)(\sqrt2x'_1x'_2)
    Split every coefficient symmetrically, 2=2⋅22=\sqrt2\cdot\sqrt2, so that each term is the same function evaluated at xx and at x′x'.
  5. Step 5:
    =ϕ(x)⊤ϕ(x′),ϕ(x)=(1, 2x1, 2x2, x12, x22, 2x1x2)∈R6=\phi(x)^\top\phi(x'),\qquad\phi(x)=\big(1,\ \sqrt2x_1,\ \sqrt2x_2,\ x_1^2,\ x_2^2,\ \sqrt2x_1x_2\big)\in\mathbb R^6
    Collect the six products as a dot product.

Result

(x⊤x′+1)2=ϕ(x)⊤ϕ(x′),dim⁡F=6\boxed{(x^\top x'+1)^2=\phi(x)^\top\phi(x'),\qquad\dim\mathcal F=6}
Derivation

Numerical check at x = (2, −1), x′ = (1, 3)

  1. Step 1:
    x⊤x′=2⋅1+(−1)⋅3=−1 ⇒ k(x,x′)=(−1+1)2=0x^\top x'=2\cdot1+(-1)\cdot3=-1\ \Rightarrow\ k(x,x')=(-1+1)^2=0
    The kernel trick: one inner product in R2\mathbb R^2, one addition, one square.
  2. Step 2:
    ϕ(x)=(1,22,−2,4,1,−22),ϕ(x′)=(1,2,32,1,9,32)\phi(x)=\big(1,2\sqrt2,-\sqrt2,4,1,-2\sqrt2\big),\qquad\phi(x')=\big(1,\sqrt2,3\sqrt2,1,9,3\sqrt2\big)
    Evaluate the six features at each point.
  3. Step 3:
    ϕ(x)⊤ϕ(x′)=1+4−6+4+9−12=0\phi(x)^\top\phi(x')=1+4-6+4+9-12=0
    The six products 1⋅11\cdot1, 22⋅22\sqrt2\cdot\sqrt2, −2⋅32-\sqrt2\cdot3\sqrt2, 4⋅14\cdot1, 1⋅91\cdot9, −22⋅32-2\sqrt2\cdot3\sqrt2 — the same value, so the two points have orthogonal feature vectors.
Proposition

Feature map and dimension of a polynomial kernel

For c>0c>0, p∈Np\in\mathbb N and x,x′∈Rdx,x'\in\mathbb R^d, the kernel (x⊤x′+c)p(x^\top x'+c)^p equals ϕ(x)⊤ϕ(x′)\phi(x)^\top\phi(x') with one coordinate per multi-index α=(α0,…,αd)∈Nd+1\alpha=(\alpha_0,\dots,\alpha_d)\in\mathbb N^{d+1}, ∣α∣=p\lvert\alpha\rvert=p: ϕα(x)=p!α0! α1!⋯αd!  cα0/2x1α1⋯xdαd.\phi_\alpha(x)=\sqrt{\frac{p!}{\alpha_0!\,\alpha_1!\cdots\alpha_d!}}\;c^{\alpha_0/2}x_1^{\alpha_1}\cdots x_d^{\alpha_d}. There are (d+pp)\binom{d+p}{p} coordinates, they are linearly independent functions, and dim⁡Hk=(d+pp)\dim\mathcal H_k=\binom{d+p}{p}; no feature map of this kernel has fewer coordinates.

Proof (9 steps)
  1. Step 1:
    z=(c,x1,…,xd), z′=(c,x1′,…,xd′) ⇒ x⊤x′+c=∑i=0dzizi′z=(\sqrt c,x_1,\dots,x_d),\ z'=(\sqrt c,x'_1,\dots,x'_d)\ \Rightarrow\ x^\top x'+c=\sum_{i=0}^dz_iz'_i
    Absorb the constant as a zeroth coordinate.
  2. Step 2:
    (∑i=0dzizi′)p=∑∣α∣=pp!α0!⋯αd!∏i=0d(zizi′)αi\Big(\sum_{i=0}^dz_iz'_i\Big)^p=\sum_{\lvert\alpha\rvert=p}\frac{p!}{\alpha_0!\cdots\alpha_d!}\prod_{i=0}^d(z_iz'_i)^{\alpha_i}
    Multinomial theorem.
  3. Step 3:
    =∑∣α∣=p[p!α! zα][p!α! z′α]=ϕ(x)⊤ϕ(x′)=\sum_{\lvert\alpha\rvert=p}\Big[\sqrt{\tfrac{p!}{\alpha!}}\,z^\alpha\Big]\Big[\sqrt{\tfrac{p!}{\alpha!}}\,z'^\alpha\Big]=\phi(x)^\top\phi(x')
    ∏i(zizi′)αi=zαz′α\prod_i(z_iz'_i)^{\alpha_i}=z^\alpha z'^\alpha and the multinomial coefficient is split as the square of its square root; zα=cα0/2x1α1⋯xdαdz^\alpha=c^{\alpha_0/2}x_1^{\alpha_1}\cdots x_d^{\alpha_d}.
  4. Step 4:
    #{α∈Nd+1:∣α∣=p}=(p+dd)=(d+pp)\#\{\alpha\in\mathbb N^{d+1}:\lvert\alpha\rvert=p\}=\binom{p+d}{d}=\binom{d+p}{p}
    Stars and bars: a multi-index is a row of pp stars cut into d+1d+1 groups by dd bars, i.e. a choice of dd bar positions among p+dp+d slots.
  5. Step 5:
    α↦x1α1⋯xdαd,α1+⋯+αd=p−α0≤p\alpha\mapsto x_1^{\alpha_1}\cdots x_d^{\alpha_d},\qquad\alpha_1+\dots+\alpha_d=p-\alpha_0\le p
    The coordinates are scaled copies of the distinct monomials of degree at most pp (α0\alpha_0 is fixed by the others), one per multi-index.
  6. Step 6:
    w⊤ϕ(x)=0  ∀x∈Rd ⇒ w=0w^\top\phi(x)=0\ \ \forall x\in\mathbb R^d\ \Rightarrow\ w=0
    A polynomial vanishing on all of Rd\mathbb R^d has all coefficients zero, and the coefficients wαp!/α! cα0/2w_\alpha\sqrt{p!/\alpha!}\,c^{\alpha_0/2} of distinct monomials vanish only if w=0w=0 (here c>0c>0 is used). Hence the vectors ϕ(x)\phi(x), x∈Rdx\in\mathbb R^d, span RD\mathbb R^D with D=(d+pp)D=\binom{d+p}{p}.
  7. Step 7:
    Hk=H0={x↦w⊤ϕ(x):w∈RD},dim⁡Hk=D\mathcal H_k=\mathcal H_0=\{x\mapsto w^\top\phi(x):w\in\mathbb R^D\},\qquad\dim\mathcal H_k=D
    ∑iaik(⋅,xi)=(∑iaiϕ(xi))⊤ϕ(⋅)\sum_ia_ik(\cdot,x_i)=\big(\sum_ia_i\phi(x_i)\big)^\top\phi(\cdot) and the ϕ(xi)\phi(x_i) reach every w∈RDw\in\mathbb R^D; the map w↦w⊤ϕw\mapsto w^\top\phi is injective by the previous step. A finite-dimensional space is complete, so no completion is needed.
  8. Step 8:
    ψ:Rd→RD′, ψ(x)⊤ψ(x′)=k(x,x′) ⇒ Hk⊆{x↦v⊤ψ(x):v∈RD′} ⇒ D′≥D\psi:\mathbb R^d\to\mathbb R^{D'},\ \psi(x)^\top\psi(x')=k(x,x')\ \Rightarrow\ \mathcal H_k\subseteq\{x\mapsto v^\top\psi(x):v\in\mathbb R^{D'}\}\ \Rightarrow\ D'\ge D
    Every ∑iaik(⋅,xi)=(∑iaiψ(xi))⊤ψ(⋅)\sum_ia_ik(\cdot,x_i)=(\sum_ia_i\psi(x_i))^\top\psi(\cdot) lies in a space of dimension at most D′D', so the feature space of any feature map is at least as large as Hk\mathcal H_k.
  9. Step 9:
    d=2, p=2, c=1:(42)=6,α∈{(2,0,0),(1,1,0),(1,0,1),(0,2,0),(0,0,2),(0,1,1)}d=2,\ p=2,\ c=1:\quad\binom42=6,\quad\alpha\in\{(2,0,0),(1,1,0),(1,0,1),(0,2,0),(0,0,2),(0,1,1)\}
    The coefficients 2!/α!\sqrt{2!/\alpha!} are 1,2,2,1,1,21,\sqrt2,\sqrt2,1,1,\sqrt2, reproducing ϕ(x)=(1,2x1,2x2,x12,x22,2x1x2)\phi(x)=(1,\sqrt2x_1,\sqrt2x_2,x_1^2,x_2^2,\sqrt2x_1x_2) from the derivation above.

∎

Lifting circles to a plane. The homogeneous kernel (x⊤x′)2=x12x1′2+2x1x2x1′x2′+x22x2′2(x^\top x')^2=x_1^2x_1'^2+2x_1x_2x'_1x'_2+x_2^2x_2'^2 has the three-dimensional feature map ϕ~(x)=(z1,z2,z3)=(x12,2x1x2,x22)\tilde\phi(x)=(z_1,z_2,z_3)=(x_1^2,\sqrt2x_1x_2,x_2^2) (only the multi-indices with α0=0\alpha_0=0 survive when c=0c=0). A circle x12+x22=r2x_1^2+x_2^2=r^2 is mapped into the plane z1+z3=r2z_1+z_3=r^2. Two concentric rings of radii rin<routr_{\mathrm{in}}<r_{\mathrm{out}}, which no line in R2\mathbb R^2 separates, land on the parallel planes z1+z3=rin2z_1+z_3=r_{\mathrm{in}}^2 and z1+z3=rout2z_1+z_3=r_{\mathrm{out}}^2, so the linear classifier sign(z1+z3−t)\mathrm{sign}(z_1+z_3-t) with rin2<t<rout2r_{\mathrm{in}}^2<t<r_{\mathrm{out}}^2 separates them; pulled back to the input plane its decision boundary is the circle x12+x22=tx_1^2+x_2^2=t. The XOR pattern, labelled by sign(x1x2)\mathrm{sign}(x_1x_2), is separated by the plane z2=0z_2=0. Rotate the lifted point clouds below and find the separating planes.

Derivation

Circles become planes under the homogeneous quadratic map

  1. Step 1:
    (x⊤x′)2=(x12)(x1′2)+(2x1x2)(2x1′x2′)+(x22)(x2′2)=ϕ~(x)⊤ϕ~(x′)(x^\top x')^2=(x_1^2)(x_1'^2)+(\sqrt2x_1x_2)(\sqrt2x'_1x'_2)+(x_2^2)(x_2'^2)=\tilde\phi(x)^\top\tilde\phi(x')
    Square x1x1′+x2x2′x_1x'_1+x_2x'_2 and split the cross coefficient 2=2⋅22=\sqrt2\cdot\sqrt2.
  2. Step 2:
    x12+x22=r2 ⇔ z1+z3=r2,z=ϕ~(x)x_1^2+x_2^2=r^2\ \Leftrightarrow\ z_1+z_3=r^2,\qquad z=\tilde\phi(x)
    z1=x12z_1=x_1^2 and z3=x22z_3=x_2^2, so the squared radius is a linear function (1,0,1)⋅z(1,0,1)\cdot z of the features.
  3. Step 3:
    sign((1,0,1)⋅ϕ~(x)−t)=sign(x12+x22−t)\mathrm{sign}\big((1,0,1)\cdot\tilde\phi(x)-t\big)=\mathrm{sign}\big(x_1^2+x_2^2-t\big)
    A hyperplane in feature space is a circle (a quadric in general) in input space.
  4. Step 4:
    sign(x1x2)=sign((0,1,0)⋅ϕ~(x))\mathrm{sign}(x_1x_2)=\mathrm{sign}\big((0,1,0)\cdot\tilde\phi(x)\big)
    z2=2x1x2z_2=\sqrt2x_1x_2: the XOR labels depend linearly on the second feature.

Quick check

What is the dimension of the RKHS of k(x,x′)=(x⊤x′+1)2k(x,x')=(x^\top x'+1)^2 on R3\mathbb R^3?

tolerance ±0.001

Building kernels, and the quantum fidelity kernel#

Proposition

Closure properties of positive-definite kernels

If k1,k2k_1,k_2 are positive-definite kernels on X\mathcal X, a≥0a\ge0 and h:X→Rh:\mathcal X\to\mathbb R is any function, then ak1ak_1, k1+k2k_1+k_2, h(x)k1(x,x′)h(x′)h(x)k_1(x,x')h(x') and the pointwise product k1k2k_1k_2 are positive-definite kernels. In particular (x⊤x′+c)p(x^\top x'+c)^p is positive definite for every c≥0c\ge0 and p∈Np\in\mathbb N.

Proof (6 steps)
  1. Step 1:
    ∑i,jcicj ak1(xi,xj)=a∑i,jcicjk1(xi,xj)≥0\sum_{i,j}c_ic_j\,ak_1(x_i,x_j)=a\sum_{i,j}c_ic_jk_1(x_i,x_j)\ge0
    A nonnegative multiple of a nonnegative number; symmetry is preserved by all four constructions.
  2. Step 2:
    ∑i,jcicj(k1+k2)(xi,xj)=∑i,jcicjk1(xi,xj)+∑i,jcicjk2(xi,xj)≥0\sum_{i,j}c_ic_j\big(k_1+k_2\big)(x_i,x_j)=\sum_{i,j}c_ic_jk_1(x_i,x_j)+\sum_{i,j}c_ic_jk_2(x_i,x_j)\ge0
    Sum of two nonnegative quadratic forms.
  3. Step 3:
    ∑i,jcicj h(xi)k1(xi,xj)h(xj)=∑i,jci′cj′k1(xi,xj)≥0,ci′=cih(xi)\sum_{i,j}c_ic_j\,h(x_i)k_1(x_i,x_j)h(x_j)=\sum_{i,j}c'_ic'_jk_1(x_i,x_j)\ge0,\qquad c'_i=c_ih(x_i)
    Absorb hh into the coefficients.
  4. Step 4:
    K2=∑rλrurur⊤, λr≥0 ⇒ (K2)ij=∑rλr(ur)i(ur)jK_2=\sum_r\lambda_ru_ru_r^\top,\ \lambda_r\ge0\ \Rightarrow\ (K_2)_{ij}=\sum_r\lambda_r(u_r)_i(u_r)_j
    Spectral decomposition of the Gram matrix of k2k_2 on the points x1,…,xmx_1,\dots,x_m; its eigenvalues are nonnegative.
  5. Step 5:
    ∑i,jcicj(K1)ij(K2)ij=∑rλr∑i,j(ci(ur)i)(cj(ur)j)(K1)ij=∑rλr dr⊤K1dr≥0\sum_{i,j}c_ic_j(K_1)_{ij}(K_2)_{ij}=\sum_r\lambda_r\sum_{i,j}\big(c_i(u_r)_i\big)\big(c_j(u_r)_j\big)(K_1)_{ij}=\sum_r\lambda_r\,d_r^\top K_1d_r\ge0
    Schur product theorem: with dr=c∘urd_r=c\circ u_r (entrywise product), each dr⊤K1dr≥0d_r^\top K_1d_r\ge0 and each λr≥0\lambda_r\ge0.
  6. Step 6:
    x⊤x′ and c are PD ⇒ x⊤x′+c PD ⇒ (x⊤x′+c)p=∏s=1p(x⊤x′+c) PDx^\top x'\ \text{and}\ c\ \text{are PD}\ \Rightarrow\ x^\top x'+c\ \text{PD}\ \Rightarrow\ (x^\top x'+c)^p=\prod_{s=1}^p(x^\top x'+c)\ \text{PD}
    x⊤x′x^\top x' has feature ϕ(x)=x\phi(x)=x and the constant c≥0c\ge0 has feature c\sqrt c; apply the sum rule once and the product rule p−1p-1 times.

∎

Proposition

Quantum overlap and fidelity kernels are positive definite

Let x↦∣ψ(x)⟩∈C2nx\mapsto\lvert\psi(x)\rangle\in\mathbb C^{2^n} be any data-encoding state preparation and ρ(x)=∣ψ(x)⟩⟨ψ(x)∣\rho(x)=\lvert\psi(x)\rangle\langle\psi(x)\rvert. Then (a) kψ(x,x′)=⟨ψ(x)∣ψ(x′)⟩k_\psi(x,x')=\langle\psi(x)\vert\psi(x')\rangle is a Hermitian positive-definite kernel, and (b) the fidelity kernel kF(x,x′)=∣⟨ψ(x)∣ψ(x′)⟩∣2k_F(x,x')=\lvert\langle\psi(x)\vert\psi(x')\rangle\rvert^2 equals Tr(ρ(x)ρ(x′))\mathrm{Tr}\big(\rho(x)\rho(x')\big), the Hilbert–Schmidt inner product of the feature vectors ρ(x)\rho(x) in the real 4n4^n-dimensional space of Hermitian matrices, and is a real positive-definite kernel.

Proof (6 steps)
  1. Step 1:
    ∑i,jci‾cj⟨ψ(xi)∣ψ(xj)⟩=⟨∑iciψ(xi)∣∑jcjψ(xj)⟩=∥∑jcj∣ψ(xj)⟩∥2≥0\sum_{i,j}\overline{c_i}c_j\langle\psi(x_i)\vert\psi(x_j)\rangle=\Big\langle\sum_ic_i\psi(x_i)\Big\vert\sum_jc_j\psi(x_j)\Big\rangle=\Big\lVert\sum_jc_j\lvert\psi(x_j)\rangle\Big\rVert^2\ge0
    The inner product is antilinear in the first slot, so ci‾\overline{c_i} moves inside the bra as cic_i; this is the Hermitian definition with c∈Cmc\in\mathbb C^m.
  2. Step 2:
    Tr(ρ(x)ρ(x′))=Tr(∣ψ⟩⟨ψ∣ψ′⟩⟨ψ′∣)=⟨ψ∣ψ′⟩ ⟨ψ′∣ψ⟩\mathrm{Tr}\big(\rho(x)\rho(x')\big)=\mathrm{Tr}\big(\lvert\psi\rangle\langle\psi\vert\psi'\rangle\langle\psi'\rvert\big)=\langle\psi\vert\psi'\rangle\,\langle\psi'\vert\psi\rangle
    Write ψ=ψ(x)\psi=\psi(x), ψ′=ψ(x′)\psi'=\psi(x'); pull out the scalar ⟨ψ∣ψ′⟩\langle\psi\vert\psi'\rangle and use Tr ∣a⟩⟨b∣=⟨b∣a⟩\mathrm{Tr}\,\lvert a\rangle\langle b\rvert=\langle b\vert a\rangle.
  3. Step 3:
    =⟨ψ∣ψ′⟩ ⟨ψ∣ψ′⟩‾=∣⟨ψ∣ψ′⟩∣2=kF(x,x′)=\langle\psi\vert\psi'\rangle\,\overline{\langle\psi\vert\psi'\rangle}=\lvert\langle\psi\vert\psi'\rangle\rvert^2=k_F(x,x')
    Conjugate symmetry ⟨ψ′∣ψ⟩=⟨ψ∣ψ′⟩‾\langle\psi'\vert\psi\rangle=\overline{\langle\psi\vert\psi'\rangle}.
  4. Step 4:
    ⟨A,B⟩HS=Tr(AB)∈R,⟨A,A⟩HS=Tr(A2)=∑i,j∣Aij∣2>0 (A≠0)\langle A,B\rangle_{HS}=\mathrm{Tr}(AB)\in\mathbb R,\quad\langle A,A\rangle_{HS}=\mathrm{Tr}(A^2)=\sum_{i,j}\lvert A_{ij}\rvert^2>0\ (A\ne0)
    For Hermitian A,BA,B: Tr(AB)‾=Tr((AB)†)=Tr(BA)=Tr(AB)\overline{\mathrm{Tr}(AB)}=\mathrm{Tr}\big((AB)^\dagger\big)=\mathrm{Tr}(BA)=\mathrm{Tr}(AB), and Tr(A2)=Tr(A†A)\mathrm{Tr}(A^2)=\mathrm{Tr}(A^\dagger A). It is symmetric and real-bilinear, hence a real inner product on Hermitian matrices.
  5. Step 5:
    kF(x,x′)=⟨ρ(x),ρ(x′)⟩HS ⇒ kF is positive definitek_F(x,x')=\langle\rho(x),\rho(x')\rangle_{HS}\ \Rightarrow\ k_F\ \text{is positive definite}
    The first proposition of this lesson with feature map ϕ=ρ\phi=\rho.
  6. Step 6:
    dim⁡R{A∈C2n×2n:A=A†}=2n+2⋅2n(2n−1)2=4n\dim_{\mathbb R}\{A\in\mathbb C^{2^n\times2^n}:A=A^\dagger\}=2^n+2\cdot\tfrac{2^n(2^n-1)}{2}=4^n
    2n2^n real diagonal entries plus a real and an imaginary part for each of the 2n(2n−1)/22^n(2^n-1)/2 entries above the diagonal (those below are determined). The quantum feature space is exponentially large in nn, yet each kernel value is a single overlap that a quantum circuit can estimate.

∎

References

  1. 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
  2. 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
  3. 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
  4. 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-graded

    Read off the explicit feature space of the inhomogeneous quadratic kernel k(x,x′)=(x⊤x′+1)2k(x,x')=(x^\top x'+1)^2 on R2\mathbb{R}^2 and evaluate the kernel at a pair of points, confirming that the kernel trick and the explicit inner product ϕ(x)⊤ϕ(x′)\phi(x)^\top\phi(x') give the same number.

    Open lab