Skip to content

Nyström approximation and random Fourier features

Replace a large kernel matrix with explicit features. Compare landmark-based Nyström projection with Fourier sampling, and see exactly what a rank-one approximation loses.

Nyström approximation and random Fourier features construct small, explicit feature vectors whose inner products approximate a chosen kernel. They make nonlinear kernel methods usable with linear-model solvers. For a quant fitting execution costs across many orders, the practical attraction is replacing a large table of pairwise order similarities with a manageable table of transformed inputs.

Write the training Gram matrix as Kij=k(xi,xj)K_{ij}=k(x_i,x_j). A feature matrix ZZ has one row z(xi)⊤z(x_i)^\top per observation and aims for

K≈ZZ⊤,k(x,x′)≈z(x)⊤z(x′).K\approx ZZ^\top,\qquad k(x,x')\approx z(x)^\top z(x').
If there are nn observations and rr features, storing ZZ takes nrnr entries instead of n2n^2 for a dense KK. This saves memory when r≪nr\ll n; it does not promise that the resulting predictions match an exact fit. scikit-learn, Kernel approximation

Nyström: keep directions represented by landmarks

Choose mm training inputs as landmarks, indexed by LL. For a real positive semidefinite kernel, define
C=K:,L,W=KL,L,K~=CW†C⊤.C=K_{:,L},\qquad W=K_{L,L},\qquad \widetilde K=CW^{\dagger}C^\top.

Here CC is n×mn\times m, WW is m×mm\times m, and W†W^{\dagger} is the Moore–Penrose pseudoinverse. It equals the inverse when WW is nonsingular. Duplicate or dependent landmark features can make WW singular; an ordinary inverse then does not exist.

If W=U+Λ+U+⊤W=U_+\Lambda_+U_+^\top retains all its strictly positive eigenvalues, an explicit factor is

Z=CU+Λ+−1/2,z(x)⊤=k(x,L)U+Λ+−1/2.Z=CU_+\Lambda_+^{-1/2},\qquad z(x)^\top=k(x,L)U_+\Lambda_+^{-1/2}.
The second expression transforms a new input using the same landmarks and normalization. In feature-space terms, this projects onto the span of the landmark feature vectors. It is data dependent even when the landmarks are sampled randomly. The classical construction and its projection interpretation are developed in Rasmussen and Williams, §8.1, following Williams and Seeger (2001).
Truncation and regularization change the approximation. Dropping small positive eigenvalues gives a truncated pseudoinverse. Replacing W†W^{\dagger} by (W+ηI)−1(W+\eta I)^{-1}, with η>0\eta>0, gives a regularized variant. Neither is the exact all-positive-eigenvalue projection above. State the threshold or η\eta rather than silently treating all three constructions as identical.

A landmark can reproduce similarities and still lose length

Consider a fictional, dimensionless example:

K=(10.50.51).K=\begin{pmatrix}1&0.5\\0.5&1\end{pmatrix}.

This matrix is positive definite: its eigenvalues are 1.51.5 and 0.50.5. Select the first observation as the sole landmark. Then

C=(10.5),W=(1),K~=CC⊤=(10.50.50.25).C=\begin{pmatrix}1\\0.5\end{pmatrix},\qquad W=(1),\qquad \widetilde K=CC^\top= \begin{pmatrix}1&0.5\\0.5&0.25\end{pmatrix}.

The first row and column are exact, but the second diagonal falls from 11 to 0.250.25. Its error is 0.750.75. The approximation has rank one, with eigenvalues 1.251.25 and 00; the original has rank two.

The geometry explains the missing amount independently. Choose exact feature vectors

ϕ1=(1,0)⊤,ϕ2=(1/2,3/2)⊤.\phi_1=(1,0)^\top,\qquad \phi_2=(1/2,\sqrt3/2)^\top.

Their inner products give KK. Projection onto the first landmark removes the second coordinate of ϕ2\phi_2. The lost squared length is (3/2)2=3/4(\sqrt3/2)^2=3/4. Thus the residual is

K−K~=(0000.75).K-\widetilde K=\begin{pmatrix}0&0\\0&0.75\end{pmatrix}.
Exact unitless feature vectors are phi1 equal to (1,0) and phi2 equal to (0.5, square root of 3 divided by 2). Projecting onto the first landmark leaves phi2 with squared length 0.25 instead of 1. The omitted squared perpendicular length is 0.75; the approximate Gram matrix has rank 1.
Exact unitless feature vectors are phi1 equal to (1,0) and phi2 equal to (0.5, square root of 3 divided by 2). Projecting onto the first landmark leaves phi2 with squared length 0.25 instead of 1. The omitted squared perpendicular length is 0.75; the approximate Gram matrix has rank 1.
Original deterministic geometry for the two-observation example. The first landmark retains the horizontal feature direction and discards the vertical direction. Matrix entries are dimensionless inner products.

This is a controlled loss of feature directions, not an identity for the full kernel. In particular, an exact landmark column does not establish a good approximation for the rest of the sample. Dividing the approximate rows by their norms would also change the approximating kernel.

Random Fourier features: sample the kernel's spectrum

Random Fourier features (RFF) use a different construction. For a continuous, real, stationary PSD kernel on Rd\mathbb R^d, write k(x,x′)=κ(x−x′)k(x,x')=\kappa(x-x'). With κ(0)=1\kappa(0)=1, Bochner's theorem provides a spectral probability measure pp satisfying

κ(δ)=Eω∼p[cos⁡(ω⊤δ)].\kappa(\delta)=\mathbb E_{\omega\sim p}[\cos(\omega^\top\delta)].

Draw rr independent frequencies ωj∼p\omega_j\sim p and independent phases bj∼Uniform⁡[0,2π]b_j\sim\operatorname{Uniform}[0,2\pi]. One real-valued map is

zj(x)=2rcos⁡(ωj⊤x+bj),E[z(x)⊤z(x′)]=k(x,x′).z_j(x)=\sqrt{\frac2r}\cos(\omega_j^\top x+b_j),\qquad \mathbb E[z(x)^\top z(x')]=k(x,x').
For the Gaussian kernel k(x,x′)=exp⁡(−∥x−x′∥2/(2ℓ2))k(x,x')=\exp(-\lVert x-x'\rVert^2/(2\ell^2)), draw ωj∼N(0,ℓ−2Id)\omega_j\sim\mathcal N(0,\ell^{-2}I_d). An overall kernel amplitude a>0a>0 requires multiplying the normalized map by a\sqrt a. This is Fourier sampling, not landmark selection. Rahimi and Recht, §3

The equality holds in expectation over draws. A finite realized map has error; increasing the feature count need not improve every pair monotonically. Its Gram matrix is PSD because it is ZZ⊤ZZ^\top, though individual estimated similarities can be negative. Standard RFF requires stationarity; Nyström can also approximate nonstationary PSD kernels. The paired sine/cosine map in the paper's Algorithm 1 is another valid construction, with different feature-count bookkeeping.

Keep the approximation inside the research split

ChoiceNyströmStandard RFF
What fixes the coordinates?Landmark inputs and their kernel matrixKernel spectrum and sampled frequencies/phases
Dependence on observed input valuesDirectNone for a fixed kernel and input dimension
Main approximation budgetLandmark count and retained eigenvaluesNumber of sampled features
What must travel with the fitted model?Landmarks, kernel settings and normalizationFrequencies, phases and kernel settings
Both also need any fitted input preprocessing. In a chronological experiment, fit scaling and select Nyström landmarks using the training window only. Apply those frozen transformations to validation and test observations. Tune bandwidth, feature count and any eigenthreshold or regularization inside the training/validation procedure; selecting them from final test results leaks information. scikit-learn, §§12.1–12.2.1

Fix and record random seeds for reproducibility, and examine sensitivity across seeds without choosing the best seed on the final test set. RFF frequencies are data independent conditional on the kernel, but a bandwidth or scaler estimated using future inputs is still a data-dependent choice. Re-sampling frequencies at prediction time changes the coordinates under an already fitted model.

A linear ridge regression on ZZ is kernel ridge regression for the approximating kernel k~(x,x′)=z(x)⊤z(x′)\widetilde k(x,x')=z(x)^\top z(x'), under matched loss, penalty and intercept conventions. Compare its held-out loss and operational cost with an exact-kernel benchmark when feasible; kernel approximation error alone is not a trading-performance measure.
For the underlying feature-map intuition, The Kernel Trick: Feature Maps and Properties of Kernels develops explicit inner products and the Gaussian kernel. The full lesson requires membership; its preview is public.

Sources

Last updated
  • kernel methods
  • nystrom approximation
  • random fourier features
  • low rank approximation
← Back to the glossaryBack to top ↑