Orthogonal Random Features
Felix X. Yu, Ananda Theertha Suresh, Krzysztof Choromanski, Daniel Holtmann-Rice, Sanjiv Kumar
Introduction
Kernel methods are widely used in nonlinear learning , but they are computationally expensive for large datasets. Kernel approximation is a powerful technique to make kernel methods scalable, by mapping input features into a new space where dot products approximate the kernel well . With accurate kernel approximation, efficient linear classifiers can be trained in the transformed space while retaining the expressive power of nonlinear methods .
This means that one can treat as a density function and use Monte-Carlo sampling to derive the following nonlinear map for a real-valued kernel:
where is sampled i.i.d. from a probability distribution with density . Let \mathbf{W}=\big{[}\mathbf{w}_{1},\cdots,\mathbf{w}_{D}\big{]}^{T}. The linear transformation is central to the above computation since,
The choice of matrix determines how well the estimated kernel converges to the actual kernel;
The computation of has space and time costs of . This is expensive for high-dimensional data, especially since is often required to be larger than to achieve low approximation error.
In this work, we address both of the above issues. We first show an intriguing discovery (Figure 1(c)): by enforcing orthogonality on the rows of , the kernel approximation error can be significantly reduced. We call this method Orthogonal Random Features (ORF). Section 3 describes the method and provides theoretical explanation for the improved performance.
Since both generating a orthogonal matrix ( time and space) and computing the transformation ( time and space) are prohibitively expensive for high-dimensional data, we further propose Structured Orthogonal Random Features (SORF) in Section 4. The idea is to replace random orthogonal matrices by a class of special structured matrices consisting of products of binary diagonal matrices and Walsh-Hadamard matrices. SORF has fast computation time, , and almost no extra memory cost (with efficient in-place implementation). We show extensive experiments in Section 5. We also provide theoretical discussions in Section 6 of applying the structured matrices in a broader range of applications where random Gaussian matrix is used.
Related Works
Explicit nonlinear random feature maps have been constructed for many types of kernels, such as intersection kernels , generalized RBF kernels , skewed multiplicative histogram kernels , additive kernels , and polynomial kernels . In this paper, we focus on approximating Gaussian kernels following the seminal Random Fourier Features (RFF) framework , which has been extensively studied both theoretically and empirically .
Key to the RFF technique is Monte-Carlo sampling. It is well known that the convergence of Monte-Carlo can be largely improved by carefully choosing a deterministic sequence instead of random samples . Following this line of reasoning, Yang et al. proposed to use low-displacement rank sequences in RFF. Yu et al. studied optimizing the sequences in a data-dependent fashion to achieve more compact maps. In contrast to the above works, this paper is motivated by an intriguing new discovery that using orthogonal random samples provides much faster convergence. Compared to , the proposed SORF method achieves both lower kernel approximation error and greatly reduced computation and memory costs. Furthermore, unlike , the results in this paper are data independent.
Structured matrices have been used for speeding up dimensionality reduction , binary embedding , deep neural networks and kernel approximation . For the kernel approximation works, in particular, the “structured randomness” leads to a minor loss of accuracy, but allows faster computation since the structured matrices enable the use of FFT-like algorithms. Furthermore, these matrices provide substantial model compression since they require subquadratic (usually only linear) space. In comparison with the above works, our proposed methods SORF and ORF are more effective than RFF. In particular SORF demonstrates both lower approximation error and better efficiency than RFF. Table 1 compares the space and time costs of different techniques.
Orthogonal Random Features
Our goal is to approximate a Gaussian kernel of the form
Recall that the linear transformation matrix of RFF can be written as
The idea of Orthogonal Random Features (ORF) is to impose orthogonality on the matrix on the linear transformation matrix . Note that one cannot achieve unbiased kernel estimation by simply replacing by an orthogonal matrix, since the norms of the rows of follow the -distribution, while rows of an orthogonal matrix have the unit norm. The linear transformation matrix of ORF has the following form
Denote the approximate kernel based on the above as . The following shows that is an unbiased estimator of the kernel, and it has lower variance in comparison to RFF.
is an unbiased estimator of the Gaussian kernel, i.e.,
Let , and . There exists a function such that for all , the variance of is bounded by
We now show a proof sketch of the variance. Suppose, .
(Appendix A.3) There is a function such that for any ,
Therefore, for a large , and , the ratio of the variance of ORF and RFF is
Figure 2(a) shows the ratio of the variance of ORF to that of RFF when and is large. First notice that this ratio is always smaller than 1, and hence ORF always provides improvement over the conventional RFF. Interestingly, we gain significantly for small values of . In fact, when and , the ratio is roughly (note when ), and ORF exhibits infinitely lower error relative to RFF. Figure 2(b) shows empirical simulations of this ratio. We can see that the variance ratio is close to that of (3), even when , a fairly low-dimensional setting in real-world cases.
Recall that . This means that ORF preserves the kernel value especially well for data points that are close, thereby retaining the local structure of the dataset. Furthermore, empirically is typically not set too small in order to prevent overfitting—a common rule of thumb is to set to be the average distance of 50th-nearest neighbors in a dataset. In Figure 2(c), we plot the distribution of for several datasets with this choice of . These distributions are all concentrated in the regime where ORF yields substantial variance reduction.
The above analysis is under the assumption that . Empirically, for RFF, needs to be larger than in order to achieve low approximation error. In that case, we independently generate and apply the transformation (2) multiple times. The next lemma bounds the variance for this case.
Let , for an integer and . There exists a function such that for all , the variance of is bounded by
Structured Orthogonal Random Features
In the previous section, we presented Orthogonal Random Features (ORF) and provided a theoretical explanation for their effectiveness. Since generating orthogonal matrices in high dimensions can be expensive, here we propose a fast version of ORF by imposing structure on the orthogonal matrices. This method can provide drastic memory and time savings with minimal compromise on kernel approximation quality. Note that the previous works on fast kernel approximation using structured matrices do not use structured orthogonal matrices .
Let us first introduce a simplified version of ORF: replace in (2) by a scalar . Let us call this method ORF´. The transformation matrix thus has the following form:
(Appendix B) Let be the approximate kernel computed with linear transformation matrix (4). Let and . There exists a function such that the bias of satisfies
The above implies that when is large is a good estimation of the kernel with low variance. Figure 3(a) shows that even for relatively small , the estimation is almost unbiased. Figure 3(c) shows that when , the variance ratio is very close to that of . We find empirically that ORF´also provides very similar MSE in comparison with ORF in real-world datasets.
We now introduce Structured Orthogonal Random Features (SORF). It replaces the random orthogonal matrix of ORF´in (4) by a special type of structured matrix :
Computing has the time cost , since multiplication with takes time and multiplication with takes time using fast Hadamard transformation. The computation of SORF can also be carried out with almost no extra memory due to the fact that both sign flipping and the Walsh-Hadamard transformation can be efficiently implemented as in-place operations .
Figures 3(b)(d) show the bias and variance of SORF. Note that although the curves for small are different from those of ORF, when is large ( in practice), the kernel estimation is almost unbiased, and the variance ratio converges to that of ORF. In other words, it is clear that SORF can provide almost identical kernel approximation quality as that of ORF. This is also confirmed by the experiments in Section 5. In Section 6, we provide theoretical discussions to show that the structure of (5) can also be generally applied to many scenarios where random Gaussian matrices are used.
Experiments
Kernel Approximation. We first show kernel approximation performance on six datasets. The input feature dimension is set to be power of 2 by padding zeros or subsampling. Figure 4 compares the mean squared error (MSE) of all methods. For fixed , the kernel approximation MSE exhibits the following ordering:
By imposing orthogonality on the linear transformation matrix, Orthogonal Random Features (ORF) achieves significantly lower approximation error than Random Fourier Features (RFF). The Structured Orthogonal Random Features (SORF) have almost identical MSE to that of ORF. All other fast kernel approximation methods, such as circulant and FastFood have higher MSE. We also include DigitalNet, the best performing method among Quasi-Monte Carlo techniques . Its MSE is lower than that of RFF, but still higher than that of ORF and SORF. The order of time cost for a fixed is
Remarkably, SORF has both better computational efficiency and higher kernel approximation quality compared to other methods.
We also apply ORF and SORF on classification tasks. Table 2 shows classification accuracy for different kernel approximation techniques with a (linear) SVM classifier. SORF is competitive with or better than RFF, and has greatly reduced time and space costs.
Simplifying SORF. The SORF transformation consists of three Hadamard-Diagonal blocks. A natural question is whether using fewer computations and randomness can achieve similar empirical performance. Figure 5(c) shows that reducing the number of blocks to two (HDHD) provides similar performance, while reducing to one block (HD) leads to large error.
Analysis and General Applicability of the Hadamard-Diagonal Structure
We provide theoretical discussions of SORF in this section. We first show that for large , SORF is an unbiased estimator of the Gaussian kernel.
(Appendix C) Let be the approximate kernel computed with linear transformation matrix . Let . Then
Even though SORF is nearly-unbiased, proving tight variance and concentration guarantees similar to ORF remains an open question. The following discussion provides a sketch in that direction. We first show a lemma of RFF.
Let be a random Gaussian matrix as in RFF, for a given , the distribution of is .
Note that in RFF can be written as , where is a scaled orthogonal matrix such that each row has norm and is distributed according to . Hence the distribution of is , identical to . The concentration results of RFF use the fact that the projections of a Gaussian vector onto orthogonal directions are independent.
The above result can also be applied to settings not limited to kernel approximation. In the appendix, we show empirically that the same scheme can be successfully applied to angle estimation where the nonlinear map is a non-smooth function . We note that the structure has also been recently used in fast cross-polytope LSH .
Conclusions
We have demonstrated that imposing orthogonality on the transformation matrix can greatly reduce the kernel approximation MSE of Random Fourier Features when approximating Gaussian kernels. We further proposed a type of structured orthogonal matrices with substantially lower computation and memory cost. We provided theoretical insights indicating that the Hadamard-Diagonal block structure can be generally used to replace random Gaussian matrices in a broader range of applications. Our method can also be generalized to other types of kernels such as general shift-invariant kernels and polynomial kernels based on Schoenberg’s characterization as in .
References
Appendix A Variance Reduction via Orthogonal Random Features
Let , and . For a vector , let denote its coordinate. Let be the double factorial of , i.e., the product of every number from n to 1 that has the same parity as n.
A.2 Proof of Lemma 1
Let . Recall that in RFF, we compute the Kernel approximation as
where each is a dimensional vector distributed . Let be a dimensional vector distributed . By Bochner’s theorem,
and hence RFF yields an unbiased estimate.
We now compute the variance of RFF approximation. Observe that
If we take such independent random variables , since variance of the sum is sum of variances,
A.3 Proof of Lemma 2
For a set of non-negative values and such that for all , ,
Combining the above two equations results in the first part of the lemma. For the second part observe that
Combining the above two equations yields the second part of the lemma. ∎
Since the problem is rotation invariant, instead of projecting a vector onto a randomly chosen two orthogonal vectors and , we can choose a vector that is uniformly distributed on a sphere of radius and project it on to the first two dimensions. Thus,
The term in the Taylor’s series expansion of sum of above two terms is
A way to compute a uniformly distributed random variable on a sphere with radius is to generate independent random variables each distributed and setting . Hence,
follows from linearity of expectation and the observation above. follows from the independence of , , and . follows from substituting the moments of chi and Gaussian distributions. follows from numerical simplification. We now describe the reasoning behind . Let , where and are independent random variables. By the properties of the Gaussian random variables is also a random variable. Thus,
and hence . Substituting the above equation in the cosine expansion, we get that the expectation is
where . Thus,
Appendix B Proof of Theorem 2
The proof of the theorem is similar to that of Lemma 2 and we outline some key steps. We first bound the bias in Lemma 5 and then the variance in Lemma 6.
If , where is distributed uniformly on a unit sphere, then
Without loss of generality, we can assume is along the first coordinate and hence . A way to compute a uniformly distributed random variable on a sphere with radius is to generate independent random variables each distributed and setting . hence,
The term in the Taylor’s series expansion of cosine in the above equation is
Similar to the proof of Lemma 2, it can be shown that the expectation of this term is
where . Hence,
Let . If , where is a uniformly chosen random rotation, then
Let . Expanding the variance we have,
For the first term, rewriting , similar to the proof of Lemma 5 it can be shown that
Second term can be bounded similar to Lemma 2 and here we just sketch an outline. Similar to the proof of Lemma 2, the variance boils down to computing the expectation of . Using Lemma 4 and summing Taylor’s series we get
Substituting the above bound and the expectation from Lemma 5, we get
Appendix C Proof of Theorem 3
The proof follows from the following two technical lemmas.
Let be distributed according to and , where s are independent Rademacher random variables. For any function such that and ,
Let , , and , for all . Hence and . By a lemma due to Stein ,
We now bound the term on the right hand side by classic Stein-type arguments.
Let . Observe that
where the first equality follows from the fact that and are independent and has zero mean. By Taylor series approximation, the first term is bounded by
Combining the above four equations, we get
Combining the above two equations, we get
Substituting the bound on the second moment of yields the result. ∎
Let be a random matrix with i.i.d. entries as before. Using the above lemma we show that behaves like while computing the bias.
For a given , let and . For any function such that and ,
Let . Then for every , . Hence by Lemma 7, we can relate expectation under to the expectation under Gaussian distribution:
where the last equality follows from the fact that does not change rotation and follows from the law of total expectation. By Cauchy-Schwartz inequality, for each
Summing over all the indices yields the lemma. ∎
Theorem 3 follows from the Bochner’s theorem and the fact that satisfies requirements for the above lemma. We note that Theorem 3 holds for the matrix itself and the third component is not necessary to bound the bias.
Appendix D Proof of Theorem 4
To prove Theorem 4, we use the Hanson-Wright Inequality.
for some universal positive constant .
For a vector , let denote the diagonal matrix whose entries correspond to the entries of . For a diagonal matrix , let denote the vector corresponding to the diagonal entries of . Let and . Observe that
is small. We first show that the expectation of the above quantity is and then use the Hanson-Wright inequality to prove concentration. Let be a diagonal matrix with entry being . The above equation can be rewriten as
Observe that the entry of the is
where the last equality follows from observing that the rows of are orthogonal to each other. Together with the fact that elements of are independent of each other, we get
To prove the concentration result, observe that the entries of are independent and sub-Gaussian, and hence we can use the Hanson-Wright inequality. To this end, we bound the Frobenius and the spectral norm of the underlying matrix. For the Frobenius norm, observe that
where follows by observing that each changes the Frobenius norm by at most , follows from the fact that does not change the Frobenius norm, and follows by substituting .
where follows by observing that each changes the spectral norm by at most , follows from the fact that rotation does not change the spectral norm, and follows by substituting . Since , by McDiarmid’s inequality, it can be shown that with probability , . Hence, by the Hanson-Wright inequality, we get
where is a constant. Choosing results in the theorem. ∎
Appendix E Discrete Hadamard-Diagonal Structure in Binary Embedding
We compare random projection based Locality Sensitive Hashing (LSH) , Circulant Binary Embedding (CBE) and Kronecker Binary Embedding (KBE) . We closely follow the experimental settings of . We choose to compare with because it proposed to use another type of structured random orthogonal matrix (Kronecker product of orthogonal matrices). As shown in Figure 6, our result (HDHDHD) provides higher recall and lower angular MSE in comparison with other methods.