Sketching as a Tool for Numerical Linear Algebra
David P. Woodruff
Introduction
To give the reader a flavor of results in this survey, let us first consider the classical linear regression problem. In a special case of this problem one attempts to “fit” a line through a set of given points as best as possible.
For example, the familiar Ohm’s law states that the voltage is equal to the resistance times the electrical current , or . Suppose one is given a set of example volate-current pairs but does not know the underlying resistance. In this case one is attempting to find the unknown slope of a line through the origin which best fits these examples, where best fits can take on a variety of different meanings.
More formally, in the standard setting there is one measured variable , in the above example this would be the voltage, and a set of predictor variables . In the above example and the single predictor variable is the electrical current. Further, it is assumed that the variables are linearly related up to a noise variable, that is , where are the coefficients of a hyperplane we are trying to learn (which does not go through the origin if ), and is a random variable which may be adversarially chosen, or may come from a distribution which we may have limited or no information about. The are also known as the model parameters. By introducing an additional predictor variable which is fixed to , we can in fact assume that the unknown hyperplane goes through the origin, that is, it is an unknown subspace of codimension . We will thus assume that and ignore the affine component throughout.
Subspace Embeddings and Least Squares Regression
We are interested in fast solutions to this problem, which we present in §2.5.
Definition 2 will be used in applications throughout this book, and sometimes for convenience we will drop the word oblivious.
Returning to Definition 2, the first usage of this in the numerical linear algebra community, to the best of our knowledge, was done by Sárlos, who proposed using Fast Johnson Lindenstrauss transforms to provide subspace embeddings. We follow the exposition in Sarlós for this .
which implies all inner products are preserved up to by rescaling by a constant.
There are many constructions of Johnson-Lindenstrauss transforms, possibly the simplest is given by the following theorem.
We will see a proof of Theorem 4 in Lemma 18.
By an argument of , it suffices to choose so that for all , there exists a vector for which . We will refer to as a -net for .
To see that suffices, if is a unit vector, then we can write
where and is a scalar multiple of a vector in . This is because we can write where and by the definition of . Then, where and
The expansion in (3) then follows by induction. But then,
where the first equality follows by (3), the second equality follows by expanding the square, the third equality follows from (2), and the fourth equality is what we want (after rescaling by a constant factor).
We show the existence of a small -net via a standard argument.
For any , there exists a -net of for which .
This can be done by choosing a maximal set of points on so that no two points are within distance from each other. It follows that the balls of radius centered at these points are disjoint, but on the other hand they are all contained in the ball of radius centered at the origin. The volume of the latter ball is a factor larger than the smaller balls, which implies . See, e.g., for more details.
It follows by setting and in Theorem 4, we can then apply Lemma 5 and (2) to obtain the following theorem. Note that the net size does not depend on , since we just need a -net for the argument, even though the theorem holds for general .
The Fast Johnson Lindenstrauss Transform is significantly faster than the above time for many reasonable settings of the parameters, e.g., in a number of numerical linear algebra applications in which can be exponentially large in . Indeed, the Fast Johnson Lindenstrauss Transform was first used by Sárlos to obtain the first speedups for regression and low rank matrix approximation with relative error. Sárlos used a version of the Fast Johnson Lindenstrauss Transform due to . We will use a slightly different version called the Subsampled Randomized Hadamard Transform, or SRHT for short. Later we will see a significantly faster transform for sparse matrices.
We will not present the proof of Theorem 7, instead relying upon the above intuition. The proof of Theorem 7 can be found in the references listed above.
There are distributions on matrices with the following properties:
2 Matrix multiplication
In this section we study the approximate matrix product problem.
Before giving the theorem, we need a definition.
We now show that sparse embeddings matrices satisfy the -JL-moment property. This was originally shown by Thorup and Zhang .
where the second equality uses that and are independent, while the third equality uses that if , and otherwise is equal to .
where the second equality uses the independence of and , and the third equality uses that since is -wise independent, in order for not to vanish, it must be that either
or
and but or
and but or
and but .
Note that in the last two cases, for not to vanish, we must have . The fourth equality and first inequality are based on regrouping the summations, and the sixth inequality uses that .
3 High probability
() Algorithm 1 outputs a subspace embedding with probability at least . In expectation step 3 is only run a constant number of times.
4 Leverage scores
Proof: We will use the following matrix Chernoff bound for a sum of random matrices, which is a non-commutative Bernstein bound.
For any , is a rank- matrix with operator norm bounded by . Hence,
We need a version of the Johnson-Lindenstrauss lemma, as follows. We give a simple proof for completeness.
The random variable is with degree of freedom. The following tail bounds are known.
(Lemma 1 of ) Let be i.i.d. random variables. Then for any ,
Setting , we have that
For , the lemma follows by a union bound over .
Finally, it follows that for all ,
Hence, , which for an appropriate choice of constant , achieves , as desired.
5 Regression
We formally define the regression problem as follows.
Inspecting the simple proof of Theorem 21 we see that (10) in particular implies
Because of the normal equations, we may apply the Pythagorean theorem,
where the first inequality is the triangle inequality, the second inequality uses the sub-multiplicativity of the spectral norm, and the third inequality uses (12). Rearranging, we have
By the normal equations in the sketch space,
6 Machine precision regression
Here we show how to reduce the dependence on to logarithmic in the regression application, following the approaches in .
and by choosing , say, iterations suffice for this scheme also to attain relative error.
7 Polynomial fitting
We now describe the problem more precisely, starting with a definition.
Vandermonde matrices of dimension require only implicit storage and admit matrix-vector multiplication time (see, e.g., Theorem 2.11 of ). It is also possible to consider block-Vandermonde matrices as in ; for simplicity we will only focus on the simplest polynomial fitting problem here, in which Vandermonde matrices suffice for the discussion.
Least Absolute Deviation Regression
While least squares regression is arguably the most used form of regression in practice, it has certain non-robustness properties that make it unsuitable for some applications. For example, oftentimes the noise in a regression problem is drawn from a normal distribution, in which case least squares regression would work quite well, but if there is noise due to measurement error or a different underlying noise distribution, the least squares regression solution may overfit this noise since the cost function squares each of its summands.
where the inequality follows by Hölder’s inequality.
where can be thought of as a relaxation parameter which will allow for more efficient algorithms.
Using this bound together with independence of the sampled rows,
We have computed and bounded as well as , and can now use strong tail bounds to bound the deviation of from its expectation. We use the following tail inequalities.
Moreover, if for all , we have
It suffices to choose so that for all , there exists a vector for which . Indeed, in this case note that
If , we are done. Otherwise, suppose is such that . Observe that , since, yet .
Then , and we can choose a vector for which , or equivalently, . Hence,
Repeating this argument, we inductively have that
There exists an -net for which .
Then is a -dimensional polytope with a (-dimensional) volume denoted . Moreover, and are similar polytopes, namely, . As such, .
By applying (19) and a union bound over the points in , and rescaling by a constant factor, we have thus shown the following theorem.
2 The Role of subspace embeddings for L1-Regression
Before discussing the existence of such embeddings, let us see how they can be used to speed up the computation of a well-conditioned basis.
3 Gaussian sketching to speed up sampling
we have that (20) holds with .
4 Subspace embeddings using cauchy random variables
The Cauchy distribution, having density function , is the unique -stable distribution. That is to say, if are independent Cauchys, then is distributed as a Cauchy scaled by .
The absolute value of a Cauchy distribution has density function . The cumulative distribution function of it is
Note also that since , we have , so that is the median of this distribution.
Although Cauchy random variables do not have an expectation, and have infinite variance, some control over them can be obtained by clipping them. The first use of such a truncation technique in algorithmic applications that we are aware of is due to Indyk .
Consider the event that a Cauchy random variable satisfies , for some parameter . Then there is a constant for which and where is an absolute constant.
(see “Connection to Auerbach bases” in Section 3.1 of ) There exists a -well-conditioned basis.
For readability, it is useful to separate out the following key lemma that is used in Theorem 36 below. This analysis largely follows that in .
Letting , we have by another union bound that
We can perform the following manipulation (for an event , we use the notation to denote the occurrence of the complement of ):
and . Combining these two, we have
for a sufficiently large constant. Plugging (22) into the above,
We thus have, combining (23) with Markov’s inequality,
As can be chosen sufficiently large, while is the fixed constant of Lemma 33, we have that
The lemma now follows by appropriately setting the constant in the lemma statement.
where the last equality used that is an Auerbach basis.
Hence, the statement of the theorem holds with probability at least , by a union bound over the events in the dilation and contraction arguments. This concludes the proof.
5 Subspace embeddings using exponential random variables
We now describe a speedup over the previous section using exponential random variables, as in . Other speedups are possible, using , though the results in additionally also slightly improve the sampling complexity. The use of exponential random variables in is inspired by an elegant work of Andoni, Onak, and Krauthgamer on frequency moments .
An exponential distribution has support , probability density function and cumulative distribution function . We say a random variable is exponential if is chosen from the exponential distribution. The exponential distribution has the following max-stability property.
If are exponentially distributed, and are real numbers, then , where is exponential.
The following lemma shows a relationship between the Cauchy distribution and the exponential distribution.
Let be scalars. Let be independendent exponential random variables, and let . Let be independent Cauchy random variables, and let . There is a constant for which for any .
Proof: We would like the density function of . Letting , the inverse function is . Taking the derivative, we have . Letting be the density function of the absolute value of a Cauchy random variable, we have by the change of variable technique,
We would also like the density function of , where . Letting , the inverse function is . Taking the derivative, . Letting be the density function of the reciprocal of an exponential random variable, we have by the change of variable technique,
We claim that for a sufficiently small constant . This is equivalent to showing that
which for , is implied by showing that
We distinguish two cases: first suppose . In this case, . Note also that in this case. Hence, . Therefore, the above is implied by showing
which holds for a sufficiently small constant .
Next suppose . In this case , and it suffices to show
Using that for , it suffices to show
which holds for a small enough .
where we made the change of variables . Setting completes the proof.
We need a bound on , where is as in Lemma 38.
There is a constant so that for any ,
Proof: For , let be i.i.d. random variables with . Let . We will obtain tail bounds for in two different ways, and use this to establish the lemma.
On the one hand, by the -stability of the Cauchy distribution, we have that , where is a standard Cauchy random variable. Note that this holds for any fixing of the . The cumulative distribution function of the Cauchy random variable is Hence for any ,
and therefore using the Taylor series for for ,
On the other hand, for any fixing of , we have
If is a random variable with finite variance, and , then
Applying this inequality with and , we have
Suppose, towards a contradiction, that for a sufficiently large constant . By independence of the and the , by (26) this implies
By (25), this is a contradiction for . It follows that , as desired.
Let be scalars. Let be independendent exponential random variables, and let . There is a constant for which for any ,
Proof: The corollary follows by combining Lemma 38 with Lemma 39, and rescaling the constant from Lemma 39 by , where is the constant of Lemma 38.
For the dilation, we need Khintchine’s inequality.
(). Let for i.i.d. random variables uniform in , and be scalars. There exists a constant for which for all
which we denote by event and condition on. Notice that the probability is taken only over the choice of the , and therefore conditions only the random variables.
In the following, and . Let be the event that
Letting , we have by Corollary 40,
We can perform the following manipulation:
It follows by linearity of expectation that,
Consequently, by a Markov bound, and using that , conditioned on , with probability at least , we have the occurrence of the event that
where the first inequality uses the triangle inequality, the second the occurrence of , and the third (28). This completes the proof.
Proof: The corollary follows by combining Theorem 30, Lemma 32 and its optimization in §3.3, and Theorem 41.
6 Application to hyperplane fitting
For the subspace approximation problem, we can write
Low Rank Approximation
We will show how to use sketching to speed up algorithms for both problems, and further variants. Our exposition is based on combinations of several works in this area by Sárlos, Clarkson, and the author .
Section Overview: In §4.1 we give an algorithm for computing a low rank approximation achieving error proportional to the Frobenius norm. In §4.2 we give a different kind of low rank approximation, called a CUR decomposition, which computes a low rank approximation also achieving Frobenius norm error but in which the column space equals the span of a small subset of columns of the input matrix, while the row space equals the span of a small subset of rows of the input matrix. A priori, it is not even clear why such a low rank approximation should exist, but we show that it not only exists, but can be computed in nearly input sparsity time. We also show that it can be computed deterministically in polynomial time. This algorithm requires several detours into a particular kind of spectral sparsification given in §4.2.1, as well as an adaptive sampling technique given in §4.2.2. Finally in §4.2.3 we show how to put the pieces together to obtain the overall algorithm for CUR factorization. One tool we need is a way to compute the best rank- approximation of the column space of a matrix when it is restricted to lie within a prescribed subspace; we defer the details of this to §4.4, where the tool is developed in the context of an application called Distributed Low Rank Approximation. In §4.3 we show how to perform low rank approximation with a stronger guarantee, namely, an error with respect to the spectral norm. While the solution quality is much better than in the case of the Frobenius norm, it is unknown how to compute this as quickly, though one can still compute it much more quickly than the SVD. In §4.4 we present the details of the Distributed Low Rank Approximation algorithm.
Rescaling by a constant factor completes the proof.
Fortunately, we can cast this projection problem as a regression problem, and solve it approximately.
implying the first part of the theorem after rescaling by a constant factor.
For the second part of the theorem, note that Lemma 45 gives the stronger guarantee that
2 CUR decomposition
We now outline the approach of Boutsidis and the author . A key lemma we need is the following, which is due to Boutsidis, Drineas, and Magdon-Ismail .
as needed. The lemma now follows by Markov’s bound.
To proceed, we need an algorithm in the next subsection, which uses a method of Batson, Spielman, and Srivastava refined for this application by Boutsidis, Drineas, and Magdon-Ismail .
The following theorem shows correctness of the Deterministic Dual Set Spectral Sparsification algorithm described in Algorithm 2.
We now turn to correctness. The crux of the analysis turns out to be to show there always exists an index in each iteration for which
We start with a lemma which uses the Sherman-Morrison-Woodbury identity to analyze a rank- perturbation.
For the second part, we use the following well-known formula.
Letting , we have
We also need the following lemma concerning properties of the function.
or equivalently, . Hence,
Equipped with Lemma 51 and Lemma 52, we now prove the main lemma we need.
At every iteration , there exists an index for which
Indeed, if we show (33), then by averaging there must exist an index for which
We first prove the equality in (33) using the definition of . Observe that it holds that
We will show below. Given this, we have
where the inequality uses Lemma 51. Since , we have
We now turn to the task of showing . The Cauchy-Schwarz inequality implies that for , one has , and therefore
Plugging into (34), we conclude that , as desired.
By Lemma 53, the algorithm is well-defined, finding a at each iteration (note that since ).
Finally, note that Algorithm 2 runs in steps. The vector of weights is initialized to the all-zero vector, and one of its entries is updated in each iteration. Thus, will contain at most non-zero weights upon termination. As shown above, the value chosen in each iteration is non-negative, so the weights in are non-negative.
We will also need the following corollary, which shows how to perform the dual set sparsification much more efficiently if we allow it to be randomized.
Lemma 55 gives us a way to find columns providing an -approximation. We would like to refine this approximation to a -approximation using only an additional number of columns. To do so, we perform a type of residual sampling from this -approximation, as described in the next section.
2.2 Adaptive sampling
For , and some fixed constant let be a probability distribution such that for each
For let be a probability distribution such that for each
To analyze the expected error of the algorithm with respect to the choices made in the sampling procedure, we have
where the second equality uses the Pythagorean theorem.
2.3 CUR wrapup
Hence, for a parameter , if we set
3 Spectral norm error
We also collect a few facts about the singular values of a Gaussian matrix.
In order to analyze SubspacePowerMethod, we need a key lemma shown in concerning powering of a matrix.
If we raise both sides to the -th power, then this completes the proof.
We can now prove the main theorem about SubspacePowerMethod
4 Distributed low rank approximation
The main algorithm AdaptiveCompress of is given in Algorithm AdaptiveCompress below.
Graph Sparsification
We formally define the problem as follows, following the notation and outlines of . Consider an ordering on the vertices, denoted . We will only consider undirected graphs, though we will often talk about edges as , where here is less than in the ordering we have placed on the edges. This will be for notational convenience only; the underlying graphs are undirected.
We call a spectral sparsifier of The usual notation for (57) is
Notice that Theorem 64 shows that if one knows the leverage scores, then by sampling edges of and reweighting them, one obtains a spectral sparsifier of . One can use algorithms for approximating the leverage scores of general matrices , though more efficient algorithms, whose overall running time is near-linear in the number of edges of , are known .
A beautiful theorem of Kapralov, Lee, Musco, Musco, and Sidford is the following .
In the remainder of the section, we give an outline of the proof of Theorem 65, following the exposition given in . We restrict to unweighted graphs for the sake of presentation; the arguments generalize in a natural way to weighted graphs.
The proof of the following theorem is elementary. We believe the power in the theorem is its novel use in algorithm design.
For the second condition, for all ,
Finally, for the third condition, for all ,
The bounds on the eigenvalues of a Laplacian are given in (the bound on the maximum eigenvalue follows from the fact that is the maximum eigenvalue of the Laplacian of the complete graph on vertices. The bound on the minimum eigenvalue follows from Lemma 6.1 of ).
To do this, first observe that the leverage score for a potential edge is given by
Then, by the second property of Theorem 66,
Thus, the only task left is to implement this hierarchy of leverage score sampling using linear sketches.
For this, we need the following standard theorem from the sparse recovery literature.
Several standard consequences of this theorem, as observed in , can be derived by setting for a constant , which is the setting of we use throughout. Of particular interest is that for , from one can determine if or given that it satisfies one of these two conditions. We omit the proof of this fact which can be readily verified from the statement of Theorem 67, as shown in .
Sketching Lower Bounds for Linear Algebra
While sketching, and in particular subspace embeddings, have been used for a wide variety of applications, there are certain limitations. In this section we explain some of them.
While our focus in this section is on lower bounds, we mention that for integers , there is the following simple algorithm for estimating Schatten norms which has a good running time but requires multiple passes over the data. This is given in .
Proof: Let for a positive constant . Suppose are independent vectors, that is, they are independent vectors of i.i.d. normal random variables with mean and variance .
where we use that for all . We also have that
This shows correctness. The running time follows from our bound on and the number of passes.
2 Sketching the operator norm
The idea is to use the min-max principle for singular values.
Proof: The min-max principle for singular values says that
The lemma now follows from the min-max principle for singular values, since every vector in the range has its norm preserved up to a factor of , and so this also holds for any -dimensional subspace of the range, for any .
is the distribution on matrices with i.i.d. entries.
It follows with probability , by the triangle inequality
In our proof we need the following tail bound due to Latała Suppose that are i.i.d. random variables. The following result, due to Latała , bounds the tails of Gaussian chaoses . The proof of Latała’s tail bound was later simplified by Lehec .
where are constants depending only on .
To prove the main theorem of this section, we need a few facts about distances between distributions.
In general is not a distance because it is not symmetric.
The total variation distance between and , denoted by , is defined as for . It can be verified that this is indeed a distance. It is well known that if , then the probability that any, possibly randomized algorithm, can distinguish the two distributions is at most .
The -divergence between and , denoted by , is defined as for or . It can be verified that these two choices of give exactly the same value of .
We can upper bound total variation distance in terms of the -divergence using the next proposition.
.
The next proposition gives a convenient upper bound on the -divergence between a Gaussian distribution and a mixture of Gaussian distributions.
We can now prove the main impossibility theorem about sketching the operator norm up to a constant factor.
Partition of size 1. The only possible partition is . We have
Partitions of size 3. Up to symmetry, there are only two partitions to consider: , and . We first consider the partition . We have
where the first inequality follows from Cauchy-Schwarz. We now consider the partition . We have
where the second equality follows by Cauchy-Schwarz.
Partition of size 4. The only partition is . Using that for integers , , we have
Latała’s inequality (Theorem 72) states that for ,
The above holds with no conditions imposed on . For convenience, we let
Note that conditioned on and ,
We now claim that for all , provided . First, note that since , . Also, since , . Hence, . Since , if achieves the minimum, then it is larger than . On the other hand, if achieves the minimum, then whenever , which since , always holds.
3 Streaming lower bounds
In this section, we explain some basic communication complexity, and how it can be used to prove bit lower bounds for the space complexity of linear algebra problems in the popular streaming model of computation. We refer the reader to Muthukrishnan’s survey for a comprehensive overview on the streaming model. We state the definition of the model that we need as follows. These results are by Clarkson and the author , and we follow the exposition in that paper.
4 Communication complexity
For lower bounds in the turnstile model, we use a few definitions and basic results from two-party communication complexity, described below. We refer the reader to the book by Kushilevitz and Nisasn for more information . We will call the two parties Alice and Bob.
For a function , we use to denote the randomized communication complexity with two-sided error at most in which only a single message is sent from Alice to Bob. Here, only a single message is sent from Alice to Bob, where is Alice’s message function of her input and her random coins. Bob computes , where is a possibly randomized function of and Bob’s input . For every input pair , Bob should output a correct answer with probability at least , where the probability is taken over the joint space of Alice and Bob’s random coin tosses. If this holds, we say the protocol is correct. The communication complexity is then the minimum over correct protocols, of the maximum length of Alice’s message , over all inputs and all settings to the random coins.
We also use to denote the minimum communication of a protocol, in which a single message from Alice to Bob is sent, for solving with probability at least , where the probability now is taken over both the coin tosses of the protocol and an input distribution .
In the augmented indexing problem, which we call , Alice is given , while Bob is given both an together with . Bob should output .
() and also , where is uniform on .
We start with an example showing how to use Theorem 74 for proving space lower bounds for the Matrix Product problem, which is the same as given in Definition 11. Here we also include in the definition the notions relevant for the streaming model.
Proof: Throughout we shall assume that is an integer, and that is an even integer. These conditions can be removed with minor modifications. Let be a -pass algorithm which solves Matrix Product with probability at least . Let . We use to solve instances of on strings of size . It will follow by Theorem 74 that the space complexity of must be .
It follows that the parties can solve the AIND problem with probability at least . The theorem now follows by Theorem 74.
4.2 Regression and low rank approximation
One can similarly use communication complexity to obtain lower bounds in the streaming model for Regression and Low Rank Approximation. The results are again obtained by reduction from Theorem 74. They are a bit more involved than those for matrix product, and so we only state several of the known theorems regarding these lower bounds. We begin with the formal statement of the problems, which are the same as defined earlier, specialized here to the streaming setting.
() Let and be arbitrary. Then,
5 Subspace embeddings
6 Adaptive algorithms
In this section we would like to point out a word of caution of using a sketch for multiple, adaptively chosen tasks.
with probability at least for some parameter . In this section we will focus on the case in which for every constant , that is, shrinks faster than any inverse polynomial in
Further, the algorithm runs in time and the first queries can be chosen non-adaptively (so the algorithm makes a single adaptive query, namely, ).
Proof: The algorithm first queries the sketch on the vectors
We state some of the intuition behind the proof of Theorem 83 below.
Formally, Theorem 83 makes use of a conditional expectation lemma showing that there exists a choice of for which
Open Problems
We have attempted to cover a number of examples where sketching techniques can be used to speed up numerical linear algebra applications. We could not cover everything and have of course missed out on some great material. We encourage the reader to look at other surveys in this area, such as the one by Mahoney , for a treatment of some of the topics that we missed.