Randomized Extended Kaczmarz for Solving Least-Squares
Anastasios Zouzias, Nikolaos Freris
Introduction
The Kaczmarz method is an iterative projection algorithm for solving linear systems of equations [Kac37]. Due to its simplicity, the Kaczmarz method has found numerous applications including image reconstruction, distributed computation and signal processing to name a few [FCM+92, Her80, Nat01, FZ12], see [Cen81] for more applications. The Kaczmarz method has also been rediscovered in the field of image reconstruction and called ART (Algebraic Reconstruction Technique) [GBH70], see also [CZ97, Her80] for additional references. It has been also applied to more general settings, see [Cen81, Table 1] and [Tom55, McC75] for non-linear versions of the Kaczmarz method.
Kaczmarz proved that this process converges to the unique solution for square non-singular matrices [Kac37], but without any attempt to bound the rate of convergence. Bounds on the rate of convergence of the Kaczmarz method are given in [McC75], [Ans84] and [Gal03, Theorem 4.4, p.120]. In addition, an error analysis of the Kaczmarz method under the finite precision model of computation is given in [Kni93, Kni96].
Nevertheless, the Kaczmarz method converges even if the linear system is overdetermined () and has no solution. In this case and provided that has full column rank, the Kaczmarz method converges to the least squares estimate. This was first observed by Whitney and Meany [WM67] who proved that the relaxed Kaczmarz method converges provided that the relaxation parameters are within $\lambda_{k}\to 0$, see also [CEG83, Theorem 1], [Tan71] and [HN90] for additional references.
In the literature there was empirical evidence that selecting the rows non-uniformly at random may be more effective than selecting the rows via Kaczmarz’s cyclic manner [HM93, FCM+92]. Towards explaining such an empirical evidence, Strohmer and Vershynin proposed a simple randomized variant of the Kaczmarz method that has exponential convergence in expectation [SV09] assuming that the linear system is solvable; see also [LL10] for extensions to linear constraints. A randomized iterative algorithm that computes a sequence of random vectors is said to converge in expectation to a vector if and only if as , where the expectation is taken over the random choices of the algorithm. Soon after [SV09], Needell analyzed the behavior of the randomized Kaczmarz method for the case of full column rank linear systems that do not have any solution [Nee10]. Namely, Needell proved that the randomized Kaczmarz estimate vector is (in the limit) within a fixed distance from the least squares solution and also that this distance is proportional to the distance of from the column space of . In other words, Needell proved that the randomized Kaczmarz method is effective for least squares problems whose least squares error is negligible.
In this paper we present a randomized iterative least squares solver (Algorithm 3) that converges in expectation to the minimum Euclidean norm solution of
The proposed algorithm is based on [SV09, Nee10] and inspired by [Pop99]. More precisely the proposed algorithm can be thought of as a randomized variant of Popa’s extended Kaczmarz method [Pop99], therefore we named it as randomized extended Kaczmarz.
In Section 2, we briefly discuss related work on the design of deterministic and randomized algorithms for solving least squares problems. In Section 3, we present a randomized iterative algorithm for projecting a vector onto a subspace (represented as the column space of a given matrix) which may be of independent interest. In addition, we discuss the convergence properties of the randomized Kaczmarz algorithm for solvable systems (Section 3.2) and recall its analysis for non-solvable systems (Section 3.3). In Section 4, we present and analyze the randomized extended Kaczmarz algorithm. Finally, in Section 5 we provide a numerical evaluation of the proposed algorithm.
Least squares solvers
In this section we give a brief discussion on least squares solvers including deterministic direct and iterative algorithms together with recently proposed randomized algorithms. For a detailed discussion on deterministic methods, the reader is referred to [Bj96]. In addition, we place our contribution in context with prior work.
In the literature, several methods have been proposed for solving least squares problems of the form (1). Here we briefly describe a representative sample of such methods including the use of QR factorization with pivoting, the use of the singular value decomposition (SVD) and iterative methods such as Krylov subspace methods applied on the normal equations [Saa03]. LAPACK provides robust implementations of the first two methods; DGELSY uses QR factorization with pivoting and DGELSD uses the singular value decomposition [ABD+90]. For the iterative methods, LSQR is equivalent to applying the conjugate gradient method on the normal equations [PS82] and it is a robust and numerically stable method.
Randomized algorithms
To the best of our knowledge, most randomized algorithms proposed in the theoretical computer science literature for approximately solving least squares are mainly based on the following generic two step procedure: first randomly (and efficiently) project the linear system into sufficiently many dimensions, and second return the solution of the down-sampled linear system as an approximation to the original optimal solution [DMM06, Sar06, CW09, NDT09, MZ11, DMMS11], see also [CW12]. Concentration of measure arguments imply that the optimal solution of the down-sampled system is close to the optimal solution of the original system. The accuracy of the approximate solution using this approach depends on the sample size and to achieve relative accuracy , the sample size should depend inverse polynomially on . This makes these approaches unsuitable for the high-precision regime of error that is considered here.
A different approach is the so called randomized preconditioning method, see [RT08, AMT10]. The authors of [AMT10] implemented Blendenpik, a high-precision least squares solver. Blendenpik consists of two steps. In the first step, the input matrix is randomly projected and an effective preconditioning matrix is extracted from the projected matrix. In the second step, an iterative least squares solver such as the LSQR algorithm of Paige and Saunders [PS82] is applied on the preconditioned system. Blendenpik is effective for overdetermined and underdetermined problems.
A parallel iterative least squares solver based on normal random projections called LSRN was recently implemented by Meng, Saunders and Mahoney [MSM11]. LSRN consists of two phases. In the first preconditioning phase, the original system is projected using random normal projection from which a preconditioner is extracted. In the second step, an iterative method such as LSQR or the Chebyshev semi-iterative method [GV61] is applied on the preconditioned system. This approach is also effective for over-determined and under-determined least squares problems assuming the existence of a parallel computational environment.
1 Relation with our contribution
In Section 5, we compare the randomized extended Kaczmarz algorithm against DGELSY, DGELSD, Blendenpik. LSRN [MSM11] did not perform well under a setup in which no parallelization is allowed, so we do not include LSRN’s performance. The numerical evaluation of Section 5 indicates that the randomized extended Kaczmarz is effective on the case of sparse, well-conditioned and strongly rectangular (both overdetermined and underdetermined) least squares problems, see Figure 1. Moreover, the randomized extended Kaczmarz algorithm has also comparable performance with LAPACK’s routine for the dense random input matrices, see Figure 2 (notice that the proposed algorithm almost matches Blendenpik’s performance for the underdetermined case, see Figure 2(b)). On the other hand, a preconditioned version of the proposed algorithm does not perform well under the case of ill-conditioned matrices, see Figure 3.
Background
where for every and for every . The following fact will be used extensively in the paper.
1 Randomized Approximate Orthogonal Projection
Algorithm 1 is iterative. Initially, it starts with . At the -th iteration, the algorithm randomly selects a column of for some , and updates by projecting it onto the orthogonal complement of the space of . The claim is that randomly selecting the columns of with probability proportional to their square norms implies that the algorithm converges to in expectation. After iterations, the algorithm outputs and by orthogonality serves as an approximation for . The next theorem bounds the expected rate of convergence for Algorithm 1.
Moreover, each iteration of Algorithm 1 requires in expectation (over the random choices of the algorithm) at most arithmetic operations.
A suggestion for a stopping criterion for Algorithm 1 is to regularly check: for some given accuracy . It is easy to see that whenever this criterion is satisfied, it holds that , i.e., .
We devote the rest of this subsection to prove Theorem 2. Define for every . Observe that , i.e., is a projector matrix. Let be a random variable over that picks index with probability . It is clear that . Later we will make use of the following fact.
For every vector in the column space of , it holds .
Define for every . A direct calculation implies that
Indeed, using the definitions of , , and the fact that for any . Moreover, it is easy to see that for every is in the column space of , since , and in addition is a projector matrix for every .
Let be a sequence of independent and identically distributed random variables distributed as . For ease of notation, we denote by , i.e., the conditional expectation conditioned on the first iteration of the algorithm. It follows that
where we used linearity of expectation, the fact that is a projector matrix, Cauchy-Schwarz inequality and Fact 3. Repeating the same argument times we get that
Note that to conclude.
2 Randomized Kaczmarz
Strohmer and Vershynin proposed the following randomized variant of Kaczmarz algorithm (Algorithm 2), see [SV09] for more details. The following theorem is a restatement of the main result of [SV09] without imposing the full column rank assumption.
We devote the rest of this subsection to prove Theorem 4 following [SV09]. The proof is based on the following two elementary lemmas which both appeared in [SV09]. However, in our setting, the second lemma is not identical to that in [SV09]. We deferred their proofs to the Appendix.
Assume that has a solution and use the notation of Algorithm 2, then is perpendicular to for any . In particular, in exact arithmetic it holds that .
The above lemma provides a formula for the error at each iteration. Ideally, we seek to minimize the error at each iteration which is equivalent to maximizing over the choice of the row projections of the algorithm. The next lemma suggests that by randomly picking the rows of reduces the error in expectation.
Theorem 4 follows by iterating Lemma 6, we get that
3 Randomized Kaczmarz Applied to Noisy Linear Systems
The analysis of Strohmer and Vershynin is based on the restrictive assumption that the linear system has a solution. Needell made a step further and analyzed the more general setting in which the linear system does not have any solution and has full column rank [Nee10]. In this setting, it turns out that the randomized Kaczmarz algorithm computes an estimate vector that is within a fixed distance from the solution; the distance is proportional to the norm of the “noise vector” multiplied by [Nee10]. The following theorem is a restatement of the main result in [Nee10] with two modifications: the full column rank assumption on the input matrix is dropped and the additive term of Theorem in [Nee10] is improved to . The only technical difference here from [Nee10] is that the full column rank assumption is not necessary, so we defer the proof to the Appendix for completeness.
Randomized Extended Kaczmarz
In the present paper, the main observation is that it is possible to efficiently reduce the norm of the “noisy” part of , (using Algorithm 1) and then apply the randomized Kaczmarz algorithm on a new linear system whose right hand side vector is now arbitrarily close to the column space of , i.e., . This idea together with the observation that the least squares solution of the latter linear system is equal (in the limit) to the least squares solution of the original system (see Fact 1) implies a randomized algorithm for solving least squares.
Next we present the randomized extended Kaczmarz algorithm which is a specific combination of the randomized orthogonal projection algorithm together with the randomized Kaczmarz algorithm.
The stopping criterion of Step 8 was decided based on the following analysis. Assume that the termination criteria are met for some . Let for some (which holds by the definition of ). Then,
By re-arranging terms and using the second part of the termination criterion, it follows that . Now,
where we used the triangle inequality, the first part of the termination rule together with and the above discussion. Now, since , it follows that
Equation (6) demonstrates that the forward error of REK after termination is bounded.
2 Rate of convergence
The following theorem bounds the expected rate of convergence of Algorithm 3.
After iterations, in exact arithmetic, Algorithm 3 with input (possibly rank-deficient) and computes a vector such that
For the sake of notation, set and denote by , i.e., the conditional expectation with respect to the first iterations of Algorithm 3. Observe that Steps and are independent from Steps and of Algorithm 3, so Theorem 2 implies that for every
Fix a parameter . After the -th iteration of Algorithm 3, it follows from Theorem 7 (Inequality (5)) that
Indeed, the randomized Kaczmarz algorithm is executed with input and current estimate vector . Set and in Theorem 7 and recall that .
Now, averaging the above inequality over the random variables and using linearity of expectation, it holds that
Simplifying the right hand side using the fact that , it follows
Moreover, observe that for every
Now for any , similar considerations as Ineq. (8) implies that
To derive the last inequality, consider two cases. If is even, set , otherwise set . In both cases, . ∎
3 Theoretical bounds on time complexity
In this section, we discuss the running time complexity of the randomized extended Kaczmarz (Algorithm 3). Recall that REK is a Las-Vegas randomized algorithm, i.e., the algorithm always outputs an “approximately correct” least squares estimate (satisfying (6)) but its runnning time is a random variable. Given any fixed accuracy parameter and any fixed failure probability we bound the number of iterations required by the algorithm to terminate with probability at least .
Fix an accuracy parameter and failure probability . In exact arithmetic, Algorithm 3 terminates after at most
iterations with probability at least .
Denote for notational convenience. It suffices to prove that with probability at least the conditions of Step 8 of Algorithm 3 are met. Instead of proving this, we will show that:
With probability at least : .
With probability at least : .
Later we prove that Items (1) and (2) imply the Lemma. First we prove Item (1). By the definition of the algorithm,
the first equality follows since , the second inequality is Markov’s inequality, the third inequality follows by Theorem 2, and the last inequality since .
the first inequality is Markov’s inequality, the second inequality follows by Theorem 8, and the last inequality follows provided that
A union bound on the complement of the above two events (Item (1) and (2)) implies that both events happen with probability at least . Now we show that conditioning on Items (1) and (2), it follows that REK terminates after iterations, i.e.,
We start with the first condition. First, using triangle inequality and Item 2, it follows that
where the first inequality is triangle inequality, the second inequality follows by Item and , the third and forth inequality follows by Item and the fifth inequality holds by Inequality (11) and the last inequality follows since . The second condition follows since
the first equation follows by orthogonality, the second inequality assuming Item (2), the third inequality follows since , the forth inequality follows by (11) and the final inequality since . ∎
Lemma 9 bounds the number of iterations with probability at least , next we bound the total number of arithmetic operations in worst case (Eqn. (12)) and in expectation (Eqn. (13)). Let’s calculate the computational cost of REK in terms of floating-point operations (flops) per iteration. For the sake of simplicity, we ignore the additional (negligible) computational overhead required to perform the sampling operations (see Section 5 for more details) and checking for convergence.
Each iteration of Algorithm 3 requires four level-1 BLAS operations (two DDOT operations of size and , respectively, and two DAXPY operations of size and , respectively) and additional four flops. In total, flops per iteration.
Therefore by Lemma 9, with probability at least , REK requires at most
Exploiting the (possible) sparsity of , we first show that each iteration of Algorithm 3 requires at most operations in expectation. For simplicity of presentation, we assume that we have stored in compressed column sparse format and compressed row sparse format [BBC+87].
By the linearity of expectation and the definitions of and , the expected running time after iterations is at most . It holds that (recall that )
Hence by Lemma 9, with probability at least , the expected number of arithmetic operations of REK is at most
Implementation and Experimental Results
The proposed algorithm has been entirely implemented in C. We provide three implementation of Algorithm 3: REK-C, REK-BLAS and REK-BLAS-PRECOND. REK-C corresponds to a direct translation of Algorithm 3 to C code. REK-BLAS is an implementation of REK with two additional technical features. First, REK-BLAS uses level-1 BLAS routines for all operations of Algorithm 3 and secondly REK-BLAS additionally stores explicitly the transpose of for more efficiently memory access of both the rows and columns of using BLAS. REK-BLAS-PRECOND is an implementation of REK-BLAS that additionally supports upper triangular preconditioning; we used Blendenpik’s preconditioning code to ensure a fair comparison with Blendenpik (see Section 5.2). In the implementations of REK-C and REK-BLAS we check for convergence every iterations.
Moreover, all implementations include efficient code that handles sparse input matrices using the compressed column (and row) sparse matrix format [BBC+87].
The sampling operations of Algorithm 3 (Steps 4 and 5) are implemented using the so-called “alias method” for generating samples from any given discrete distribution [Wal77, Vos91]. The alias method, assuming access to a uniform random variable on .
2 Experimental Results
We report our experimental results in this section. We compared the randomized extended Kaczmarz (REK-C, REK-BLAS,REK-BLAS-PRECOND) algorithm to LAPACK’s DGELSY and DGELSD least squares solvers, Blendenpick Available at http://www.mathworks.com/matlabcentral/fileexchange/25241-blendenpik. Blendenpik’s default settings were used. (version 1.3, [AMT10]) and MATLAB’s backslash operator. LSRN [MSM11] did not perform well under a setup in which no parallelization is allowed as the one used here, so we do not include LSRN’s performance. DGELSY uses QR factorization with pivoting and DGELSD uses the singular value decomposition. We use MATLAB with version 7.9.0.529 (R2009b). In addition, we use MATLAB’s included BLAS and LAPACK packages and we call LAPACK’s functions from MATLAB using MATLAB’s CMEX technology which allows us to measure only LAPACK’s elapsed time. We should highlight that MATLAB is used as a scripting language and no MATLAB-related overheads have been taken under consideration. Blendenpik requires the FFTW library http://www.fftw.org/; we used FFTW-3.3.3. To match the accuracy of LAPACK’s direct solvers, we fixed in Algorithm 3 to be 10e-14. Moreover, during our experiments we ensured that the residual error of all the competing algorithms were about of the same order of magnitude.
We used a Pentium(R) Dual-Core E5300 (2.60GHz) equipped with 5GB of RAM and compiled our source code using GCC-4.7.2 under Linux operating system. All running times displayed below are measured using the ftime Linux system call by taking the average of the running time of 10 independent executions.
We experimented our algorithm under three different distributions of random input matrices (sparse, dense and ill-conditioned) under the setting of strongly rectangular settings of least squares instances. In all cases we normalized the column norms of the input matrices to unity and generate the right hand side vector having Gaussian entries of variance one.
We tested our algorithm in the overdetermined setting of random sparse matrices with and and density . We also tested REK-BLAS on the underdetermined case where and . In both cases, the density of the sparse matrices was set to (for even sparser matrices REK-BLAS performed even better compared to all other mentioned methods). To generate these sparse matrix ensembles, we used MATLAB’s sprandn function with variance one. The results are depicted in Figure 1. Both plots demonstrate that REK-BLAS is superior on both the underdetermined (Figure 1(b)) and overdetermined case (Figure 1(a)). It is interesting that REK-BLAS performs well in the underdetermined case.
Dense and well-conditioned least squares
In this scenario, we used random overdetermined dense matrices with much more rows than columns, i.e., we set and . We also tested REK-BLAS on the underdetermined case where and . We generated this set of matrices using MATLAB’s randn function with variance ten. We depicted the results in Figure 2(a). In the overdetermined case (Figure 2(a)), REK-BLAS is marginally superior compared to LAPACK’s routines whereas REK-C (as a naive implementation of Algorithm 3) is inferior. Blendepik is the winner in this case. Interestingly, REK-BLAS almost matches the performance of Blendenpik in the underdetermined case, see Figure 2(b).
Dense and ill-conditioned least squares
Finally, we tested all algorithms under a particular case of random ill-conditioned dense matrices with and . Namely, we used Higham’s randSVD function for generating these matrices [Hig89, Hig96]. More precisely, we set the condition number of these matrices to be ; set the top singular value to one and the rest to 10e-6. The results are displayed in Figure 3. Unfortunately, in the ill-conditioned setting REK-BLAS-PRECOND is inferior compared to LAPACK’s routines and Blendepik. We also verified the results of [AMT10] that Blendepik is superior compared to LAPACK’s least squares solvers in this setting.
Acknowledgements
We would like to thank the anonymous reviewers for their invaluable comments on an earlier draft of the present manuscript. The first author would like to thank Haim Avron for his technical support on several issues regarding Blendenpik and Philip A. Knight for sharing his unpublished manuscript [Kni96].
References
Appendix
We present the proof of known facts from previous works for completeness.
(of Lemma 5) It suffices to show that . For notational convenience, let for every . Assume that for some arbitrary . Then,
using the definition of , and the fact that since is a solution to . Now, by the definition of , . ∎
(of Lemma 6) In light of Lemma 5, it suffices to show that . By the definition of , it follows
By hypothesis, is in the row space of for any when is; in addition, the same is true for by the definition of pseudo-inverse [GL96]. Therefore, . ∎
(of Theorem 7) As in [Nee10], for any define the affine hyper-planes:
Assume for now that at the -th iteration of the randomized Kaczmarz algorithm applied on , the -th row is selected. Note that is the projection of on by the definition of the randomized Kaczmarz algorithm on input . Let us denote the projection of on by . The two affine hyper-planes are parallel with common normal , so is the projection of on and the minimum distance between and equals . In addition, since , therefore by orthogonality we get that
Since is the projection of onto (that is to say, is a randomized Kaczmarz step applied on input where the -th row is selected on the -th iteration) and is in the row space of , Lemma 6 tells us that
Note that for given selected row we have ; by the distribution of selecting the rows of we have that
Inequality (5) follows by taking expectation on both sides of Equation (14) and bounding its resulting right hand side using Equations (15) and (16). Applying Inequality (5) inductively, it follows that
where we used that is in the row space of . The latter sum is bounded above by . ∎