# Low-rank matrix approximations

Low-rank matrix approximations are essential tools in the application of kernel methods to large-scale learning problems.

Kernel methods (for instance, support vector machines or Gaussian processes) project data points into a high-dimensional or infinite-dimensional feature space and find the optimal splitting hyperplane. In the kernel method the data is represented in a kernel matrix (or, Gram matrix). Many algorithms can solve machine learning problems using the kernel matrix. The main problem of kernel method is its high computational cost associated with kernel matrices. The cost is at least quadratic in the number of training data points, but most kernel methods include computation of matrix inversion or eigenvalue decomposition and the cost becomes cubic in the number of training data. Large training sets cause large storage and computational costs. Despite low rank decomposition methods (Cholesky decomposition) reduce this cost, they continue to require computing the kernel matrix. One of the approaches to deal with this problem is low-rank matrix approximations. The most popular examples of them are Nyström method and the random features. Both of them have been successfully applied to efficient kernel learning.

## Nyström approximation

Kernel methods become unfeasible when the number of points $n$ is so large such that the kernel matrix ${\hat {K}}$ cannot be stored in memory.

If $n$ is the number of training examples, the storage and computational cost required to find the solution of the problem using general kernel method is $O(n^{2})$ and $O(n^{3})$ respectively. The Nyström approximation can allow a significant speed-up of the computations. This speed-up is achieved by using instead of the kernel matrix its approximation ${\tilde {K}}$ of rank $q$ . An advantage of the method is that it is not necessary to compute or store the whole kernel matrix, but only its block of size $q\times n$ .

It reduces the storage and complexity requirements to $O(nq)$ and $O(nq^{2})$ respectively.

### Theorem for kernel approximation

${\hat {K}}$ is a kernel matrix for some kernel method. Consider the first $q points in the training set. Then there exists matrix ${\tilde {K}}$ of rank $q$ :

${\tilde {K}}={\hat {K}}_{n,q}{\hat {K}}_{q}^{-1}{\hat {K}}_{n,q}^{\text{T}}$ , where

$({\hat {K}}_{q})_{i,j}=K(x_{i},x_{j}),i,j=1,\dots ,q$ ,

${\hat {K}}_{q}$ is invertible matrix

and

$({\hat {K}}_{n,q})_{i,j}=K(x_{i},x_{j}),i=1,\dots ,n{\text{ and }}j=1,\dots ,q.$ #### Proof

##### Singular-value decomposition application

Applying singular-value decomposition (SVD) to matrix $A$ with dimensions $p\times m$ produces a singular system consisting of singular values $\{\sigma _{j}\}_{j=1}^{k},{\text{ }}(\sigma _{j}>0{\text{ }}\forall j=1,\dots ,k),$ vectors $\{v_{j}\}_{j=1}^{m}\in \mathbb {C} ^{m}$ and $\{u_{j}\}_{j=1}^{p}\in \mathbb {C} ^{p}$ such that they form orthonormal bases of $\mathbb {C} ^{m}$ and $\mathbb {C} ^{p}$ respectively:

${\begin{cases}A^{\text{T}}Av_{j}=\sigma _{j}v_{j},{\text{ }}j=1,\dots ,k,\\A^{\text{T}}Av_{j}=0,{\text{ }}j=k+1,\dots ,m,\\AA^{\text{T}}u_{j}=\sigma _{j}u_{j},{\text{ }}j=1,\dots ,k,\\AA^{\text{T}}u_{j}=0,{\text{ }}j=k+1,\dots ,p.\end{cases}}$ If $U$ and $V$ are matrices with $u$ ’s and $v$ ’s in the columns and $\Sigma$ is a diagonal $p\times m$ matrix having singular values $\sigma _{i}$ on the first $k$ -entries on the diagonal (all the other elements of the matrix are zeros):

${\begin{cases}Av_{j}={\sqrt {\sigma _{j}}}u_{j},{\text{ }}j=1,\dots ,k,\\Av_{j}=0,{\text{ }}j=k+1,\dots ,m,\\A^{\text{T}}u_{j}={\sqrt {\sigma _{j}}}v_{j},{\text{ }}j=1,\dots ,k,\\A^{\text{T}}u_{j}=0,{\text{ }}j=k+1,\dots ,p,\end{cases}}$ then the matrix $A$ can be rewritten as:

$A=U\Sigma ^{1/2}V^{\text{T}}$ .

##### Further proof
• ${\hat {X}}$ is $n\times D$ data matrix
• ${\hat {K}}={\hat {X}}{\hat {X}}^{\text{T}}$ • ${\hat {C}}={\hat {X}}^{\text{T}}{\hat {X}}$ Applying singular-value decomposition to these matrices:

${\hat {X}}={\hat {U}}{\hat {\Sigma }}^{1/2}{\hat {V}}^{\text{T}},{\text{ }}{\hat {K}}={\hat {U}}{\hat {\Sigma }}{\hat {U}}^{T},{\text{ }}{\hat {C}}={\hat {V}}{\hat {\Sigma }}{\hat {V}}^{\text{T}}.$ • ${\hat {X}}_{q}$ is the $q\times D$ -dimensional matrix consisting of the first $q$ rows of matrix ${\hat {X}}$ • ${\hat {K}}_{q}={\hat {X}}_{q}{\hat {X}}_{q}^{\text{T}}$ • ${\hat {C}}={\hat {X}}^{\text{T}}{\hat {X}}$ Applying singular-value decomposition to these matrices:

${\hat {X}}_{q}={\hat {U}}_{q}{\hat {\Sigma }}_{q}^{1/2}{\hat {V}}_{q}^{\text{T}},{\text{ }}{\hat {K}}_{q}={\hat {U}}_{q}{\hat {\Sigma }}_{q}{\hat {U}}_{q}^{T},{\text{ }}{\hat {C}}_{q}={\hat {V}}_{q}{\hat {\Sigma }}_{q}{\hat {V}}_{q}^{\text{T}}.$ Since ${\hat {U}},{\text{ }}{\hat {V}},{\hat {U}}_{q}{\text{ and }}{\hat {V}}_{q}$ are orthogonal matrices,

${\hat {U}}={\hat {X}}{\hat {V}}{\hat {\Sigma }}^{-1/2},{\text{ }}{\hat {V}}_{q}={\hat {X}}_{q}^{\text{T}}{\hat {U}}_{q}{\hat {\Sigma }}_{q}^{-1/2}.$ Replacing ${\hat {V}},{\text{ }}{\hat {\Sigma }}{\text{ by }}{\hat {V}}_{q}{\text{ and }}{\hat {\Sigma }}_{q}$ , an approximation for ${\hat {U}}$ can be obtained:

${\tilde {U}}={\hat {X}}{\hat {X}}_{q}^{\text{T}}{\hat {U}}_{q}{\hat {\Sigma }}_{q}^{-1}$ ( ${\tilde {U}}$ is not necessarily an orthogonal matrix).

However, defining ${\tilde {K}}={\tilde {U}}{\hat {\Sigma }}_{q}{\tilde {U}}^{\text{T}}$ , it can be computed the next way:

{\begin{aligned}{\tilde {K}}={\tilde {U}}{\hat {\Sigma }}_{q}{\tilde {U}}^{\text{T}}={\hat {X}}{\hat {X}}_{q}^{\text{T}}{\hat {U}}_{q}{\hat {\Sigma }}_{q}^{-1}{\hat {\Sigma }}_{q}({\hat {X}}{\hat {X}}_{q}^{\text{T}}{\hat {U}}_{q}{\hat {\Sigma }}_{q}^{-1})^{\text{T}}\\={\hat {X}}{\hat {X}}_{q}^{\text{T}}{\big \{}{\hat {U}}_{q}({\hat {\Sigma }}_{q}^{-1})^{\text{T}}{\hat {U}}_{q}^{\text{T}}{\big \}}({\hat {X}}{\hat {X}}_{q}^{\text{T}})^{\text{T}}\\\end{aligned}} By the characterization for orthogonal matrix ${\hat {U}}_{q}$ : equality $({\hat {U}}_{q})^{\text{T}}=({\hat {U}}_{q})^{-1}$ holds. Then, using the formula for the inverse of matrix multiplication $(AB)^{-1}=B^{-1}A^{-1}$ for invertible matrices $A$ and $B$ , the expression in braces can be rewritten as:

{\begin{aligned}{\hat {U}}_{q}({\hat {\Sigma }}_{q}^{-1})^{\text{T}}{\hat {U}}_{q}^{\text{T}}=({\hat {U}}_{q}{\hat {\Sigma }}_{q}^{\text{T}}{\hat {U}}_{q}^{\text{T}})^{-1}=({\hat {K}}_{q})^{-1}\end{aligned}} .

Then the expression for ${\tilde {K}}$ :

{\begin{aligned}{\tilde {K}}=({\hat {X}}{\hat {X}}_{q}^{\text{T}}){\hat {K}}_{q}^{-1}({\hat {X}}{\hat {X}}_{q}^{\text{T}})^{\text{T}}\\\end{aligned}} .

Defining ${\hat {K}}_{n,q}={\hat {X}}{\hat {X}}_{q}^{\text{T}}$ , the proof is finished.

### General theorem for kernel approximation for a feature map

For a feature map $\Phi :{\mathcal {X}}\rightarrow {\mathcal {F}}$ with associated kernel $K(x,x')=\langle \Phi (x),\Phi (x')\rangle _{\mathcal {F}}$ : equality ${\hat {K}}={\hat {K}}_{n,q}{\hat {K}}_{q}^{-1}{\hat {K}}_{n,q}^{\text{T}}$ also follows by replacing ${\hat {X}}$ by the operator ${\hat {\Phi }}:{\mathcal {F}}\rightarrow \mathbb {R} ^{n}$ such that $\langle {\hat {\Phi }}w\rangle _{i}=\langle \Phi (x_{i}),w\rangle _{\mathcal {F}}$ , ${\text{ }}i=1,\dots ,n$ , $w\in {\mathcal {F}}$ , and ${\hat {X}}_{q}$ by the operator ${\hat {\Phi }}_{q}:{\mathcal {F}}\rightarrow \mathbb {R} ^{q}$ such that $\langle {\hat {\Phi }}w\rangle _{i}=\langle \Phi (x_{i}),w\rangle _{\mathcal {F}}$ , ${\text{ }}i=1,\dots ,q$ , $w\in {\mathcal {F}}$ . Once again, a simple inspection shows that the feature map is only needed in the proof while the end result only depends on computing the kernel function.

### Application for regularized least squares

In a vector and kernel notation, the problem of Regularized least squares can be rewritten as:

$\min _{c\in \mathbb {R} ^{n}}{\frac {1}{n}}\|{\hat {Y}}-{\hat {K}}c\|_{\mathbb {R} ^{n}}^{2}+\lambda \langle c,{\hat {K}}c\rangle _{\mathbb {R} ^{n}}$ .

Computing the gradient and setting in to 0, the minimum can be obtained:

{\begin{aligned}-{\frac {1}{n}}{\hat {K}}({\hat {Y}}-{\hat {K}}c)+\lambda {\hat {K}}c=0\Rightarrow {\hat {K}}({\hat {K}}+\lambda nI)c={\hat {K}}{\hat {Y}}\\\Rightarrow c=({\hat {K}}+\lambda nI)^{-1}{\hat {Y}},{\text{ where }}c\in \mathbb {R} ^{n}\\\end{aligned}} The inverse matrix $({\hat {K}}+\lambda nI)^{-1}$ can be computed using Woodbury matrix identity:

{\begin{aligned}({\hat {K}}+\lambda nI)^{-1}={\cfrac {1}{\lambda n}}{\bigg (}{\cfrac {1}{\lambda n}}{\hat {K}}+I{\bigg )}^{-1}\\={\cfrac {1}{\lambda n}}{\bigg (}I+{\hat {K}}_{n,q}({\lambda n}{\hat {K}}_{q})^{-1}{\hat {K}}_{n,q}^{\text{T}}{\bigg )}^{-1}\\={\cfrac {1}{\lambda n}}{\Big (}I-{\hat {K}}_{n,q}(\lambda n{\hat {K}}_{q}+{\hat {K}}_{n,q}^{\text{T}}{\hat {K}}_{n,q})^{-1}{\hat {K}}_{n,q}^{\text{T}}{\Big )}\\\end{aligned}} It has the desired storage and complexity requirements.

## Randomized feature maps approximation

Let $\mathbf {x} ,\mathbf {x'} \in \mathbb {R} ^{d}$ – samples of data, $z:\mathbb {R} ^{d}\rightarrow \mathbb {R} ^{D}$ – a randomized feature map (maps a single vector to a vector of higher dimensionality) so that the inner product between a pair of transformed points approximates their kernel evaluation:

$K(\mathbf {x} ,\mathbf {x'} )=\langle \Phi (\mathbf {x} ),\Phi (\mathbf {x'} )\rangle \approx z(\mathbf {x} )^{\text{T}}z(\mathbf {x'} )$ ,

where $\Phi$ is the mapping embedded in the RBF kernel.

Since $z$ is low-dimensional, the input can be easily transformed with $z$ , after that different linear learning methods to approximate the answer of the corresponding nonlinear kernel can be applied. There are different randomized feature maps to compute the approximations to the RBF kernels. For instance, Random Fourier features and random binning features.

### Random Fourier features

Random Fourier features map produces a Monte Carlo approximation to the feature map. The Monte Carlo method is considered to be randomized. These random features consists of sinusoids $\cos(w^{\text{T}}\mathbf {x} +b)$ randomly drawn from Fourier transform of the kernel to be approximated, where $w\in \mathbb {R} ^{d}$ and $b\in \mathbb {R}$ are random variables. The line is randomly chosen, then the data points are projected on it by the mappings. The resulting scalar is passed through a sinusoid. The product of the transformed points will approximate a shift-invariant kernel. Since the map is smooth, random Fourier features work well on interpolation tasks.

### Random binning features

A random binning features map partitions the input space using randomly shifted grids at randomly chosen resolutions and assigns to an input point a binary bit string that corresponds to the bins in which it falls. The grids are constructed so that the probability that two points $\mathbf {x} ,\mathbf {x'} \in \mathbb {R} ^{d}$ are assigned to the same bin is proportional to $K(\mathbf {x} ,\mathbf {x'} )$ . The inner product between a pair of transformed points is proportional to the number of times the two points are binned together, and is therefore an unbiased estimate of $K(\mathbf {x} ,\mathbf {x'} )$ . Since this mapping is not smooth and uses the proximity between input points, Random Binning Features works well for approximating kernels that depend only on the $L_{1}$ – distance between datapoints.

## Comparison of approximation methods

The approaches for large-scale kernel learning (Nyström method and random features) differs in the fact that the Nyström method uses data dependent basis functions while in random features approach the basis functions are sampled from a distribution independent from the training data. This difference leads to an improved analysis for kernel learning approaches based on the Nyström method. When there is a large gap in the eigen-spectrum of the kernel matrix, approaches based on the Nyström method can achieve better results than Random Features based approach.