Finding Linear Structure in Large Datasets with Scalable Canonical Correlation Analysis
Zhuang Ma, Yichao Lu, Dean Foster
Introduction
Canonical Correlation Analysis (CCA), first introduced in 1936 by (Hotelling, 1936), is a foundamental statistical tool to characterize the relationship between two multidimensional variables, which finds a wide range of applications. For example, CCA naturally fits into multi-view learning tasks and tailored to generate low dimensional feature representations using abandunt and inexpensive unlabeled datasets to supplement or refine the expensive labeled data in a semi-supervised fashion. Improved generalization accuracy has been witnessed or proved in areas such as regression (Kakade & Foster, 2007), clustering (Chaudhuri et al., 2009; Blaschko & Lampert, 2008), dimension reduction (Foster et al., 2008; McWilliams et al., 2013), word embeddings (Dhillon et al., 2011, 2012), etc. Besides, CCA has also been succesfully applied to genome-wide association study (GWAS) and has been shown powerful for understanding the relationship between genetic variations and phenotypes (Witten et al., 2009; Chen et al., 2012).
There are various equivalent ways to define CCA and here we use the linear algebraic formulation of (Golub & Zha, 1995), which captures the very essense of the procedure, pursuing the directions of maximal correlations between two data matrices.
Let be the singular value decomposition. Then , , and where and .
The identifiability of canonical vectors is equivalent to the identifiability of the singular vectors . Lemma 1.1 implies that the leading dimensional CCA subspace can be solved by first computing the whitening matrices and then perform a -truncated SVD on the whitened covariance matrix . This classical algorithm is feasible and accurate when the data matrices are small but it can be slow and numerically unstable for large scale datasets which are common in modern natural language processing (large corpora, Dhillon et al. (2011, 2012)) and multi-view learning (abandunt and inexpensive unlabeled data, Hariharan & Subramanian (2014)) applications.
Throughout the paper, we call the step of orthonormalizing the columns of and whitening step. The computational complexity of the classical algorithm is dominated by the whitening step. There are two major bottlenecks,
Huge matrix multiplication to obtain with computational complexity for general dense and .
Large matrix decomposition to compute and with computational complexity (Even when and are sparse, are not necessarily sparse)
The whitening step dominates the -truncated SVD step because the top dimensional singular vectors can be efficiently computed by randomized SVD algorithms (see Halko et al. (2011) and many others).
Another classical algorithm (built-in function in Matlab) introduced in (Björck & Golub, 1973) uses a different way of whitening. It first carrys out a QR decomposition, and and then performs a SVD on , which has the same computational complexity as the algorithm indicated by Lemma 1.1. However, it is difficult to exploit sparsity in QR factorization while can be efficiently computed when and are sparse.
Besides computational issues, extra space is necessary to store two whitening matrices and (typically dense). In high dimensional applications where the number of features is huge, this can be another bottleneck considering the capacity of RAM of personal desktops (10-20 GB). In large distributed storage systems, the extra required space might incur heavy communication cost.
Therefore, it is natural to ask: is there a scalable algorithm that avoids huge matrix decomposition and huge matrix multiplication? Is it memory efficient? Or even more ambitiously, is there an online algorithm that generates decent approximation given a fixed computational power (e.g. CPU time, FLOP)?
2 Related Work
Scalability begins to play an increasingly important role in modern machine learning applications and draws more and more attention. Recently lots of promising progress emerged in the literature concerning with randomized algorithms for large scale matrix approximations, SVD, and Principal Component Analysis (Sarlos, 2006; Liberty et al., 2007; Woolfe et al., 2008; Halko et al., 2011). Unfortunately, these techniques does not directly solve CCA due to the whitening step. Several authors have tried to devise a scalable CCA algorithm. Avron et al. (2013) proposed an efficient approach for CCA between two tall and thin matrices () harnessing the recently developed tools, Subsampled Randomized Hadamard Transform, which only subsampled a small proportion of the data points to approximate the matrix product. However, when the size of the features, and , are large, the sampling scheme does not work. Later, Lu & Foster (2014) consider sparse design matrices and formulate CCA as iterative least squares, where in each iteration a fast regression algorithm that exploits sparsity is applied.
Another related line of research considers stochastic optimization algorithms for PCA (Arora et al., 2012; Mitliagkas et al., 2013; Balsubramani et al., 2013), which date back to Oja & Karhunen (1985). Compared with batch algorithms, the stochastic versions empirically converge much faster with similar accuracy. Further, these stochastic algorithms can be applied to streaming setting where data comes sequentially (one pass or several pass) without being stored. As mentioned in (Arora et al., 2012), stochastic optimization algorithm for CCA is more challenging and remains an open problem because of the whitening step.
3 Main Contribution
The main contribution of this paper is to directly tackle CCA as a nonconvex optimization problem and propose a novel Augmented Approximate Gradient (AppGrad) scheme and its stochastic variant for finding the top dimensional canonical subspace. Its advantages over state-of-art CCA algorithms are three folds. Firstly, AppGrad scheme only involves large matrix multiplying a thin matrix of width and small matrix decomposition of dimension , and therefore to some extent is free from the two bottlenecks. It also benefits if and are sparse while classical algorithm still needs to invert the dense matrices and . Secondly, AppGrad achieves optimal storage complexity , the space necessary to store the output, compared with classical algorithms which usually require for storing the whitening matrices. Thirdly, the stochastic (online) variant of AppGrad is especially efficient for large scale datasets if moderate accuracy is desired. It is well-suited to the case when computational resources are limited or data comes as a stream. To the best of our knowledge, it is the first stochastic algorithm for CCA, which partly gives an affirmative answer to a question left open in (Arora et al., 2012).
The rest of the paper is organized as follows. We introduce AppGrad scheme and establish its convergence properties in section 2. We extend the algorithm to stochastic settings in section 3. Extensive real data experiments are presented in section 4. Concluding remarks and future work are summarized in section 5. Proof of Theorem 2.1 and Proposition 2.3 are relegated to the supplementary material.
Algorithm
For simplicity, we first focus on the leading canonical pair to motivate the proposed algorithms. Results for general scenario can be obtained in the same manner and will be briefly discussed in the later part of this section.
To begin with, we recast CCA as an nonconvex optimization problem (Golub & Zha, 1995).
Although (1) is a nonconvex (due to the nonconvex constraint), (Golub & Zha, 1995) showed that an alternating minimization strategy (Algorithm 1), or rather iterative least squares, actually converges to the leading canonical pair. However, each update is computationally intensive. Essentially, the alternating least squares acts like a second order method, which is usually recognized to be inefficient for large-scale datasets, especially when current estimate is not close enough to the optimum. Therefore, it is natural to ask: is there a valid first order method that solves (1)?
Heuristics borrowed from convex optimization literature give rise to a projected gradient scheme summarized in Algorithm 2. Instead of completely solving a least squares in each iterate, a single gradient step of (1) is performed and then project back to the constrained domain, which avoids inverting a huge matrix. Unfortunately, the following proposition demonstrates that Algorithm 2 fails to converge to the leading canonical pair.
If leading canonical correlation and either is not an eigenvector of or is not an eigenvector of , then , the leading canonical pair is not a fixed point of the naive gradient scheme in Algorithm 2. Therefore, the algorithm does not converge to .
The proof is similar to the proof of Proposition 2.2 and we leave out the details here. ∎
The failure of Algorithm 2 is due to the nonconvex nature of (1). Although every gradient step might decrease the objective function, this property no longer persists after projecting to its nonconvex domain \big{\{}(\phi,\psi)\,|\,\phi^{\top}{\bf S_{x}}\phi=1,\,\psi^{\top}{\bf S_{y}}\psi=1\big{\}} (the normalization step). On the contrary, decreases triggered by gradient descent is always maintained if projecting to a convex region.
2 AppGrad Scheme
As a remedy, we propose a novel Augmented Approximate Gradient (AppGrad) scheme summarized in Algorithm 3. It inherits the convergence guarantee of alternating least squares as well as the scalability and memory efficiency of first order methods, which only involves matrix-vector multiplication and only requires extra space.
AppGrad seems unnatural at first sight but has some nice intuitions behind as we will discuss later. The differences and similarities between these algorithms are subtle but crucial. Compared with the naive gradient descent, we introduce two auxiliary variables , an unnormalized version of . During each iterate, we keep updating and without scaling them to have unit norm, which in turn produces the ‘correct’ normalized counterpart, . It turns out that is a fixed point of the dynamic system .
, let , then are the fixed points of AppGrad scheme.
To prove the proposition, we need the following lemma that characterizes the relations among some key quantities.
By Lemma 1.1, , where , and . Then we have . ∎
Substitute into the iterative formula in Algorithm 3.
The second equality is direct application of Lemma 2.2. The third equality is due to the fact that . Then,
Therefore . A symmetric argument will show that , which completes the proof. ∎
The connection between AppGrad and alternating minimization strategy is not instaneous. Intuitively, when is not close to , solving the least squares completely as carried out in Algorithm 1 is a waste of computational power (informally by regarding it as a second order method, the Newton Step has fast convergence only when current estimate is close to the optimum). Instead of solving a sequence of possibly unrelevant least squares, the following lemma shows that AppGrad directly targets at the least squares that involves the leading canonical pair.
Let be the leading canonical pair and . Then,
Let , by optimality condition, . Apply Lemma 2.2,
Similar argument gives ∎
Lemma 2 characterizes the relationship between leading canonical pair and its unnormalized counterpart , which sheds some insight on how AppGrad works. The intuition is that and are current estimations of and , and the updates of in Algorithm 3 are actually gradient steps of the least squares in (2), with the unknown truth approximated by . In terms of mathematics,
The normalization step in Algorithm 3 corresponds to generating new approximations of , namely , using the updated through the relationship . Therefore, one can interpret AppGrad as approximate gradient scheme for solving (2). When converge to , its scaled version converge to the leading canonical pair .
The following theorem shows that when the estimates enter a neighborhood of the true canonical pair, AppGrad is contractive. Define the error metric where .
where \delta=1-\Big{(}1-\frac{2(\lambda_{1}^{2}-\lambda_{2}^{2})-L_{1}e_{0}}{2\lambda_{1}^{2}}\Big{)}^{\frac{1}{2}}>0
The theorem reveals that the larger is the eigengap , the broader is the contraction region. We didn’t try to optimize the conditions above and empirically as shown in the experiments, a randomized initialization always suffices to capture most of the correlations.
3 General Rank-k𝑘k Case
Following the spirit of rank-one case, AppGrad can be easily generalized to compute the top dimesional canonical subspace as summarized in Algorithm 4. The only difference is that the original scalar normalization is replaced by its matrix counterpart, that is to multiply the inverse of the square root matrix , ensuring that .
Notice that the gradient step only involves a large matrix multiplying a thin matrix of width and the SVD is performed on a small matrix. Therefore, the computational complexity per iteration is dominated by the gradient step, of order . The cost will be further reduced when the data matrices are sparse.
Compared with classical spectral agorithm which first whitens the data matrices and then performs a SVD on the whitened covariance matrix, AppGrad actually merges these two steps together. This is the key of its efficiency. In a high level, whitening the whole data matrix is not necessary and we only want to whiten the directions that contain the leading CCA subspace. However, these directions are unknown and therefore for two-step procedures, whitening the whole data matrix is unavoidable. Instead, AppGrad tries to identify (gradient step) and whiten (normalization step) these directions simultaneously. In this way, every normalization step is only performed on the potential dimensional target CCA subspace and therefore only deals with a small matrix.
Parallel results of Lemma 1, Proposition 2.1, Proposition 2.2, Lemma 2 for this general scenario can be established in a similar manner. Here, to make Algorithm 4 more clear, we state the fixed point result of which the proof is similar to Proposition 2.2.
Let be the diagonal matrix of top canonical correlations and let be the top CCA vectors. Also denote and . Then for any orthogonal matrix , is a fixed point of AppGrad scheme.
The top dimensional canonical subspace is identifiable up to a rotation matrix and Proposition 2.3 shows that every optimum is a fixed point of AppGrad scheme.
4 Kernelization
Following the same logic as Proposition 2.3, a similar fixed point result can be proved. Therefore, Algorithm 4 can be directly applied to compute by simply replacing with .
Stochastic AppGrad
Recently, there is a growing interest in stochastic optimization which is shown to have better performance for large-scale learning problems (Bousquet & Bottou, 2008; Bottou, 2010). Especially in the so-called ‘data laden regime’, where data is abundant and the bottleneck is runtime, stochastic optimization dominate batch algorithms both empirically and theoretically. Given these advantages, lots of efforts have been spent on developing stochastic algorithms for principal component analysis (Oja & Karhunen, 1985; Arora et al., 2012; Mitliagkas et al., 2013; Balsubramani et al., 2013). Despite promising progress in PCA, as mentioned in (Arora et al., 2012), stochastic CCA is more challenging and remains an open problem due to the whitening step.
As a gradient scheme, AppGrad naturally generalizes to the stochastic regime and we summarize in Algorithm 5. Compared with the batch version, only a small subset of samples are used to compute the gradient, which reduces the computational cost per iteration from to ( is the size of the minibatch). Empirically, this makes stochastic AppGrad much faster than the batch version as we will see in the experiments. Also, for large scale applications when fully calculating the CCA subspace is prohibitive, stochastic AppGrad can generate a decent approximation given a fixed computational power, while other algorithms only give a one-shot estimate after the whole procedure is carried out completely. Moreover, when there is a generative model, as shown in (Bousquet & Bottou, 2008), due to the tradeoff between statistical and numerical accuracy, fully solving an empirical risk minimization is unnecessary since the statistical error will finally dominate. On the contrary, stochastic optimization directly tackles the problem in the population level and therefore is more statistically efficient.
It is worth mentioning that the normalization step is accomplished using a sampled Gram matrix and . A key observation is that when , using standard concentration inequality, because the matrix we want to approximate is a matrix, while generally sample is needed to have . As we have argued in previous section, this bonus is a byproduct of the fact that AppGrad tries to identify and whiten the directions that contains the CCA subspace simultaneously, or else samples are necessary for whitening the whole data matrices.
Experiments
In this section, we present experiments on four real datasets to evaluate the effectiveness of the proposed algorithms for computing the top 20 (=20) dimensional canonical subspace. A short summary of the datasets is in Table 1.
Mediamill is an annotated video dataset from the Mediamill Challenge (Snoek et al., 2006). Each image is a representative keyframe of a video shot annotated with 101 labels and consists of 120 features. CCA is performed to explore the correlation structure between the images and its labels.
MNIST is a database of handwritten digits. CCA is used to learn correlated representations between the left and right halves of the images.
Penn Tree Bank dataset is extracted from Wall Street Journal, which consists of million tokens and a vocabulary size of (Lamar et al., 2010). CCA has been successfully used on this dataset to build low dimensional word embeddings (Dhillon et al., 2011, 2012). The task here is a CCA between words and their context. We only consider the 10, 000 most frequent words to avoid sample sparsity.
URL Reputation dataset (Ma et al., 2009) is extracted from UCI machine learning repository. The dataset contains 2.4 million URLs each represented by 3.2 million features. For simplicity we only use the first 2 million samples. of the features are host based features like WHOIS info, IP prefix and are lexical based features like Hostname and Primary domain. We run a CCA between a subset of host based features and a subset of lexical based features.
Evaluation Criterion: The evaluation criterion we use for the first three datasets (Mediamill, MNIST, Penn Tree Bank) is Proportions of Correlations Captured (PCC). To introduce this term, we first define Total Correlations Captured (TCC) between two matrices to be the sum of their canonical correlations as defined in Lemma 1.1. Then, for estimated top dimensional canonical subspace and true leading dimensional CCA subspace , PCC is defined as
Intuitively PCC characterizes the proportion of correlations captured by certain algorithm compared with the true CCA subspace. Therefore, the higher is PCC the better is the estimated CCA subspace. This criterion has two major advantages over subspace distance ( is projection matrix of the column space of ). First, it is more natural and relevant considering that the goal of CCA is to capture most correlations between two data matrices. Second, when the eigengap is not big enough, the top dimensional CCA subspace is ill posed while the correlations captured is well defined.
We use the output of the standard spectral algorithms as the truth to calculate the denominator of PCC. However, for URL Reputation dataset, the number of samples and features are too large for the algorithm to compute the true CCA subspace in a reasonable amount of time and instead we only compare the numerator (monotone w.r.t. PCC) for different algorithms.
Initialization We initialize by first drawing samples from standard Gaussian distribution and then normalize such that and
Stepsize For both AppGrad and stochastic AppGrad, a small part of the training set is held out and cross-validation is used to choose the step size adaptively.
Regularization For all the algorithms, a little regularization is added for numerical stability which means we replace Gram matrix with for some small positive .
Oversampling Oversampling means when aiming for top dimensional subspace, people usually computes top dimesional subspace from which a best diemsional subspace is extracted. In practice, suffices to improve the performance. We only do a oversampling of 5 in the URL dataset.
2 Summary of Results
For the first three datasets (Mediamill, MNIST, Penn Tree Bank), both in-sample and out-of-sample PCC are computed for AppGrad and Stochastic AppGrad as summarized in Figure1. As you can see, both algorithms nearly capture most of the correlations compared with the true CCA subspace and stochastic AppGrad consistently achieves same PCC with much less computational cost than its batch version. Moreover, the larger is the size of the data, the bigger advantage will stochastic AppGrad obtain. One thing to notice is that, as revealed in Mediamill dataset, out-of-sample PCC is not necessarily less than in-sample PCC because both denominator and numerator will change on the hold out set.
For URL Reputation dataset, as we mentioned earlier, classical algorithms fails on a typical desktop. The reason is that these algorithms only produce a one-shot estimate after the whole procedure is completed, which is usually prohibitive for huge datasets. In this scenario, the advantage of online algorithms like stochastic AppGrad becomes crucial. Further, the stochastic nature makes the algorithm cost-effective and generate decent approximations given fixed computational resources (e.g. FLOP). As revealed by Figure 2, as the number of iterations increases, stochastic AppGrad captures more and more correlations.
Since the true CCA subspaces for URL dataset is too slow to compute, we compare our algorithm with some naive heuristics which can be carried out efficiently in large scale and catches a reasonable amount of correlation. Below is a brief description of them.
Non-Whitening (NW-CCA): directly perform SVD on the unwhitened covariance matrix . This strategy is also used in (Witten et al., 2009)
Diagnoally Whitening (DW-CCA) (Lu & Foster, 2014): avoid inverting matrices by approximating with and .
Whitening the leading Principal Component Directions (PCA-CCA): First compute the leading dimensional principal component subspace and project the data matrices and to the subspace, denote them and . Then compute the top dimensional CCA subspace of the pair . At last, transform the CCA subspace of back to the CCA subspace of orginal matrix pair . Specifically for this example, we choose (log(FLOP)=35, dominating the computational cost of Stochastic AppGrad) .
For all the heuristics mentioned above, SVD and PCA steps are carried out using the randomized algorithms in (Halko et al., 2011). For PCA-CCA, as the number of Principal Components () increases, more correlation will be captured but the computational cost will also increase. When , PCA-CCA is reduced to the orginal CCA.
Essentially, all the heuristics are incorrect algorithms and try to approximately whiten the data matrices. As suggested by Figure 2, stochastic AppGrad significantly captures much more correlations.
Conclusions and Future Work
In this paper, we present a novel first order method, AppGrad, to tackle large scale CCA as a nonconvex optimization problem. This bottleneck-free algorithm is both memory efficient and computationally scalable. More importantly, its online variant is well-suited to practical high dimensional applications where batch algorithm is prohibitive and data laden regime where data is abundant and runtime is main concern.
Further, AppGrad is flexible and structure information can be easily incorporated into the algorithm. For example, if the canonical vectors are assumed to be sparse (Witten et al., 2009; Gao et al., 2014), a thresholding step can be added between the gradient step and normalization step to obtain sparse solutions while it is hard to add sparse constraint to the classical CCA formulation which is a generalized eigenvalue problem. Heuristics in (Witten et al., 2009) avoid this by simply skipping the whitening procedure (NW-CCA). (Gao et al., 2014) resorts to semidefinite programming and therefore is very slow. AppGrad with thresholding works well in simulations and we leave its theoretical properties for future research.
References
Proofs
A brief review of the notations in the main paper:
Further, we define , the cosine of the angle between two vectors induced by the inner product . Similarly, we define . To prove the theorem, we will repeatedly use the following lemma.
and
Proof of Lemma 6.1 Notice that , then
Also notice that , which implies . Further
2 Proof of Theorem 2.1
Without loss of generality, we can always assume because the canonical vectors are only identifiable up to a flip in sign and we can always choose such that the cosines are nonnegative. Apply simple algebra to the gradient step , we have
By Lemma 2.2, , which implies
The last inequality uses the assumption that . By Lemma6.1, . Hence, . Also notice that , then
Now, we are going to bound . Because is an orthonormal matrix (orthogonal if ) and is a unit vector, there exisit coefficients and unit vector such that . Therefore,
By definition, . Further by Lemma 6.1,
Notice that , we have
By definition, \delta=1-\frac{1}{\lambda_{1}}\Big{(}\frac{L_{1}}{2}\|\Delta\widetilde{\psi}^{0}\|^{2}+\frac{L_{1}}{2}\|\Delta\widetilde{\phi}^{0}\|^{2}+\lambda_{2}^{2}\Big{)}^{\frac{1}{2}} and . Substitute in (6) with ,
3 Proof of Proposition 2.3
Substitute into the iterative formula in Algorithm 4.
The second equality is direct application of Lemma 1. The third equality is due to the fact that . Then,
Therefore . A symmetric argument will show that , which completes the proof.