Frequent Directions : Simple and Deterministic Matrix Sketching
Mina Ghashami, Edo Liberty, Jeff M. Phillips, David P. Woodruff
Introduction
The data streaming paradigm considers computation on a large data set where data items arrive in arbitrary order, are processed, and then never seen again. It also enforces that only a small amount of memory is available at any given time. This small space constraint is critical when the full data set cannot fit in memory or disk. Typically, the amount of space required is traded off with the accuracy of the computation on . Usually the computation results in some summary of , and this trade-off determines how accurate one can be with the available space resources.
Modern large data sets are often viewed as large matrices. For example, textual data in the bag-of-words model is represented by a matrix whose rows correspond to documents. In large scale image analysis, each row in the matrix corresponds to one image and contains either pixel values or other derived feature values. Other large scale machine learning systems generate such matrices by converting each example into a list of numeric features. Low rank approximations for such matrices are used in common data mining tasks such as Principal Component Analysis (PCA), Latent Semantic Indexing (LSI), and k-means clustering. Regardless of the data source, the optimal low rank approximation for any matrix is obtained by its truncated Singular Value Decompositions (SVD).
In large matrices as above, one processor (and memory) is often incapable of handling all of the dataset in a feasible amount of time. Even reading a terabyte of data on a single processor can take many hours. Thus this computation is often spread among some set of machines. This renders standard SVD algorithms infeasible. Given a very large matrix , a common approach is to compute in the streaming paradigm a sketch matrix that is significantly smaller than the original. A good sketch matrix is such that or and so computations can be performed on rather than on without much loss in precision.
In this paper, we propose a fourth approach: frequent directions. It is deterministic and draws on the similarity between the matrix sketching problem and the item frequency estimation problem. We provide additive and relative error bounds for it; we show how to merge summaries computed in parallel on disjoint subsets of data; we show it achieves the optimal tradeoff between space and accuracy, up to constant factors, for any row-update based summary; and we empirically demonstrate that it outperforms exemplars from all of the above described approaches.
2 Item Frequency Approximation
Our algorithm for sketching matrices is an extension of a well known algorithm for approximating item frequencies in streams. The following section shortly overviews the frequency approximation problem. Here, a stream has elements where each . Let be the frequency of item and stands for number of times item appears in the stream. It is trivial to produce all item frequencies using space simply by keeping a counter for each item. Although this method computes exact frequencies, it uses space linear to the size of domain which might be huge. Therefore, we are interested in using less space and producing approximate frequencies .
3 Connection to Matrix Sketching
4 Main results
Assuming a constant word size, any randomized matrix approximation streaming algorithm in the row-wise-updates model, which guarantees and that succeeds with probability at least , must use space.
Theorem 1.4 claims that FrequentDirections is optimal with respect to the tradeoff between sketch size and resulting accuracy. On the other hand, in terms of running time, FrequentDirections is not known to be optimal.
5 Practical Implications
Frequent Directions
This section proves our main results for Algorithm 1 which is our simplest and most space efficient algorithm. The reader will notice that we occasionally use inequalities instead of equalities at different parts of the proof to obtain three Properties. This is not unintentional. The reason is that we want the same exact proofs to hold also for Algorithm 1 which we describe in Section 3. Algorithm 1 is conceptually identical to Algorithm 1, it requires twice as much space but is far more efficient. Moreover, any algorithm which produces an approximate matrix which satisfies the following facts (for any choice of ) will achieve the error bounds stated in Lemma 1.1 and Lemma 1.2.
In what follows, we denote by , , the values of , and respectively after the th row of was processed. Let , be the total mass we subtract from the stream during the algorithm. To prove our result we first prove three auxiliary properties.
For any vector we have .
Use the observations that .
To see this, first note that . Now, consider the fact that . Substituting for above and taking the sum yields
Combining this with yields that . ∎
Now we can show that projecting onto provides a relative error approximation. Here, correspond to the singular vectors of as above and to the singular vectors of in a similar fashion.
Running Time Analysis
In extremely large datasets, the processing is often distributed among several machines. Each machine receives a disjoint input of raw data and is tasked with creating a small space summary. Then to get a global summary of the entire data, these summaries need to be combined. The core problem is illustrated in the case of just two machines, each process a data set and , where , and create two summaries and , respectively. Then the goal is to create a single summary which approximates using only and . If can achieve the same formal space/error tradeoff as each to in a streaming algorithm, then the summary is called a mergeable summary .
First note that satisfies all facts with , by additivity of squared spectral norm along any direction (e.g. ) and squared Frobenious norms (e.g. ), but has space twice as large as desired. Property 1 is straight forward for since only shrinks in all directions in relation to . For Property 2 follows by considering any unit vector and expanding
This property trivially generalizes to any number of partitions of . It is especially useful when the matrix (or data) is distributed across many machines. In this setting, each machine can independently compute a local sketch. These sketches can then be combined in an arbitrary order using FrequentDirections.
2 Worst case update time
Space Lower Bounds
In this section we show that FrequentDirections is space optimal with respect to the guaranteed accuracy. We present nearly-matching lower bounds for each case. We show the number of bits needed is equivalent to times the number of rows FrequentDirections requires. We first prove Theorem 1.3 showing the covariance error bound in Theorem 1.1 is nearly tight, regardless of streaming issues.
We start with a simple intuitive lemma showing an lower bound, which we will refer to. We then prove our main lower bound.
Any streaming algorithm which, for every input , with constant probability (over its internal randomness) succeeds in outputting a matrix for which must use bits of space.
Let be the set of -dimensional subspaces over the vector space , where denotes the finite field of elements with the usual modulo arithmetic. The cardinality of is known to be
where the inequalities assume that .
where are integers. We can assume that the greatest common divisor (gcd) of is , otherwise the same conclusion holds after we divide by the gcd. Note that (1) implies that , i.e., when we take each of the coordinates modulo . Since the cannot all be divisible by (since would then be odd and so by the gcd condition the left hand side would contain a vector with at least one odd coordinate, contradicting that the right hand side is a vector with even coordinates), and the rows of form a basis over , the right hand side must be non-zero, which implies that . This implies that is in the span of the rows of over , a contradiction.
where denotes the expected length of the encoding of , is the entropy function, and is the mutual information. For background on information theory, see . This completes the proof. ∎
2 Intuition for Main Lower Bound
The only other lower bounds for streaming algorithms for low rank approximation that we know of are due to Clarkson and Woodruff . As in their work, we use the Index problem in communication complexity to establish our bounds, which is a communication game between two players Alice and Bob, holding a string and an index , respectively. In this game Alice sends a single message to Bob who should output with constant probability. It is known (see, e.g., ) that this problem requires Alice’s message to be bits long. If Alg is a streaming algorithm for low rank approximation, and Alice can create a matrix while Bob can create a matrix (depending on their respective inputs and ), then if from the output of Alg on the concatenated matrix Bob can output with constant probability, then the memory required of Alg is bits, since Alice’s message is the state of Alg after running it on .
The main technical challenges are thus in showing how to choose and , as well as showing how the output of Alg on can be used to solve Index. This is where our work departs significantly from that of Clarkson and Woodruff . Indeed, a major challenge is that in Theorem 1.4, we only require the output to be the matrix , whereas in Clarkson and Woodruff’s work from the output one can reconstruct . This causes technical complications, since there is much less information in the output of the algorithm to use to solve the communication game.
The intuition behind the proof of Theorem 1.4 is that given a matrix , where is a random unit vector, then if is a sufficiently good projection matrix for the low rank approximation problem on , then the second row of actually reveals a lot of information about . This may be counterintuitive at first, since one may think that is a perfectly good low rank approximation. However, it turns out that is a much better low rank approximation in Frobenius norm, and even this is not optimal. Therefore, Bob, who has together with the output , can compute the second row of , which necessarily reveals a lot of information about (e.g., if , its second row would reveal a lot of information about ), and therefore one could hope to embed an instance of the Index problem into . Most of the technical work is about reducing the general problem to this primitive problem.
3 Proof of Main Lower Bound for Preserving Subspaces
Now let be a small constant to be determined. We consider the following two player problem between Alice and Bob: Alice has a matrix which can be written as a block matrix , where is the identity matrix, and is a matrix in which the entries are in . Here means we append the columns of to the left of the columns of ; see Figure 1. Bob is given a set of standard unit vectors , for distinct . Here we need , but we can assume is less than a sufficiently small constant, as otherwise we would just need to prove an lower bound, which is established by Lemma 4.1.
Denote this problem by . We will show the randomized -way communication complexity of this problem , in which Alice sends a single message to Bob and Bob fails with probability at most , is bits. More precisely, let be the following product distribution on Alice and Bob’s inputs: the entries of are chosen independently and uniformly at random in , while is a uniformly random set among all sets of distinct indices in . We will show that , where denotes the minimum communication cost over all deterministic -way (from Alice to Bob) protocols which fail with probability at most when the inputs are distributed according to . By Yao’s minimax principle (see, e.g., ), .
We use the following two-player problem Index in order to lower bound . In this problem Alice is given a string , while Bob is given an index . Alice sends a single message to Bob, who needs to output with probability at least . Again by Yao’s minimax principle, we have that , where is the distribution for which and are chosen independently and uniformly at random from their respective domains. The following is well-known.
For a small enough positive constant, and , we have .
We proceed to lower bound in a certain way, which will allow our reduction to Index to be carried out. We need the following fact:
((2.4) of ) Let be an matrix with i.i.d. entries which are each with probability and with probability , and suppose . Then for all ,
where are absolute constants. Here is the operator norm of .
We apply Fact 4.2 to the matrix , which implies,
and using that and is a sufficiently small constant, this implies
where is an absolute constant (depending on ). Note that for sufficiently small, . Let be the event that , which we condition on.
We partition the rows of into and , where contains those rows whose projection onto the first coordinates equals for some . Note that is and is . Here, is since it includes the rows in indexed by , together with the rows . Let us also partition the rows of into and , so that the union of the rows in and in is equal to , where the rows of are the rows of in , and the rows of are the non-zero rows of in (note that of the rows are non-zero and are zero in restricted to the columns in ).
For any unit vector , write , where , and , and where for a set is on indices . Then, conditioned on occurring,
Let be the matrix consisting of the top rows of , so that has the form , where is a identity matrix. By construction of , . Now, , and so
We will also make use of the following simple but tedious fact.
For , the function is maximized when . We define to be the value of at its maximum, where .
Setting , we can equivalently maximize , or equivalently . Differentiating this expression and equating to , we have
Multiplying both sides by one obtains the equation , and squaring both sides, after some algebra one obtains . Using the quadratic formula, we get that the maximizer satisfies , or . ∎
Conditioned on occurring,
Suppose we replace the vector with an arbitrary vector supported on coordinates in with the same norm as . Then the right hand side of this expression cannot increase, which means it is maximized when , for which it equals and setting to equal the in Fact 4.3, we see that this expression is at most . ∎
Write the projection matrix output by the streaming algorithm as , where is with orthonormal columns (note that ). Applying Lemma 4.2 and Fact 4.3 to each of the columns , we have:
Using the matrix Pythagorean theorem, we thus have,
Therefore, if Bob succeeds in solving on input , then,
Comparing (4) and (5), we arrive at, conditioned on :
where is a constant that can be made arbitrarily small by making arbitrarily small.
Since is a projector, . Write , where the vectors in are supported on , and the vectors in are supported on . We have,
where the first inequality uses and (6), the second inequality uses that event occurs, and the third inequality holds for a constant that can be made arbitrarily small by making the constant arbitrarily small.
Combining with (5) and using the triangle inequality,
where is a constant that can be made arbitrarily small for an arbitrarily small constant (note that also becomes arbitrarily small as becomes arbitrarily small). Hence, , and together with Corollary 4.1, that implies for a constant that can be made arbitrarily small by making arbitrarily small.
Our next goal is to show that is almost as large as . Consider any column of , and write it as . Hence,
Suppose for a value . Then
and hence, letting denote the corresponding values of for the columns of , we have
Comparing the square of (7) with (9), we have
where is a constant that can be made arbitrarily small by making an arbitrarily small constant. Now, as shown above, while since if is the -th column of , by (10) we have
for a constant that can be made arbitrarily small by making an arbitarily small constant.
Now since event occurs, and since the rows of are the concatenation of rows of and , so combining with (11), we arrive at
for a constant that can be made arbitrarily small by making arbitrarily small.
Combining the square of (7) with (12), we thus have
where the constant can be made arbitrarily small by making arbitrarily small.
or equivalently, for a constant that can be made arbitrarily small by making the constant small enough. This intuitively says that provides a good low rank approximation for the matrix . Notice that by (15),
Conditioned on event , where is a constant that can be made arbitrarily small by making arbitrarily small.
The lemma now follows since and can be made arbitrarily small by making the constant small enough. ∎
For the first part of the corollary, observe that
for a constant that can be made arbitrarily small by making arbitrarily small.
where is a constant that can be made arbitrarily small by making the constant arbitrarily small.
By a union bound over the occurrence of events , , and , and the streaming algorithm succeeding (which occurs with probability ), it follows that Bob succeeds in solving Index with probability at least , as required. This completes the proof. ∎
Related Work on Matrix Sketching and Streaming
As mentioned in the introduction, there are a variety of techniques to sketch a matrix. There are also several ways to measure error and models to consider for streaming.
In this paper we focus on the row-update streaming model where each stream elements appends a row to the input matrix . A more general model the entry-update model fixes the size of at , but each element indicates a single matrix entry and adds (or subtracts) to its value.
The accuracy of a sketch matrix can be measured in several ways. Most commonly one considers an , rank matrix that is derived from (and sometimes ) and measures the projection error where proj-err . When can be derived entirely from , we call this a construction result, and clearly requires at least space. When the space is required to be independent of , then either implicitly depends on , or requires another pass of the data. It can then be defined one of two ways: (as is considered in this paper) takes , the best rank- approximation to , and then projects onto ; projects onto , and then takes the best rank- approximation of the result. Note that is better than , since it knows the rank- subspace to project onto without re-examining .
We also consider covariance error where covar-err in this paper. One can also bound , but this has an extra parameter , and is less clean. This measure captures the norm of along all directions (where as non-construction, projection error only indicates how accurate the choice of subspace is), but still does not require space.
Sketch paradigms
Given these models, there are several types of matrix sketches. We describe them here with a bit more specificity than in the Introduction, with particular attention to those that can operate in the row-update model we focus on. Specific exemplars are described which are used in out empirical study to follow. The first approach is to sparsify the matrix , by retaining a small number of non-zero. These algorithms typically assume to know the dimensions of , and are thus not directly applicable in out model.
Catalog of Related Bounds.
Recall that the error can be measured in several ways.
If it is not constructive, it is denoted by a P for projection if it uses a projection . Alternatively if the weaker form of , then this is denoted where is the rank of before the projection.
In most recent results a projection error of is obtained, and is denoted R.
Although in some cases a weaker additive error of the form is achieved and denoted A. This can sometimes also be expressed as a spectral norm of the form (note the error term still has a Frobenius norm). This is denoted L2.
In a few cases the error does not follow these patterns and we specially denote it.
Algorithms are randomized unless it is specified. In all tables we state bounds for a constant probability of failure. If we want to decrease the probability of failure to some parameter , we can generally increase the size and runtime by .
It is worth noting that under the construction model, and allowing streaming turnstile updates to each element of the matrix, the hashing algorithm has been shown space optimal by Clarkson and Woodruff (assuming each matrix entry requires bits, and otherwise off by only a factor). It is randomized and it constructs a decomposition of a rank matrix that satisfies , with probability at least . This provides a relative error construction bound of size bits. They also show an bits lower bound. Our paper shows that the row-update model is strictly easier with a lower upper bound.
Although not explicitly described in their paper , one can directly use their techniques and analysis to achieve a weak form of a non-construction projection bound. One maintains a matrix with columns where is a matrix where each entry is chosen from at random. Then setting , achieves a , however is rank and hence that is the only bound on as well.
Experimental Results
The other three baselines are Sampling, Hashing, and Random-projection, described in Section 5.
2 Datasets
We consider the real-world dataset Birds in which each row represents an image of a bird, and each column a feature. This dataset has 11788 data points and 312 features, and we recover rank for projection error experiments.
3 Results
Similar results in error and runtime are shown on the real Birds data set in Figure 8.
Acknowledgments
The authors thank Qin Zhang for discussion on hardness results. We also thank Stanley Eisenstat, and Mark Tygert for their guidance regarding efficient svd rank-1 updates.