Scaling Kernel Methods
Nyström approximation and random Fourier features.
Exact kernel methods hit a wall: an matrix and an solve, which at a million examples means terabytes of memory and about operations. Two ideas break the wall. Replace the Gram matrix by a low-rank approximation built from a few landmarks or a few random features, and replace exact factorizations by well-preconditioned iterations. The surprise is statistical: far less computation than loses nothing in accuracy.
What you’ll learn
- Quantify the time and memory of exact kernel ridge regression, and explain why fast eigenvalue decay and the effective degrees of freedom make low-rank approximation possible.
- Derive the Nyström approximation as a projection, and Nyström kernel ridge regression with its cost; state column-sampling guarantees.
- Derive random Fourier features from Bochner's theorem and bound their approximation error.
- Explain why about landmarks or features suffice statistically, and how preconditioned solvers (FALKON, EigenPro) and GPU iterations reach millions of points.
The cubic wall, and why it can be broken
| Gram matrix (8-byte entries) | Cholesky, about operations | |
|---|---|---|
| 0.8 GB | ||
| 80 GB | ||
| 8 TB |
The wall can be broken because the Gram matrix of a smooth kernel is nearly low-rank. Its eigenvalues decay fast (faster than any power of for the Gaussian kernel when the inputs lie in a bounded region), and kernel ridge regression barely uses the small ones: its fitted values are , which multiplies the -th eigendirection of by . The number of directions that survive is the effective degrees of freedom,
typically far smaller than . An approximation that keeps the top few hundred or thousand directions and discards the rest discards mostly what the penalty would have suppressed anyway.
Nyström: a few landmarks
Pick landmarks , for instance a uniform random subset of the training points. Let hold the kernel values between all points and the landmarks, and those among the landmarks. The Nyström approximation is
Why this formula: let be the orthogonal projection of feature space onto . With , the projected features have inner products
So is an honest Gram matrix (of projected features), exact on the landmark columns, and the error is the Gram matrix of the residuals , hence positive semidefinite: Nyström never overestimates. The name comes from Nyström's quadrature method for integral equations, which Williams & Seeger (2001) applied to kernel machines.
Nyström kernel ridge regression. Restrict the function to the landmark sections, , and minimize . Forming costs , the solve , the memory :
Why is the Nyström error always positive semidefinite?
- Because the landmarks are sampled at random
- Because it is the Gram matrix of the residual features left after projecting onto the landmarks' span
- Because is positive semidefinite
- It is not; Nyström errors can have either sign
Show the answer
B. Because it is the Gram matrix of the residual features left after projecting onto the landmarks' span
is the Gram matrix of the projected features , and with orthogonal parts, so (Gram matrix of residuals). Any Gram matrix is PSD. The approximation only ever loses energy, whichever landmarks are used.
Random Fourier features
Bochner writes the kernel as an average over random frequencies:
Split the cosine with a random phase. Since , and the second term averages to zero over :
Replace the expectation by an average over independent draws. The result is an explicit, data-independent feature map whose inner products are unbiased for the kernel: random Fourier features (Rahimi & Recht, 2007).
Each term lies in , so Hoeffding's inequality bounds the error at a fixed pair of points. Uniformly over a compact set , a union bound over a net plus a Lipschitz argument shows that features give error at most everywhere with constant probability, where . Rahimi & Recht (2007) proved this for paired features , , each pair contributing to the inner product; Sutherland & Schneider (2015) proved a bound of the same order, with worse constants, for the random-phase features above, which also have the higher variance of the two for the Gaussian kernel at equal dimension.
With random Fourier features the kernel is approximated to about . Roughly how many features bring the typical error down to ?
Show the answer
9000 features
The error of an average of independent terms shrinks like , so a threefold smaller error needs times the features: about 9,000. Every extra digit costs a hundred times more features, which is why random features are used for learning, where an error well below the statistical error of order is wasted, rather than for evaluating kernels precisely.
Approximating the kernel to accuracy everywhere is the wrong target for learning. The regularized solution only uses the directions above the noise level, and the statistical error is already of order . Rudi & Rosasco (2017) showed that for kernel ridge regression with chosen for the rate, about random features suffice to keep that rate. For that is about features and roughly operations instead of .
| Property | Nyström | Random Fourier features |
|---|---|---|
| Applies to | any kernel | shift-invariant kernels (Bochner); other random expansions exist for dot-product kernels |
| Basis | data-dependent: kernel sections at landmarks | data-independent: random cosines |
| Adapts to the spectrum | yes; with a large eigengap its generalization bound can be far better (Yang et al., 2012) | no; frequencies follow whatever the data |
| Training cost | , or one pass of SGD on | |
| Streaming and distributed | landmarks must be chosen first | features are fixed in advance, so data can stream |
Iterative solvers and preconditioning
The other road keeps the exact problem and avoids the factorization. Conjugate gradients (CG) solves with one matrix–vector product per iteration: time, and memory if the kernel is recomputed in blocks. Its speed depends on the condition number , which is large exactly when statistics asks for a small .
- FALKON (Rudi, Carratino & Rosasco, 2017) combines both roads: Nyström kernel ridge regression with about landmarks, solved by CG with a Nyström-based preconditioner that makes the system well conditioned, so that about iterations suffice. It reaches optimal statistical accuracy with essentially memory and time.
- EigenPro (Ma & Belkin, 2017) starts from an observation about gradient descent on kernel least squares: it converges quickly only along the top eigendirections of , so for smooth kernels a polynomial number of iterations reaches only a vanishingly small part of the function space. Its preconditioner flattens the top eigenvalues to the -th, , which permits far larger steps and suits mini-batches on GPUs.
- Exact Gaussian processes on GPUs replace the Cholesky factorization by CG and Lanczos iterations built from matrix–matrix products; with these, exact GP regression has been run on more than a million points (Wang et al., 2019). Structured kernel interpolation (Wilson & Nickisch, 2015) goes further by interpolating onto a grid where has fast Kronecker or Toeplitz products.
Key takeaways
- Exact kernel ridge regression needs memory and time, but the Gram matrix of a smooth kernel is nearly low-rank, and only about directions matter.
- Nyström: is the Gram matrix of features projected onto the landmarks' span, so its error is PSD. Nyström kernel ridge regression costs time and memory.
- Random Fourier features: by Bochner's theorem a shift-invariant kernel is , so random cosines approximate it with error , independently of the data.
- About landmarks or features preserve the worst-case rate of exact kernel ridge regression, and leverage-score sampling needs only about . FALKON attains optimal accuracy in time and memory; EigenPro and GPU conjugate gradients scale exact solvers further.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Nyström kernel ridge regression with landmarks on training points costs, in time and memory,
- time and memory, as for the exact method
- time and memory
- time and memory
- time and memory
Show the answer
C. time and memory
It needs the block ( memory), the product ( time) and one solve (). The full Gram matrix is never formed.
For which kernel are random Fourier features obtained by drawing the frequencies from a Gaussian distribution?
- The Laplacian kernel
- The polynomial kernel
- Any positive-definite kernel
- The Gaussian RBF kernel , with
Show the answer
D. The Gaussian RBF kernel , with
By Bochner's theorem the sampling distribution is the kernel's normalized Fourier transform, and the Fourier transform of a Gaussian is a Gaussian, with the inverse width: a short length scale means high frequencies.
A random-feature approximation of a kernel uses features. How does its error at a fixed pair of points typically shrink?
- Like : quadrupling halves the error
- Like : doubling halves the error
- Exponentially in
- It does not shrink: random features have a fixed bias
Show the answer
A. Like : quadrupling halves the error
is an average of independent, bounded, unbiased terms, so its standard deviation scales as and Hoeffding gives tails .
Why can about landmarks or random features match the worst-case learning rate of exact kernel ridge regression on points?
- Because every Gram matrix has rank at most
- Because the estimator's statistical error is already of order , and the regularized solution only uses the directions above , which a modest number of landmarks or features captures
- Because the Nyström approximation is exact for the Gaussian kernel
- Because the test error does not depend on the kernel
Show the answer
B. Because the estimator's statistical error is already of order , and the regularized solution only uses the directions above , which a modest number of landmarks or features captures
An approximation only needs to be good where it matters: on the top directions, about of them, and up to an error smaller than the unavoidable . That is what the analyses of Rudi, Camoriano & Rosasco (2015) and Rudi & Rosasco (2017) make precise.
Further reading
- C. K. I. Williams & M. Seeger, "Using the Nyström method to speed up kernel machines," Advances in Neural Information Processing Systems 13, 682–688 (2001).
- P. Drineas & M. W. Mahoney, "On the Nyström method for approximating a Gram matrix for improved kernel-based learning," Journal of Machine Learning Research 6, 2153–2175 (2005).
- A. Rahimi & B. Recht, "Random features for large-scale kernel machines," Advances in Neural Information Processing Systems 20 (2007).
- A. Rudi & L. Rosasco, "Generalization properties of learning with random features," Advances in Neural Information Processing Systems 30 (2017).
- A. Rudi, L. Carratino & L. Rosasco, "FALKON: an optimal large scale kernel method," Advances in Neural Information Processing Systems 30 (2017).