Reproducing Kernel Hilbert Spaces
From vectors to the representer theorem, with the math background taught along the way.
Linear regression with more parameters than data points has many perfect fits. A standard way to choose among them is to pick the fit with the smallest weight norm . That choice needs two ingredients. You need a space of candidate models, and you need a way to measure how big each candidate is.
Now suppose you want to fit a nonlinear function directly, with no weight vector in sight. The candidates are functions, and the space of functions has infinitely many dimensions. What does the size of a function even mean? And how could a computer search an infinite-dimensional space?
A reproducing kernel Hilbert space (RKHS) is a space of functions designed to answer both questions. It comes with a norm that measures how complicated a function is. And the best fit in the entire infinite-dimensional space can be found by solving an linear system, where is the number of data points. It is also the shared language of kernel methods, Gaussian processes, and the neural tangent kernel theory of wide networks.
Notation
| Symbol | Meaning |
|---|---|
| The set of possible inputs. On this page it is usually the real line. | |
| Functions from to . Blue everywhere. | |
| A Hilbert space whose elements are functions on . | |
| The inner product of two functions in . | |
| The norm of , equal to . Magenta everywhere. | |
| A linear functional, a linear map from a vector space to . | |
| The evaluation functional at . It sends to the number . | |
| The part of inside a subspace and the part orthogonal to . | |
| The kernel, a function of two inputs. Green everywhere. | |
| The kernel with one slot fixed. It is the function , a bump centered at . | |
| The training points. Data is orange everywhere. | |
| The kernel matrix with entries . | |
| A vector of coefficients, one per training point. | |
| A feature map that turns an input into a vector of features. | |
| Regularization strength. |
Functions are vectors
You already think of a vector in as a list of three numbers. Another way to say the same thing is that a vector assigns a number to each index 1, 2, 3. That is a function on the set .
So a function is a vector with one coordinate per input. A function on the real line has one coordinate for every real number, which is why function spaces are infinite-dimensional.
Let . Take with and with . As vectors these are and .
Adding functions pointwise is adding vectors. gives . Scaling works the same way. gives .
A set of functions is a vector space if it is closed under pointwise addition and scalar multiplication. For all and , both and are in .
Takeaway. A function is a vector whose coordinates are indexed by inputs, so everything you know about vectors is worth trying on functions.
Inner products and norms
In the dot product gives you geometry. It gives lengths through , and it tells you when two vectors are perpendicular. To do geometry with functions we need the same tool.
An inner product is any rule that takes two vectors and returns a number, as long as it behaves like the dot product. For functions on a finite set, the dot product itself works. For functions on an interval, the sum over coordinates becomes an integral.
On with and we get and .
On with and , the integral version gives
This integral inner product is called the inner product. Remember it, because Step 4 shows it is the wrong choice for learning.
An inner product on a vector space is a map with three properties, for all and .
- Symmetry. .
- Linearity. .
- Positivity. , and only when .
The norm is .
Two elements and are orthogonal, also called perpendicular, if . An element is orthogonal to a subspace if it is orthogonal to everything in it.
In the vectors and are orthogonal because . On with the integral inner product, and are orthogonal because .
The one inequality we will use everywhere
For any and in an inner product space, the inner product is never bigger than the product of the norms.
Here is the proof, since we lean on this three times later. Assume and pick any number .
Move the fraction to the left side, multiply by , and take square roots. That is the inequality.
Takeaway. An inner product gives a function space lengths and angles, and Cauchy–Schwarz bounds any inner product by the two lengths.
Hilbert spaces and projection
In infinite dimensions a new problem appears. A sequence of perfectly nice functions can converge to something that is no longer in your space. It is the same problem the rationals have, where are all rational and the limit is not.
A space with no such holes is called complete. A Hilbert space is an inner product space that is complete. Completeness is what guarantees that minimizers and limits exist, so that when we later ask for the best function, there is one.
Take continuous functions on with the norm. Let be 0 on the left, 1 on the right, with a straight ramp of width in the middle. Each is continuous.
As grows the ramps get steeper and the functions get closer to each other in norm. The thing they converge to is a step function, which is not continuous. The space of continuous functions with this norm has a hole exactly there.
A sequence converges to if as . The sequence is Cauchy if as . A space is complete if every Cauchy sequence converges to an element of the space. A Hilbert space is a complete inner product space.
with the dot product is a Hilbert space. Every finite-dimensional inner product space is one too.
Orthogonal projection
The second thing we need from Hilbert spaces is the shadow of a vector on a subspace. Given a subspace , any vector splits into a part inside and a part perpendicular to all of .
In let be the floor, spanned by and . The vector splits as plus . The squared lengths add up. .
Let be a finite-dimensional subspace of an inner product space. Every can be written as , where and for every . The squared norms add.
Here is the proof. Finite-dimensional subspaces are the only case we need. Pick perpendicular unit vectors that span . The Gram–Schmidt procedure from linear algebra produces them. Define and .
So is perpendicular to every , and therefore to everything in . The lengths then obey Pythagoras.
Takeaway. A Hilbert space is an inner product space with no holes, and in it any vector splits into a piece inside a subspace plus a perpendicular piece whose squared lengths add.
Why the obvious norm fails
The space from Step 2 is a Hilbert space, so why not use it? Because learning is about function values at points. We observe at training inputs and we want at test inputs. A useful norm should control those values. The norm does not.
Pause and predictA function is 1 at and falls linearly to 0 within a distance on each side. As shrinks toward zero, what happens to its norm? What happens to its value at ?
The value at stays exactly 1 while the norm goes to zero. Check it with the slider below. In , a function can be almost the zero function and still be far from zero at the one point you care about.
The norm in the readout comes from a direct calculation. The spike is two mirror-image ramps, so
It is even worse than the plot suggests. Changing a function at a single point does not change any integral. So the norm cannot see the value at all. Making fully rigorous requires treating functions that differ on negligible sets as the same object, which needs measure theory. We will not need that, because the spaces we build next avoid the problem.
Takeaway. In , being small in norm tells you nothing about being small at a point, so is the wrong space for learning from point values.
The definition of an RKHS
The fix is to demand exactly the property lacks. We want a Hilbert space of functions where a small norm forces small values at every point. That demand is the entire definition of an RKHS.
To state it we need one new term. A linear functional is a machine that eats a vector and returns a single number, and does so linearly.
Let be a vector space. A linear functional on is a map that respects addition and scaling. For all and all numbers ,
In the map for a fixed vector is a linear functional. For instance on sends to . The map is not one, because doubling doubles the norm but negating does not negate it.
The functional we care about reads off the value of a function at one fixed input.
Let be a vector space of functions on and fix an input . The evaluation functional at is the map defined by
It is a linear functional because functions add and scale pointwise. We have .
On with the dot product, take . Evaluation at the third point gives . And . A coordinate is never bigger than the length of the whole vector, so here evaluation is controlled by the norm with constant 1.
A linear functional on a Hilbert space is bounded if there is a constant with for every .
A reproducing kernel Hilbert space on is a Hilbert space whose elements are functions , such that for every the evaluation functional is bounded. For each there is a constant with
In an RKHS, for all and every ,
In particular, if then at every point .
The proof is one line. We have , where the equality uses linearity of and the inequality is boundedness.
Spikes are therefore impossible. A function with must have norm at least .
Notice that no kernel has appeared yet. The name promises a kernel, and the next step shows that boundedness alone forces one to exist.
Takeaway. An RKHS is a Hilbert space of functions in which the value at each point is controlled by the norm.
Where the kernel comes from
In every linear functional is a dot product with some fixed vector. If is linear then , where collects the values of on the basis vectors. The same fact holds in any Hilbert space for bounded functionals. It is called the Riesz representation theorem.
On let . Then with . The functional is fully described by one vector living in the same space.
Let be a bounded linear functional on a Hilbert space . Then there is exactly one element such that for every .
Here is the proof in finite dimensions. Take perpendicular unit vectors spanning the space, so that .
So works. It is also the only choice. If and both work, then for every . Choosing gives , so .
In infinite dimensions the same idea works, and boundedness is exactly what makes the infinite sum converge. I am stating the infinite-dimensional theorem without its full proof. This is also the place where completeness from Step 3 is needed.
Apply Riesz to evaluation
In an RKHS each evaluation functional is bounded. So the Riesz theorem hands us, for each input , one special function in .
Let be an RKHS on . For each , let be the element that the Riesz theorem gives for . It satisfies the reproducing property
The reproducing kernel of is the function of two inputs
Taking the inner product with reproduces the value of at . The function plays the role that the coordinate vector plays for reading off the third coordinate.
Let be the reproducing kernel of an RKHS . Then
- is symmetric, so .
- Its slices are the special functions, so .
- is positive semidefinite. For any points and numbers we have .
- Every satisfies .
The proof takes the four parts in turn.
It is symmetric. because inner products are symmetric.
Its slices are the special functions. Apply the reproducing property to the function at the point .
So is the function you get from by fixing the second slot at , which is what means.
It is positive semidefinite. Take any points and any numbers .
In matrix language, the kernel matrix with satisfies for every .
It bounds function values. By the reproducing property and Cauchy–Schwarz,
This is the best possible constant in the definition of an RKHS.
Let be all linear functions on , written , with inner product . Which function reproduces evaluation at ? We need for all , so . The kernel is .
With and we get , and . This is called the linear kernel. Ordinary linear regression already lives in an RKHS.
Takeaway. Bounded evaluation forces the existence of a kernel , which is symmetric, positive semidefinite, and reads off function values through .
Building the space from a kernel
Step 6 went from a space to a kernel. In practice people go the other way. They pick a kernel and let it define the space. This works because any symmetric positive semidefinite function is the kernel of exactly one RKHS.
A function is a kernel (also called a positive definite kernel) if it is symmetric and for every , every choice of points , and every ,
The literature says "positive definite kernel" for this condition even though the inequality is not strict.
The Gaussian kernel on the real line is . The number is called the lengthscale. For and the points and , the kernel matrix is
The last inequality holds because the cross term can never outweigh .
A non-example is distance. Take with the same two points. Then has zeros on the diagonal and ones off it. Choosing gives . So not every similarity-like function is a kernel.
The construction
Start with the bump functions , one for each input . Step 6 says these must be in the space. So take all finite weighted sums of bumps.
Step 6 also says what the inner product between two bumps must be, namely . Extending by linearity leaves no choice for sums. If then
Check that the reproducing property holds with this inner product. Take , a single bump with weight 1.
The last equality is just the definition of evaluated at . Finally, fill the holes by adding the limits of Cauchy sequences, as in Step 3.
For every kernel on there is exactly one RKHS of functions on whose reproducing kernel is . It is the completion of the space of finite sums under the inner product above.
The theorem appears in Aronszajn (1950), who credits the idea to E. H. Moore. Three details are skipped here. The inner product does not depend on how is written as a sum. It is strictly positive for . And the limits added during completion are still genuine functions on . All three are proved in the references at the end.
Pause and predictPlace two Gaussian bumps almost on top of each other. Case A gives both weight . Case B gives them weights and . Both have . Which case has the larger RKHS norm?
Case A. The bumps overlap, so and . That is about in case A and about in case B. This makes sense because in case B the two bumps cancel and is nearly the zero function. The norm measures the function, not the coefficients. Try both cases below.
While you play, check the bound from Step 6. For the Gaussian kernel , so at every point. The maximum of in the readout never exceeds the square root of the norm readout.
Takeaway. Choosing a kernel chooses the space. Its functions are weighted sums of kernel bumps and their limits, and the squared norm of such a sum is .
The feature map view
There is a second way to see the same space, and it connects straight back to linear regression. A kernel is a dot product between feature vectors. An RKHS is the set of linear models on those features, and the RKHS norm is the weight norm.
Take the polynomial kernel on the real line. Expand the square.
Check with and . The kernel gives . The features are and , with dot product .
Now consider all linear models on these features, . Give them the inner product . Is this the RKHS of the polynomial kernel? Check the reproducing property. The bump is the model with weights , since . Then
It reproduces. By the uniqueness in Step 7, this space of quadratics with the weight-norm is the RKHS. For instance has weights and norm 1, while has weights and norm about .
Suppose for some map from into a Hilbert space of feature vectors. Then the RKHS of is the set of functions , and
The minimum matters when several weight vectors give the same function. The RKHS norm is the norm of the smallest one. Every kernel has at least one feature map, namely with . Feature maps are not unique, but they all give the same RKHS.
The Gaussian kernel needs infinitely many features. For , split the exponent and use the Taylor series of .
So Gaussian-kernel regression is linear regression on infinitely many features. No computer could store , yet is one line of code. Using to get feature dot products without computing features is called the kernel trick.
This is the link to overparameterized linear regression. The minimum-norm interpolator there picks the smallest among weights that fit the data. In an RKHS, picking the smallest is the same act, carried out in a feature space that may be infinite-dimensional.
Takeaway. An RKHS is the set of linear models on some feature map, and the RKHS norm is the smallest weight norm that produces the function.
What the norm measures
The RKHS norm is a complexity measure. A function with small norm cannot be large and cannot change quickly. How quickly it may change is set by the kernel.
Let be an RKHS with kernel . For every and all inputs ,
The size bound was part 4 of the lemma in Step 6. To prove the bound on change, compare the values at two points using the reproducing property.
Gaussian kernel with and two points a distance apart. The square root is . So any in this RKHS satisfies . To jump by 1 over that short distance, a function needs norm at least 10.
For some kernels the norm has an explicit formula. For the Laplace kernel on the real line it is
That formula penalizes both size and slope. For the Gaussian kernel the penalty involves derivatives of every order, which is why its functions are extremely smooth. The Laplace formula is quoted here as a standard result without a derivation.
Takeaway. A small RKHS norm means the function is small and changes slowly, with the kernel deciding what slowly means.
The representer theorem
We can now pose the learning problem. Among all functions in , find the one that fits the data well and has small norm.
The first term is the fit to the data. The second is the complexity penalty, with setting the trade-off.
Pause and predictFor the Gaussian kernel, is infinite-dimensional. How many numbers do you expect it takes to write down the exact minimizer for data points?
Exactly . The minimizer is a weighted sum of the bumps centered at the training inputs. Every other direction in the infinite-dimensional space is useless, for a reason the proof below makes precise.
Any minimizer of the problem above has the form
The same holds if the squared error is replaced by any loss that depends on only through , and if is replaced by any strictly increasing function of . The squared-error case goes back to Kimeldorf and Wahba around 1970. The general version is due to Schölkopf, Herbrich and Smola (2001).
Proof
Let be the subspace spanned by the bumps . It is finite-dimensional, so by Step 3 any splits as with perpendicular to every bump.
The fit term cannot see . At each training point,
So and agree on all the training data and have the same fit term.
The penalty can only grow with . By Pythagoras from Step 3, .
Putting these together, if then dropping it keeps the fit identical and strictly lowers the penalty. So a minimizer must have . It lies in , which means it is a weighted sum of the bumps.
Takeaway. Anything perpendicular to the training bumps is invisible to the data and costs norm, so the best function is always a sum of bumps at the training inputs.
Kernel ridge regression
The representer theorem turns a search over functions into a search over numbers. All that is left is to plug into the objective and solve for .
The minimizer of the problem in Step 10 is
Here is the derivation. Both terms become matrix expressions. The prediction at a training point is . The squared norm is from Step 7. So the objective is
Set the gradient to zero.
The bracket is zero when
The matrix is always invertible, because is positive semidefinite and . Since is convex, this stationary point is a minimizer.
If two training inputs coincide, is singular and other vectors also make the gradient zero. They differ from ours by some with . The function has squared norm , so it is the zero function. Every solution therefore gives the same .
Two data points, and . Gaussian kernel with and .
The fitted values are and , pulled slightly away from the targets and . The squared norm is .
It contains ordinary ridge regression
With the linear kernel , the kernel ridge prediction is , where is the ordinary ridge regression solution.
To see this, use the linear kernel. Then , where the rows of are the training inputs. The prediction at a new is
The last line is . The swap is valid because . Both sides equal . Multiply by the two inverses on either side and you get the swap.
Notice what changed. The familiar ridge formula inverts a matrix, one row per parameter. The kernel formula inverts an matrix, one row per data point. When features are infinite, only the second is possible.
As the fit passes through every training point when is invertible, with . Among all functions in that interpolate the data, this one has the smallest norm. It is the function-space twin of the minimum-norm interpolator of overparameterized linear regression.
Pause and predictIn the playground below, you will push toward zero. The curve must then pass through every noisy point. What do you expect to happen to , and does a larger lengthscale make that better or worse?
The norm grows, and a larger lengthscale makes it much worse. Wide bumps are nearly identical to their neighbors, so matching noisy targets needs huge weights of alternating sign that almost cancel. The norm readout can jump by many orders of magnitude. With a short lengthscale each bump handles its own point and the norm stays modest.
Takeaway. Kernel ridge regression is . It is ridge regression in feature space, computed with an solve no matter how many features there are.
The whole chain in one place
- Functions are vectors, so a set of functions can be a vector space.
- An inner product gives that space a norm and Cauchy–Schwarz.
- Completeness makes it a Hilbert space, where projections and Pythagoras work.
- The norm does not control values at points, so it is a poor fit for learning.
- An RKHS is a Hilbert space of functions where each point evaluation is bounded by the norm.
- By Riesz, bounded evaluation produces with , and is symmetric and positive semidefinite.
- Conversely every such defines one RKHS, made of sums of bumps with .
- Equivalently it is linear models on a feature map, with the RKHS norm equal to the smallest weight norm.
- The norm bounds how large is and how fast it changes.
- Regularized fitting over the whole space always lands on a sum of training bumps.
- For squared loss the coefficients are .
Common misconceptions
"The Gaussian RKHS contains every reasonable function." It does not. On an interval it contains no nonzero constant function and no nonzero polynomial (Steinwart, Hush and Scovel 2006, Minh 2010). What is true is that its functions can approximate any continuous function on a bounded closed interval as closely as you like (Steinwart 2001). The approximating functions pay with an exploding norm.
"The RKHS norm is some version of the norm." They are different. A function can have a tiny norm and a huge RKHS norm, as the playground shows when the fit wiggles through noise.
" is the sum of squared coefficients." It is . Overlapping bumps interact, as in the Step 7 prediction.
"Any similarity function is a kernel." It must be symmetric and positive semidefinite. Distance is a non-example.
"The feature map is part of the definition." Many different feature maps give the same kernel, and they all give the same RKHS. The kernel is the canonical object.
"Kernel methods are a different thing from linear models." They are linear models, in a feature space chosen through . All the nonlinearity is in the fixed map . Nothing about is learned from data.
Blind spots worth knowing about
The spectral view (Mercer's theorem). Under mild conditions a kernel can be expanded as with eigenvalues and orthonormal eigenfunctions , the function analog of diagonalizing a symmetric matrix. Then , where is the component of along . Directions with small eigenvalues are expensive, and those are typically the high-frequency ones. This is the tool behind most precise generalization analyses of kernel regression, and it is how the analysis of double descent in linear regression (Hastie et al., listed below) extends beyond plain linear features.
Gaussian processes. A Gaussian process uses the same as a covariance function for a random function. Its posterior mean with noise variance is exactly the kernel ridge solution above. A subtle point is that random draws from the process are typically rougher than anything in the RKHS and almost surely lie outside it when the RKHS is infinite-dimensional. Kanagawa et al. (2018) is the reference for these connections.
The neural tangent kernel. Jacot, Gabriel and Hongler (2018) showed that an infinitely wide network, under a particular scaling of the initialization, trains like kernel regression with a fixed kernel determined by the architecture. This is the main reason deep learning theory talks about RKHSs. It is also a limitation. A fixed kernel means the features never change. Other scalings of the network, such as the maximal update parameterization (µP), are designed so that features keep moving at infinite width. That is the regime this theory does not describe.
Beyond RKHS norms. The RKHS norm is an norm on a fixed set of features. Networks that learn features behave more like an -type norm over an infinite pool of possible neurons, which can adapt to structure such as dependence on a few input directions. Bach (2017) contrasts the two function spaces. If you ever see "Barron space" or "variation norm", this is that story.
Random features. Rahimi and Recht (2007) approximate a kernel with a finite number of random features and then run plain ridge regression. This gives a bridge between kernel regression () and the parameter-count axis in double descent plots.
Interpolation without regularization. The limit, sometimes called ridgeless kernel regression, fits noise exactly and can still generalize in high dimensions. Belkin, Ma and Mandal (2018) argued that this puzzle already appears in kernel methods, not only in deep networks.
Cost. The solve takes time proportional to and memory proportional to . That scaling is the practical reason kernel methods lost ground to networks on large datasets.
Sources and further reading
- T. Hastie, A. Montanari, S. Rosset and R. Tibshirani (2019). Surprises in high-dimensional ridgeless least squares interpolation. For minimum-norm interpolation and double descent in linear regression.
- N. Aronszajn (1950). Theory of reproducing kernels. Transactions of the American Mathematical Society 68. The original source for Steps 5 to 7.
- G. Kimeldorf and G. Wahba (1970). A correspondence between Bayesian estimation on stochastic processes and smoothing by splines. Annals of Mathematical Statistics 41. Also their 1971 paper, Some results on Tchebycheffian spline functions.
- B. Schölkopf, R. Herbrich and A. Smola (2001). A generalized representer theorem. COLT 2001. The proof in Step 10 follows theirs.
- M. Kanagawa, P. Hennig, D. Sejdinovic and B. Sriperumbudur (2018). Gaussian processes and kernel methods, a review on connections and equivalences. A readable modern reference for most of this page.
- I. Steinwart, D. Hush and C. Scovel (2006). An explicit description of the reproducing kernel Hilbert spaces of Gaussian RBF kernels. IEEE Transactions on Information Theory 52. And H. Q. Minh (2010), Some properties of Gaussian reproducing kernel Hilbert spaces, Constructive Approximation 32.
- A. Jacot, F. Gabriel and C. Hongler (2018). Neural tangent kernel, convergence and generalization in neural networks.
- F. Bach (2017). Breaking the curse of dimensionality with convex neural networks. JMLR 18.
- M. Belkin, S. Ma and S. Mandal (2018). To understand deep learning we need to understand kernel learning.
- A. Rahimi and B. Recht (2007). Random features for large-scale kernel machines. NeurIPS 2007.
- Textbooks. Schölkopf and Smola, Learning with Kernels (2002). Steinwart and Christmann, Support Vector Machines (2008), for full proofs of everything stated without proof here.