Professional Documents
Culture Documents
Algorithm 583 LSQR: Sparse Linear Equations and Least Squares Problems
Algorithm 583 LSQR: Sparse Linear Equations and Least Squares Problems
Categories and Subject Descriptors: G.1.3 [Numerical Analysis] Numerical Linear Algebra--linear
systems (dtrect and tterattve methods), G.3 [Mathematics of Computing]: Probability and Statis-
tms--statzshcal computtng, stattsttcal software, G.m [Mathematics of Computing]: Miscella-
n e o u s - - F O R T R A N program untts
General Terms Algorithms
Additional Key Words and Phrases: Analysis of variance, conjugate-gradient method, least squares,
linear equatmns, regression, sparse matrix
1. INTRODUCTION
L S Q R finds a solution x to the following problems:
U n s y m m e t r i c equations: solve Ax = b (1.1)
Linear least squares: minimize [[A x - b [[2 (1.2)
essential function is to compute products of the form A x and AWy for given
vectors x and y.
Problems (1.1) and (1.2) are t r e a t e d as special cases of (1.3), which we shall
write as
2. MATHEMATICAL BACKGROUND
Algorithmic details are given in [6], mainly for the case ~ = 0. We summarize
these here with ~ reintroduced, and show t h a t a given value of :k m a y be dealt
with at negligible cost. T h e vector n o r m I] v ]]2 = (vTv) 1/2 is used throughout.
ACM Transactions on Mathematical Software, Vol. 8, No. 2, June 1982
Algorithms • 197
(XI
~2 O~2
fi3 "
U k + l ~ [UI~ U2~ - - . ~ Uk+l]~ (2.1)
B k ~--
V k + l = [Vl, V2, • • . , Vk+l],
~k+l
(2.2)
tk+l = file1 - B k y k
rk = b - A x k (2.3)
rk = Uk+ltk+l (2.4)
AWrk = h2Xk + Olk+lgk+lVk+l
will hold to machine accuracy, where rk+~ is the last component of tk+~, and we
therefore conclude t h a t (rk, xD will be an acceptable solution of (1.4) if the
computed value of either IIth+l II or I ak+lVk+l I is suitably small.
Bjorck [1] has previously observed t h a t subproblem (2.2) is the appropriate
generalization of minll B k y k -- fl~el II, when X ~ 0. He also discusses methods for
computing yk and xk efficiently for various ~ and k.
In L S Q R we assume t h a t a single value of )~ is given, and to save storage and
work, we do not compute yk, rk, or tk+~. The orthogonal factorization
(2.5)
qk J
proceeds according to
pl
2 0/2 ~2 O/2 j~2 ~2
X
I pl 8= 61] p~ e2
p2 62
-'* f13
Note that the first ~ is rotated into the diagonal element a~. This alters the right-
hand side fl~e~ to produce ~1, the first component of qk. An alternative is to rotate
into f12 (and similarly for later h), since this does not affect the right-hand side
and it more closely simulates the algorithm that results when LSQR is applied to
and 5 directly. However, the rotations then have a greater effect on Bk, and in
practice the first option has proved to give marginally more accurate results.
The estimates required to implement the stopping criteria are
II kU = = Ilrkll 2 + X=llxkll = = + Ilqkll =,
4. CODING APROD
The best way to compute y + Ax and x + ATy depends upon the origin of the
matrix A. We shall illustrate a case that commonly arises, in which A is a sparse
matrix whose nonzero coefficients are stored by rows in a simple list. Let A have
ACM Transactions on Mathematmal Software, Voi. 8, No. 2, June 1982
Algorithms • 199
5. PRECONDITIONING
INTEGER MODE,M,N,LENIW,LENRW
INTEGER IW(LENIW)
REAL X(N) ,Y(M), RW(LENRW)
REAL RA
INTEGER JA, NA
COMMON RA(9000), JA(9000), NA(I000)
INTEGER I,J,L,LI,L2
REAL SUM, YI, ZERO
ZERO - 0.0
L2 - 0
IF (MODE .NE.I) GO TO 400
Fig. 1. Computation ofy + Ax,
x + Ary, where A is a sparse
matrix stored compactly by MODE - 1 -- SET Y = Y + A*X.
rows. For convenience, the
data structure for A is held in DO 200 I - I, M
COMMON. SUM - ZERO
L1 " L2 + 1
L2 " L2 + NA(I)
DO 100 L " LI, L2
J .. JA(L)
SUM - SUM + RA(L)*X(J)
I00 CONTINUE
Y(1) = Y(1) + SUM
200 CONTINUE
RETURN
END OF APROD
END
A C M Transactionson MathematicalSoftware,Vol 8,~No. 2,June 1982.
Algorithms . 201
INTEGER MODE,M,N,LENIW,LENRW
INTEGER IW(LENIW)
REAL X(N),Y(M),RW(LENRW)
INTEGER LENJA,LENRA,LOCJA
LOCJA ffi M + I
LENJA ffi LENIW - LOCJA + 1
LENRA ffi LENRW Fig. 2 S a m e as Figure 1, with
CALL A P R O D I ( M O D E , M , N , X , Y ) the data structure for A held
* LENJA,LENRA,IW,IW(LOCJA),RW ) in the workspace parameters.
RETURN
END OF APROD
END
INTEGER MODE,M,N,LENJA,LENRA
INTEGER NA(M),JA(LENJA)
REAL X(N),Y(M),RA(LENRA)
INTEGER I,J,L,LI,L2
REAL SUM,YI,ZERO
END OF APRODI
END
0 ~ ~ ~ ~
0 ~ 0 0 ~ ~
,-10 000
II 0 I
U r.r-1 ~.4 0
0'3 I 0 0 I~ I I I I I I I 1 1 1 1 I I I
0 r..r..1 •K O0 0
I 0
0
0 0
0
0 II II II
0
I I I I I I I I I I I l l
I| ~ 0 ~ ~ 0 ~ ~
°
Q
o
0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
! I I I I I
0 O Q O
o,I
0 O O 0 0 0 Q O O O Q Q Q O
Q O O O O O O Q O 0 O 0 0
~'~ 0
II I1
0
0
~ 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
I I I I I
0
0 O O O O O 0 0 0 0 0 Q O 0
0 Q O O O O O Q O O 0 O O Q
0 O O 0 0 0 0 0 0 0 0 O O 0
II •-,-i 0
~ ~ 0 0 ~ ~
Z
0
| 1 1
I
0
r~ 0
0
I
v
000
O~ ~'~1
0 0~-~"
0 0 O0
I
~2
O0
I I 0
0
v
000
0
000
I.-.I CO
u'l
¢0,-~
O0
-I¢ I I
000
v aOu'~
0
00u'~
0
0 OC)
Z
0
0 c.,I r'~ txl r.-.
~cO00
0 u~ ,.-4
C~
r~
°
00oh
Z
o
Z
0
204 • Algorithms
6. OUTPUT
S u b r o u t i n e L S Q R produces printed o u t p u t on file N O U T , if the p a r a m e t e r
N O U T is positive. T h i s is illustrated in Figure 3, in which the least squares
p r o b l e m solved is P(20, 10, 1, 1) as defined in [6], with a slight generalization to
include a d a m p i n g p a r a m e t e r )~ = 10 -2. (Single precision was used on an I B M
370/168.) T h e items printed~at the k t h iteration are as follows.
ITN T h e iteration n u m b e r k. Results are always printed for the
first 10 a n d last 10 iterations. I n t e r m e d i a t e results are
printed if m _< 40 or n ___ 40, or if one of the convergence
conditions is nearly satisfied. Otherwise, i n f o r m a t i o n is
printed e v e r y 10th iteration.
X(1) T h e value of the first e l e m e n t of the a p p r o x i m a t e solution
Xk.
FUNCTION T h e value of the function being minimized, n a m e l y [] Fk [I --
(11 rk II2 + x 2 II x, 112)'/2
COMPATIBLE A dimensionless q u a n t i t y which should converge to zero if
a n d only i f A x = b is compatible. I t is a n e s t i m a t e of II ~k II/
II b II, which decreases monotonically.
INCOMPATIBLE A dimensionless q u a n t i t y which should converge to zero if
a n d only i f the o p t i m u m II ~k II is nonzero. I t is a n e s t i m a t e
of IIii T ~ II/(11 ti IIwII Fk II), which is usually not monotonic.
NORM(ABAR) A m o n o t o n i c a l l y increasing e s t i m a t e of IILi II~.
COND(ABAR) A monotonically increasing e s t i m a t e of cond(z~) =
IIA IIr II/i+ IIr, the condition n u m b e r of z{.
ACKNOWLEDGMENT
T h e a u t h o r s are grateful to R i c h a r d H a n s o n for suggestions t h a t p r o m p t e d
several i m p r o v e m e n t s to the i m p l e m e n t a t i o n of L S Q R .
REFERENCES
1. BJORCK, A. A bidlagonahzation algorithm for solving ill-posed systems of linear equatmns Rep
LITH-MAT-R-80-33, Dep. Mathematics, Linkopmg Univ., Lmkoping, Sweden, 1980.
2 ELDI~,N, L. Algorithms for the regularization of ill-conditioned least squares problems BIT 17
(1977), 134-145.
3. HESTENES, M.R, AND STIEFEL, E Methods of conjugate gradients for solving hnear systems. J
Res. N.B.S. 49 (1952), 409-436.
4 LAWSON,C.L, AND HANSON, R.J Solvmg Least Squares Problems. Prentice-Hail, Englewood
Cliffs, N.J., 1974.
5 LAWSON, C . L , HANSON, R J., KINCA1D, D.R, ANDKROGH,F T Basic hnear algebra subprograms
for Fortran usage ACM Trans Math Softw 5, 3 (Sept 1979), 308-323 and (Algorithm} 324-325.
6. PAIGE, C.C., AND SAUNDERS, M A LSQR An algorithm for sparse linear equations and sparse
least squares ACM Trans Math Softw 8, 1 (March 1982), 43-71
ACM TransacUons on Mathematical Software, Vol 8, No. 2, June 1982
Algorithms • 205
7. SMITH, G., AND CAMPBELL, F. A critique of some ridge regression methods. J. Am. Star. Assoc.
75, 369 (March 1980), 74-81
8 VARAH, J.M A practical examination of some numerical methods for linear discrete ill-posed
problems S I A M Rev. 21 (1979), 100-111.
9. WOLD, S, WOLD, H., DUNN, W.J., AND RUHE, A. The collinearity problem in linear and
nonlinear regression. The partial least squares (PLS) approach to generalized inverses. Rep.
UMINF-83.80, Univ. Ume~, Ume&, Sweden, 1980.
ALGORITHM
[ A p a r t o f t h e l i s t i n g is p r i n t e d h e r e . T h e c o m p l e t e l i s t i n g is a v a i l a b l e f r o m t h e
A C M A l g o r i t h m s D i s t r i b u t i o n S e r v i c e (see p a g e 227 for o r d e r f o r m ) . ]
~~ ; ~ L ~ I ~ •
208 • Algorithms
C 166.
C NORMALLY, CONLIM SHOULD BE IN THE RANGE 167.
C 1~ TO 1/REAR. 168.
C SUGGESTED VALb~ -- 169.
C CONLIM = 1/(100*RELPR) FOR COMPATIBLE SYSTEMS, 170.
C CONLIM - I/(10*SQRT(RELPR)) FOR LEAST SQUARES. 171.
C 172,
C NOTE. IF THE USER IS NOT CONCERNED ABOUT THE PARAMETERS 173.
C ATOL, BTOL AND CONLIM, ANY OR ALL OF THEM MAY BE SET 174.
C TO ZERO. THE EFFECT WILL BE THE SAME AS THE VALUES 175.
C RELPR, RELPR AND I/KELPR RESPECTIVELY. 176.
C 177.
C ITNLIM INPUT AN UPPER LIMIT ON THE NUMBER OF ITERATIONS. 178.
C SUGGESTED VALUE -- 179.
C ITNLIM " N/2 FOR WELL CONDITIONED SYSTEMS, 180.
C ITNLIM - 4*N OTHERWISE. 181.
C 182.
C NOUT INPUT FILE NUMBER FOR PRINTER. IF POSITIVE, 183.
C A SUMMARY WILL BE PRINTED ON FILE NOUT. 184.
C 185.
C ISTOP OUTPUT AN INTEGER GIVING THE REASON FOR TERMINATION... 186.
C 187.
C 0 X " 0 IS THE EXACT SOLUTION. 188.
C NO ITERATIONS WERE PERFORMED. 189.
C 190.
C 1 THE EQUATIONS A*X - B ARE PROBABLY 191.
C COMPATIBLE. NORM(A*X - B) IS SUFFICIENTLY 192.
C SMALL, GIVEN THE VALUES OF ATOL AND BTOL. 193 •
C 194.
C 2 THE SYSTEM A*X = B IS PROBABLY NOT 195.
C COMPATIBLE. A LEAST-SQUARES SOLUTION HAS 196.
C BEEN OBTAINED WHICH IS SUFFICIENTLY ACCURATE, 197.
C GIVEN THE VALUE OF ATOL. 198 •
C 199.
C 3 AN ESTIMATE OF COND(ABAR) HAS EXCEEDED 200.
C CONLIM. THE SYSTEM A*X - B APPEARS TO BE 2~1.
C ILL-CONDITIONED. OTHERWISE, THERE COULD BE AN 202.
C AN ERROR IN SUBROUTINE APROD. 203.
C 204.
C 4 THE EQUATIONS A*X - B ARE PROBABLY 205.
C COMPATIBLE. NORM(A*X - B) IS AS SMALL AS 206.
C SEEMS REASONABLE ON THIS MACHINE. 207.
C 208.
C 5 THE SYSTEM A*X - B IS PROBABLY NOT 209.
C COMPATIBLE. A LEAST-SQUARES SOLUTION HAS 21~.
C BEEN OBTAINED WHICH IS AS ACCURATE AS SEEMS 211.
C REASONABLE ON THIS MACHINE. 212.
C 213.
C 6 COND(ABAR) SEEMS TO BE SO LARGE THAT THERE IS 214.
C NOT MUCH POINT IN DOING FURTHER ITERATIONS, 215.
C GIVEN THE PRECISION OF THIS MACHINE. 216.
C THERE COULD BE AN ERROR IN SUBROUTINE APROD. 217.
C 218.
C 7 THE ITERATION LIMIT ITNLLM WAS REACHED. 219.
C 220.
C ANORM OUTPUT AN ESTIMATE OF THE FROBENIUS NORM OF ABAE. 221.
C THIS IS THE SQUARE-ROOT OF THE SUM OF SQUARES 222.
C OF THE ELEMENTS OF ABAR. 223.
C IF DAMP IS SMALL AND IF THE COLUMNS OF A 224.
C RAVE ALL BEEN SCALED TO HAVE LENGTH 1.0, 225.
C ANORM SHOULD INCREASE TO ROUGHLY SQRT(N). 226.
ACM Transactions on Mathematical Software, Vol. 8, No. 2, June 1982.
Algorithms • 200