Uniform Sampling for Matrix Approximation
Michael B. Cohen, Yin Tat Lee, Cameron Musco, Christopher Musco, Richard Peng, Aaron Sidford
Introduction
By re-examining uniform sampling, a heuristic known to work for low coherence data, we give spectral approximation algorithms that avoid projection entirely. Our methods are the first to match state-of-the-art runtimes while preserving row structure and sparsity in all matrix operations.
Possible fixes include randomly “mixing” data points to avoid degeneracies [AMT10]. However, this approach sacrifices sparsity and structure in our data matrix, increasing storage and runtime costs. Is there a more elegant fix? First note that sampling by approximate leverage scores is fine, but we may need to select more than the optimal rows. With that in mind, consider the following straightforward algorithm for iterative sampling (inspired by [LMP13]):
Reduce significantly by sampling uniformly.
Approximate using the smaller matrix and estimate leverage scores for .
While intuitive, this scheme was not previously known to work! Our main technical result is proving that it does. This process (and related schemes) will quickly converge on a small spectral approximation to – i.e. with rows.
More importantly, both of these results are similar in that they rely on the primitive that a (possibly poor) spectral approximation to is sufficient for approximately computing leverage scores, which are in turn good enough for obtaining an even better spectral approximation. As mentioned, uniform sampling will not in general give a spectral approximation – it does not preserve information about all singular values. Our key contribution is a better understanding of what information uniform sampling does preserve. It turns out that, although weaker than a spectral approximation, the matrix obtained from uniform sampling can nonetheless give leverage score estimates that are good enough to obtain increasingly better approximations to .
where is some fixed constant. Note that, when sampling by exact leverage scores, it can be shown that so we take rows.
Thus, to prove that our proposed iterative algorithm works, we need to show that, if we uniformly sample a relatively small number of rows from (Step 1) and estimate leverage scores using these rows (Step 2), then the sum of our estimates will be small. Then, when we sample by these estimated leverage scores in Step 3, we can sufficiently reduce the size of . Note that we will not aim to reduce to height in one shot – we just need our leverage estimates to sum to say, , which allows us to cut the large matrix in half at each step.
In prior work, the sum of overestimates was bounded by estimating each leverage score to within a multiplicative factor. This requires a spectral approximation, which is why previous iterative sampling schemes could only boost poor spectral approximations to better spectral approximations. Of course, a “for each” statement is not required, and we will not get one through uniform sampling. Thus, our core result avoids this technique. Specifically, we show,
Although not stated here for conciseness, we also prove versions of Theorem 1 with slightly different guarantees (Theorems 3 and 4) using a technique that we believe is of independent interest. It is well known that, if has low coherence – that is, has a low maximum leverage score – then uniform sampling from the matrix is actually sufficient for obtaining a full spectral approximation. The uniform rate will upper bound the leverage score rate for every row. With this in mind, we show a powerful fact: while many matrices do not have low coherence, for any , we can decrease the weight on a small subset of rows to make the matrix have low coherence. Specifically,
Intuitively, this lemma shows that uniform sampling gives a matrix that spectrally approximates a large sub-matrix of the original data. It follows from our more general Theorem 2, which describes exactly how leverage scores of can be manipulated through row reweighting.
2 Road Map
Survey prior work on randomized linear algebra and spectral matrix approximation.
Review frequently used notation and important foundational lemmas.
Prove that uniform sampling is sufficient for leverage score estimation (Theorem 1).
Show the existence of small, coherence-reducing reweightings (Theorem 2, Lemma 1).
Use this result to prove alternative versions of Theorem 1 (Theorems 3 and 4).
Describe simple and efficient iterative algorithms for spectral matrix approximation.
Background
In the past decade, fast randomized algorithms for matrix problems have risen to prominence. Numerous results give improved running times for matrix multiplication, linear regression, and low rank approximation – helpful surveys of this work include [Mah11] and [HMT11]. In addition to asymptotic runtime gains, randomized alternatives to standard linear algebra tools tend to offer significant gains in terms of data access patterns and required working memory.
Algorithms for randomized linear algebra often work by generically reducing problem size – large matrices are compressed (using randomness) to smaller approximations which are processed deterministically via standard linear algebraic methods. Methods for matrix reduction divide roughly into two categories – random projection methods [CW09, CW13, MM13, NN12, Sar06] and sampling methods [DKM04, DKM06a, DKM06b, DMM08, DM10, LMP13].
Random projection methods recombine rows or columns from a large matrix to form a much smaller problem that approximates the original. Descending from the Johnson-Lindenstrauss Lemma [JL84] and related results, these algorithms are impressive for their simplicity and speed – reducing a large matrix simply requires multiplication by an appropriately chosen random matrix.
Sampling methods, on the other hand, seek to approximate large matrices by judiciously selecting (and reweighting) few rows or columns. Sampling itself is even simpler and faster than random projection – the challenge becomes efficiently computing the correct measure of “importance” for rows or columns. More important rows or columns are selected with higher probability.
2 Approximate Linear Regression
3 Row Sampling
As discussed, an alternative route to spectral matrix approximation is importance sampling. Specifically, rows can be sampled with probability proportional to their leverage scores, as suggested in [DMM06] and proved by Spielman and Srivastava [SS08]. Spielman and Srivastava were specifically focused on spectral approximations for the edge-vertex incidence matrix of a graph. This is more commonly referred to as spectral sparsification – a primitive that has been very important in literature on graph algorithms. Each row in a graph’s (potentially tall) edge-vertex incident matrix corresponds to an edge and the row’s leverage score is exactly the edge’s weighted effective resistance, whicth is used as the sampling probability in [SS08].
While leverage scores for the edge-vertex incidence matrix of a graph can be computed quickly [KMP10, ST04], in general, computing leverage scores requires evaluating , which is as difficult as solving regression in the first place. Li, Miller, and Peng address this issue with methods for iteratively computing good row samples [LMP13]. Their algorithms achieve input-sparsity time regression, but are fairly involved and rely on intermediate operations that ultimately require Johnson-Lindenstrauss projections, mixing rows and necessitating dense matrix operations. An alternative approach from [LMP13] does preserve row structure (except for possible additions of rows from the identity to intermediate matrices) but converges in a number of steps that depends on ’s condition number.
Notation and Preliminaries
2 Spectral Approximation
Letting denote the singular value of a matrix, -spectral approximation implies:
3 Leverage Scores
The leverage score of the row of is:
A row’s leverage score measures how important it is in composing the row space of . If a row has a component orthogonal to all other rows, its leverage score is . Removing it would decrease the rank of , completely changing its row space. If all rows are the same, each has leverage score . The coherence of is . If has low coherence, no particular row is especially important. If has high coherence, it contains at least one row whose removal would significantly affect the composition of ’s row space. A characterization that helps with this intuition follows:
Let denote the optimal for . The entry of is given by .
If has an component in , we set its generalized leverage score to , since it might be the only row in pointing in this direction. Thus, when sampling rows, we cannot remove it. We could set the generalized leverage score to , but using simplifies notation in some of our proofs. If is a spectral approximation for , then every generalized leverage score is a good multiplicative approximation to its corresponding true leverage score:
If is a -spectral approximation of , so , then .
This follows simply from the definition of leverage scores and generalized leverage scores and the fact that implies . ∎
4 Leverage Score Sampling
Sampling rows from according to their exact leverage scores gives a spectral approximation for with high probability. Sampling by leverage score overestimates also suffices. Formally:
Given an error parameter , let be a vector of leverage score overestimates, i.e., for all . Let be a sampling rate parameter and let be a fixed positive constant. For each row, we define a sampling probability . Furthermore, let denote a function which returns a random diagonal matrix with independently chosen entries. with probability and otherwise.
If we set , has at most non-zero entries and is a -spectral approximation for with probability at least .
For completeness, we prove Lemma 4 in Appendix A using a matrix concentration result of [Tro12].
Leverage Score Estimation via Uniform Sampling
In this section, we prove Theorem 1 using a simple expectation argument. We restate a more complete version of the theorem below:
When , so it holds trivially.
When and then by the Sherman-Morrison formula for pseudoinverses [Mey73, Thm 3],
This random process is also equivalent to randomly selecting a set of rows, then randomly choosing a row and returning its leverage score! In expectation it is therefore equal to the average leverage score in . has rows and its leverage scores sum to its rank, so we can bound its average leverage score by . Overall we have:
Coherence Reducing Reweighting
In this section, we prove Theorem 2, which shows that we can reweight a small number of rows in any matrix to make it have low coherence. This structural result may be of independent interest. It is also fundamental in proving Theorem 3, a slightly stronger and more general version of Theorem 1 that we will prove in Section 6.
Actually, for Theorem 2 we prove a more general statement, studying how to select a diagonal row reweighting matrix to arbitrarily control the leverage scores of . One simple conjecture would be that, given a vector , there always exists a such that . This conjecture is unfortunately not true - if is the identity matrix, then if and otherwise. Instead, we show the following:
Note that (6) is easy to satisfy – it holds if we set . Hence, the main result is the second claim . Not only does a exist that gives the desired leverage score bounds, but it is only necessary to reweight rows in with a low total weight in terms of .
For any incoherence parameter , if we set for all , then this theorem shows the existence of a reweighting that reduces coherence to . Such a reweighting has and therefore . So, we see that Lemma 1 follows as a special case of Theorem 2.
In order to prove Theorem 2, we first give two technical lemmas which are proved in Appendix A. Lemma 5 describes how the leverage scores of evolve when a single row of is reweighted. We show that, when we decrease the weight of a row, that row’s leverage score decreases and the leverage score of all other rows increases.
Next we claim that leverage scores are lower semi-continuous in the weighting of the rows. This allows us to reason about weights that arise as the limit of Algorithm 1 for computing them.
is lower semi-continuous in the diagonal matrix , i.e. for any sequence with for all and , we have
With Lemmas 5 and 6 in place, we are ready to prove the main reweighting theorem.
We prove the existence of the required by considering the limit of the following algorithm for computing a reweighting matrix.
For all , let be the value of after the update to the weight. We show that meets the conditions of Theorem 2. First note that Algorithm 1 is well defined and that all entries of are non-negative for all . To see this, suppose we need to decrease so that . Note that the condition gives
Therefore, Lemma 5 shows that we can make arbitrary small by setting close enough to . Since the leverage score for row is continuous, this implies that exists as desired.
Since, the entries of are non-negative and decrease monotonically by construction, clearly exists. Furthermore, since setting makes , we see that, by construction,
Therefore, by Lemma 6 we have that .
It only remains to show that . Let be the first iteration such that for any such that . Let be the set of rows such that and let . Since decreasing the weight of one row increases the leverage scores of all other rows, we have
When we set , it must be the case that . In this case, removing the row decreases the rank of by 1 and hence . Therefore,
Leverage Score Approximation via Undersampling
Theorem 1 alone is enough to prove that a variety of iterative methods for spectral matrix approximation work. However, in this section we prove Theorem 3, a slight strengthening and generalization that improves runtime bounds, proves correctness for some alternative sampling schemes, and gives some more intuition for why uniform sampling allows us to obtain leverage score estimates with low total sum.
Theorem 3 relies on Theorem 2, which intuitively shows that a large fraction of our matrix has low coherence. Sampling rows uniformly will give a spectral approximation for this portion of our matrix. Then, since few rows are reweighted in , even loose upper bounds on the leverage scores for those rows will allow us to bound the total sum of estimated leverage scores when we sample uniformly.
Formally, we show an upper bound on the sum of estimated leverage scores obtained from undersampling according to any set of leverage score upper bounds. Uniform sampling can simply be viewed as undersampling when all we know is that each leverage score is upper bounded by . That is, in the uniform case, we set .
The bound in Theorem 3 holds with high probability, rather than in expectation like the bound in Theorem 1. This gain comes at a cost of requiring our sampling rate to be higher by a factor of . At the end of this section we show how the factor can be removed at least in the case of uniform sampling, giving a high probability statement that matches the bound of Theorem 1.
Let be a vector of leverage score overestimates, i.e., for all . For some undersampling parameter , let . Let Then, with high probability, is a leverage score overestimate, i.e. , and
Furthermore, has nonzeros.
Let . Since is a set of leverage score overestimates, Lemma 4 (with ) shows that, with high probability,
In , when we include a row, we reweight it by . For , we sample at a rate lower by a factor of as compared with , so we weight rows by a factor of higher. The multiplied by makes up for this difference. Thus, is equivalent to with some rows removed. Therefore:
So, for all , . By assumption , so this proves that .
By Theorem 2, there is a diagonal matrix such that for all and . For this , using the fact that , we have
Using , we have
Now, note that . Since is an overestimate of leverage scores for , Lemma 4 (again with ) shows that . Hence (9) along with Lemma 3 shows that
Choosing an undersampling rate is equivalent to choosing a desired sampling rate and setting accordingly. From this perspective, it is clear that the above theorem gives an extremely simple way to iteratively improve leverage scores. Start with with . Undersample at rate to obtain a sample of size , which gives new leverage score estimates with . Repeat this process, cutting the sum of leverage score estimates in half with each iteration. Recall that we restrict , so once the sum of leverage score estimates converges on , this halving process halts – as expected, we can not keep cutting the sum further.
The algorithm just described corresponds to Algorithm 3 in Section 7 and differs somewhat from approaches discussed earlier (e.g. our proposed iterative algorithm from Section 1). It always maintains a sample of just rows that is improved iteratively.
Consider instead sampling few rows from with the goal of estimating leverage scores well enough to obtain a spectral approximation with rows. In the uniform sampling case, when , if we set for example, then sampling rows uniformly will give us leverage score estimates summing to . This is good enough to cut our original matrix in half. However, we see that we have lost a factor to Theorem 1, which let us cut down to expected size by sampling just rows uniformly.
At least when , this factor can be eliminated. In Theorem 3, we set , meaning that rows selected for are included with weight . Instead of reweighting rows, consider simply setting all non-zero values in to be . We know that our leverage score estimates will still be overestimates as we still have and so . Further
. In this case, is simply itself, so we know our leverage score estimates are exact and thus their sum is . We can use them to obtain a spectral approximation with rows.
. In this case, we reweight rows by . Thus, increasing weights in to will reduce leverage score estimates by a factor of . So overall we have:
Recall from Lemma 4 that sampling by actually gives a matrix with rows. Thus, we obtain a -spectral approximation to with the following number of rows:
Setting for some so that samples rows at rate yields the following theorem:
Choosing allows us to find a spectral approximation of size , as long as . This matches the bound of Theorem 1, but holds with high probability.
Applications to Row Sampling Algorithms
As discussed in the introduction, Theorems 1, 3, and 4 immediately yield new, extremely simple algorithms for spectral matrix approximation. For clarity, we initially present versions running in nearly input-sparsity time. However, we later explain how our first algorithm can be modified with standard techniques to remove log factors, achieving input-sparsity time and thus matching state-of-the-art results [CW13, MM13, NN12]. Our algorithms rely solely on row sampling, which preserves matrix sparsity and structure, possibly improving space usage and runtime for intermediate system solves.
The first algorithm we present, Repeated Halving, is a simple recursive procedure. We uniformly sample rows from to obtain . By Theorems 1 and 4, estimating leverage scores of with respect to this sample allows us to immediately find a spectral approximation to with rows. Of course, is still large, so computing these estimates would be slow. Thus, we recursively find a spectral approximation of and use this to compute the estimated leverage scores.
2 Runtime Analysis
First, we give an important primitive showing that estimates of generalized leverage scores can be computed efficiently. Computing exact generalized leverage scores is slow and we only need constant factor approximations, which will only increase our sampling rates and hence number of rows sampled by a constant factor.
By setting , we can obtain constant factor approximations to generalized leverage scores in time .
Lemma 7 follows from a standard technique that uses Johnson-Lindenstrauss projections [AT11, LMP13, SS08]. Presuming , the general idea is to write . If we instead compute , where is a random Gaussian matrix with rows, then by the Johnson-Lindenstrauss Lemma, with high probability, the approximation will be within a factor of for all (See Lemma 4.5 of [LMP13]).
The naive approach requires multiplying every row by , which has height and would thus incur cost . Computing takes at most time to compute , and time to compute and invert it. It then takes less than time to multiply these two matrices. With in hand, we just need to multiply by each row in to obtain our generalized leverage scores, which takes time . If we use an alternative system solver instead of explicitly computing , the JL reduction means we only need to solve systems in to compute (one for each row of ).
A slight modification is needed to handle the case when – we need to check whether the vector has a component in the null-space of . There are a variety of ways to handle this detection. For example, we can choose a random gaussian vector and compute . This gives a random vector in the null space of , so computing its dot product with any row will tell us (with probability 1) whether is orthogonal to the null space or not. ∎
With this primitive in place, we can analyze the runtime of our two algorithms. For simplicity, we just give runtimes for computing a constant factor spectral approximation to . Such an approximation is sufficient for use as a preconditioner in iterative regression algorithms [AMT10, CW13, RT08]. Furthermore, it allows us to compute leverage scores of up to a constant factor, from which we can sample rows to directly obtain a approximation with rows. By Lemma 7 the runtime of this final refinement is just .
The proof is by induction – it suffices to show that the work done at the top level is . At each of the levels of recursion, we cut our matrix in half uniformly so will also be cut approximately in half with high probability.
3 Achieving Input Sparsity Time
As is standard, factors on the term are ‘hidden’ as we can just slightly increase the value of to subsume them. The full tradeoff parameterized by is:
4 General Sampling Framework
It is worth mentioning that Algorithms 2 and 3 are two extremes on a spectrum of algorithms between halving and refinement sampling. Generically, the full space of algorithms can be summarized using the pseudocode in Algorithm 4. For notation, note that always refers to our original data matrix. is the data matrix currently being processed in the recursive call to Algorithm 4.
Different choices for and lead to different algorithms. Note that the last recursion to approximate has error build up incurred from sampling to create . As a result, this generic scheme has error buildup, but it can be removed by sampling w.r.t. instead of .
Note that if we choose , we can simply set , and the first recursive call in Line 2 is not necessary. Also, Theorem 3 gives that, if we pick sufficiently large, can be bounded by . This would then remove the last recursive call to compute . Such modifications lead to head and tail recursive algorithms, as well as a variety of intermediate forms:
Head recursive algorithm, , giving Algorithm 2 (Repeated Halving).
Tail recursive algorithm, , , sampled w.r.t. . At each step error compounds so setting error to per step gives a constant factor approximation.
, , sampled w.r.t. , giving Algorithm 3 (Refinement Sampling).
For situations where iterations are expensive, e.g. MapReduce, a useful choice of parameters is likely , This allows one to compute and without recursion, while still giving speedups.
Acknowledgements
We would like to thank Jonathan Kelner and Michael Kapralov for helpful discussions. This work was partially supported by NSF awards 0843915, 1111109, and 0835652, CCF-AF-0937274, CCF-0939370, and CCF-1217506, NSF Graduate Research Fellowship grant 1122374, Hong Kong RGC grant 2150701, AFOSR grant FA9550-13-1-0042, and the Defense Advanced Research Projects Agency (DARPA).
References
Appendix A Properties of Leverage Scores
Here we prove Lemma 4, which states that it is possible to obtain a spectral approximation by sampling rows from independently with probabilities proportional to leverage score overestimates.
Given an error parameter , let be a vector of leverage score overestimates, i.e., for all . Let be a sampling rate parameter and let be a fixed positive constant. For each row, we define a sampling probability . Furthermore, we define a function , which returns a random diagonal matrix with independently chosen entries. with probability and otherwise.
Setting , has at most non-zero entries and is a -spectral approximation for with probability at least .
We rely on the following matrix concentration result, which is a variant of Corollary 5.2 from [Tro12], given by Harvey in [Har12]:
First, consider when . The is slightly less direct, and we will deal with it shortly. , so implies that . We have
is rank 1, so its maximum (only) eigenvalue is equal to its trace. By the cyclic property, . Furthermore, the matrix is positive semidefinite, so
which gives us (12) and thus (10) when .
Equation (10) does not hold directly when . In this case, with probability . However, selecting is exactly the same as selecting and summing random variables , each equal to with probability , and thus clearly satisfying
A.2 Rank 1 Updates
Here we prove Lemma 5, making critical use of the Sherman-Morrison formula for the Moore-Penrose pseudoinverse [Mey73, Thm 3].
A.3 Lower Semi-continuity of Leverage Scores
Here we prove Lemma 6 by providing a fairly general inequality, Lemma 12, for relating leverage scores under one set of weights to leverage scores under another.
is lower semi-continuous in the diagonal matrix , i.e. for any sequence with for all and , we have
Note that is in the image of as and . Consequently,
Since , Lemma 2 implies
We can bound the contribution of by
Applying triangle inequality to (16), (17), and (18) yields the result. ∎
For any such that (14) follows trivially from the fact that leverage scores are non-negative. For any such that , since we know that, for all sufficiently large for some fixed value , it is the case that . Furthermore, this implies that as we have and . Applying Lemma 12 with and taking on both sides of (15) gives the result. ∎