chisl_meth / Лаб 6 QR-алгоритм, метод итераций / chapter3
.pdf3.5. THE DOUBLE SHIFT QR ALGORITHM |
71 |
||||||
0.0000 |
|
-0.0000 |
-1.9412 |
3.0516 |
2.9596 |
-10.2714 |
|
0 |
|
0.0000 |
0.0000 |
-0.1632 |
3.8876 |
4.1329 |
|
0 |
|
0 |
|
0 |
0.0000 |
-0.0000 |
3.0000 |
7 |
5 |
1.7264e-02 |
-7.5016e-01 |
|
|
||
8 |
5 |
2.9578e-05 |
-8.0144e-01 |
|
|
||
9 |
5 |
5.0602e-11 |
-4.6559e+00 |
|
|
||
10 |
5 |
-1.3924e-20 |
-3.1230e+00 |
|
|
||
H(10) = |
|
|
|
|
|
|
|
5.0000 |
|
6.0000 |
-2.7603 |
1.3247 |
11.5569 |
-2.0920 |
|
-6.0000 |
|
5.0000 |
-10.7194 |
0.8314 |
11.8952 |
21.0142 |
|
-0.0000 |
|
-0.0000 |
3.5582 |
3.3765 |
5.9254 |
-8.5636 |
|
-0.0000 |
|
-0.0000 |
-3.1230 |
-1.5582 |
-10.0935 |
-6.3406 |
|
0 |
|
0 |
|
0 |
0.0000 |
4.0000 |
4.9224 |
0 |
|
0 |
|
0 |
0.0000 |
0 |
3.0000 |
11 |
4 |
1.0188e+00 |
-9.1705e-16 |
|
|
||
H(11) = |
|
|
|
|
|
|
|
5.0000 |
|
6.0000 |
-10.2530 |
4.2738 |
-14.9394 |
-19.2742 |
|
-6.0000 |
|
5.0000 |
-0.1954 |
1.2426 |
7.2023 |
-8.6299 |
|
-0.0000 |
|
-0.0000 |
2.2584 |
-5.4807 |
-10.0623 |
4.4380 |
|
0.0000 |
|
-0.0000 |
1.0188 |
-0.2584 |
-5.9782 |
-9.6872 |
|
0 |
|
0 |
|
0 |
0 |
4.0000 |
4.9224 |
0 |
|
0 |
|
0 |
0.0000 |
0 |
3.0000 |
3.5.2The complexity
We first estimate the complexity of a single step of the double step Hessenberg QR algorithm. The most expensive operations are the applications of the 3 × 3 Householder reflectors in steps 13 and 15 of Algorithm 3.5. Let us first count the flops for applying the Householder reflector to a 3-vector,
x := (I − 2uuT )x = x − u(2uT x).
The inner product uT x costs 5 flops, multiplying with 2 another one. The operation x := x − uγ, γ = 2uT x, cost 6 flops, altogether 12 flops.
In the k-th step of the loop there are n − k of these application from the left in step 13 and k +4 from the right in step 15. In this step there are thus about 12n+O(1) flops to be executed. As k is running from 1 to p − 3. We have about 12pn flops for this step. Since p runs from n down to about 2 we have 6n3 flops. If we assume that two steps are required per eigenvalue the flop count for Francis’ double step QR algorithm to compute all eigenvalues of a real Hessenberg matrix is 12n3. If also the eigenvector matrix is accumulated the two additional statements have to be inserted into Algorithm 3.5. After step 15 we have
1: Q1:n,k+1:k+3 := Q1:n,k+1:k+3P ;
and after step 23 we introduce
72 CHAPTER 3. THE QR ALGORITHM
1: Q1:n,p−1:p := Q1:n,p−1:pP ;
which costs another 12n3 flops.
We earlier gave the estimate of 6n3 flops for a Hessenberg QR step, see Algorithm 3.2. If the latter has to be spent in complex arithmetic then the single shift Hessenberg QR algorithm is more expensive than the double shift Hessenberg QR algorithm that is executed in real arithmetic.
Remember that the reduction to Hessenberg form costs 103 n3 flops without forming the transformation matrix and 143 n3 if this matrix is formed.
3.6The symmetric tridiagonal QR algorithm
The QR algorithm can be applied straight to Hermitian or symmetric matrices. By (3.1) we see that the QR algorithm generates a sequence {Ak} of symmetric matrices. Taking into account the symmetry, the performance of the algorithm can be improved considerably. Furthermore, from Theorem 2.14 we know that Hermitian matrices have a real spectrum. Therefore, we can restrict ourselves to single shifts.
3.6.1Reduction to tridiagonal form
The reduction of a full Hermitian matrix to Hessenberg form produces a Hermitian Hessenberg matrix, which (up to rounding errors) is a real symmetric tridiagonal matrix. Let us consider how to take into account symmetry. To that end let us consider the first reduction step that introduces n − 2 zeros into the first column (and the first row) of A = A Cn×n. Let
P1 |
= |
0 In−1 |
− 2u1u1 |
, u1 Cn, ku1k = 1. |
|
|
1 |
0T |
|
Then,
A |
1 |
:= P AP |
1 |
= (I |
− |
2u |
u )A(I |
− |
2u |
u ) |
|||||||
|
1 |
|
|
1 |
|
1 |
|
|
1 |
1 |
|
|
|||||
|
|
|
|
= A |
− |
u |
(2u A |
− |
2(u Au |
)u ) |
|||||||
|
|
|
|
|
1 |
| |
1 |
|
|
|
1 |
1 |
1 |
||||
|
|
|
|
|
|
|
|
|
|
{z |
|
|
|
} |
v1 = A − u1v1 − v1u1.
In the k-th step of the reduction we similarly have
− (2Au1 − 2u1(u Au1)) u
| {z 1 } 1 v1
Ak = Pk Ak−1Pk = Ak−1 − uk−1vk−1 − vk−1uk−1,
where the last n − k elements of uk−1 and vk−1 are nonzero. Forming
vk−1 = 2Ak−1uk−1 − 2uk−1(uk−1Ak−1uk−1)
costs 2(n − k)2 + O(n − k) flops. This complexity results from Ak−1uk−1. The rank-2
update of Ak−1,
Ak = Ak−1 − uk−1vk−1 − vk−1uk−1,
requires another 2(n−k)2 +O(n−k) flops, taking into account symmetry. By consequence, the transformation to tridiagonal form can be accomplished in
nX−1 4(n − k)2 + O(n − k) = 43n3 + O(n2)
k=1
3.6. THE SYMMETRIC TRIDIAGONAL QR ALGORITHM |
73 |
floating point operations.
3.6.2The tridiagonal QR algorithm
In the symmetric case the Hessenberg QR algorithm becomes a tridiagonal QR algorithm. This can be executed in an explicit or an implicit way. In the explicit form, a QR step is essentially
1:Choose a shift µ
2:Compute the QR factorization A − µI = QR
3:Update A by A = RQ + µI.
Of course, this is done by means of plane rotations and by respecting the symmetric tridiagonal structure of A.
In the more elegant implicit form of the algorithm we first compute the first Givens rotation G0 = G(1, 2, ϑ) of the QR factorization that zeros the (2, 1) element of A − µI,
|
−s |
c |
a21 |
0 |
(3.11) |
c |
s |
a11 − µ |
= , c = cos(ϑ0), s = sin(ϑ0). |
Performing a similary transformation with G0 we have (n = 5)
|
|
× |
× |
× |
|
G0AG0 |
= A′ = |
× |
× |
+ |
|
+ × × × |
|||||
|
|
|
|
× × |
|
|
|
|
|
× |
|
|
|
|
|
|
|
|
|
|
|
× |
× |
Similar as with the double step Hessenberg QR algorithm we chase the bulge down the diagonal. In the 5 × 5 example this becomes
|
G0 |
× × × |
|
|
G1 |
× × × + |
|
|||||||
|
−−=−G−−(1−,−2−,−ϑ−0→) |
|
× |
× |
+ |
|
|
−−=−G−−(2−,−3−,−ϑ−1→) |
|
× |
× |
0 |
|
|
|
|
|
|
|
|
+ |
|
|
||||||
|
|
|
|
|
× |
× |
|
|
|
|
|
× |
× |
|
A |
|
|
+ |
× |
× |
|
|
0 |
× |
× |
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
× |
× |
|
|
|
|
|
× |
× |
G2 |
× × × |
|
|
|
G3 |
× × × |
|
|
|
|
|
|
|||||
−−=−G−−(3−,−4−,−ϑ−2→) |
× |
× |
0 |
|
|
|
−−=−G−−(4−,−5−,−ϑ−3→) |
× |
× |
|
|
|
|
|
|
||
|
0 |
|
|
|
|
× × × |
|
|
|
|
|||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
||
|
|
× |
× |
× |
× |
|
|
× × |
× |
|
|
|
|||||
|
|
× |
× |
+ |
|
|
|
0 |
|
0 |
|
= A. |
|||||
|
|
+ |
|
|
|
|
|
|
|
|
|||||||
The full step is given by |
|
|
|
× |
× |
|
|
|
× |
× |
|
|
|
||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
= Q AQ, |
|
Q = G0 G1 · · · Gn−2. |
|
|
|
|
|
|
|
|||||
|
|
A |
|
|
|
|
|
|
|
|
Because Gke1 = e1 for k > 0 we have
Q e1 = G0 G1 · · · Gn−2 e1 = G0 e1.
Both explicit and implicit QR step form the same first plane rotation G0. By referring to the Implicit Q Theorem 3.5 we see that explicit and implicit QR step compute essentially the same A.
74 |
CHAPTER 3. THE QR ALGORITHM |
Algorithm 3.6 Symmetric tridiagonal QR algorithm with implicit Wilkinson shift
1:Let T Rn×n be a symmetric tridiagonal matrix with diagonal entries a1, . . . , an and o -diagonal entries b2, . . . , bn.
This algorithm computes the eigenvalues λ1, . . . , λn of T and corresponding eigenvectors q1, . . . , qn. The eigenvalues are stored in a1, . . . , an. The eigenvectors are stored in the matrix Q, such that T Q = Q diag(a1, . . . , an).
2:m = n /* Actual problem dimension. m is reduced in the convergence check. */
3:while m > 1 do
4:d := (am−1 − am)/2; /* Compute Wilkinson’s shift */
5:if d = 0 then
6:s := am − |bm|;
7: |
else |
||
|
s := am − bm2 /(d + sign(d)p |
|
); |
8: |
d2 + bm2 |
9:end if
10:x := a(1) − s; /* Implicit QR step begins here */
11:y := b(2);
12:for k = 1 to m − 1 do
13:if m > 2 then
14:[c, s] := givens(x, y);
15: |
else |
s c |
b2 |
a2 |
|
|
|
||||
16: |
Determine [c, s] such that c |
−s |
a1 |
b2 |
c s
−s c is diagonal
17:end if
18:w := cx − sy;
19:d := ak − ak+1; z := (2cbk+1 + ds)s;
20:ak := ak − z; ak+1 := ak+1 + z;
21:bk+1 := dcs + (c2 − s2)bk+1;
22:x := bk+1;
23:if k > 1 then
24:bk := w;
25:end if
26:if k < m − 1 then
27: |
y := −sbk+2; bk+2 := cbk+2; |
||
28: |
end if |
c |
s |
|
|
||
29: |
Q1:n;k:k+1 := Q1:n;k:k+1 |
−s |
c ; |
30:end for/* Implicit QR step ends here */
31:if |bm| < ε(|am−1| + |am|) then /* Check for convergence */
32:m := m − 1;
33:end if
34:end while
3.7. RESEARCH |
75 |
Algorithm 3.6 shows the implicit symmetric tridiagonal QR algorithm. The shifts are chosen acording to Wilkinson. An issue not treated in this algorithm is deflation. Deflation is of big practical importance. Let us consider the following 6 × 6 situation
|
b2 |
a2 |
b3 |
|
|
|
|
|
|
|
a1 |
b2 |
|
|
|
|
|
|
. |
T = |
|
b3 |
03 |
a |
4 |
b |
5 |
|
|
|
|
|
|
|
|
|
|
||
|
|
|
a |
0 |
|
|
|
|
|
|
|
|
|
b5 |
a5 |
b6 |
|
||
|
|
|
|
|
|
b6 |
a6 |
|
|
|
|
|
|
|
|
|
|||
|
|
|
|
|
|
|
|
|
|
The shift for the next step is determined from elements a5, a6, and b6. According to (3.11) the first plane rotation is determined from the shift and the elements a1 and b1. The implicit shift algorithm then chases the bulge down the diagonal. In this particular situation, the procedure finishes already in row/column 4 because b4 = 0. Thus the shift which is an approximation to an eigenvalue of the second block (rows 4 to 6) is applied to the wrong first block (rows 1 to 3). Clearly, this shift does not improve convergence.
If the QR algorithm is applied in its direct form, then still the first block is not treated properly, i.e. with a (probably) wrong shift, but at least the second block is diagonalized rapidly.
Deflation is done as indicated in Algorithm 3.6: If
if |bk| < ε(|ak−1| + |ak|) then deflate.
Deflation is particularly simple in the symetric case since it just means that a tridiagonal eigenvalue problem decouples in two (or more) smaller tridiagonal eigenvalue problems. Notice, however, that the eigenvectors are still n elements long.
3.7Research
Still today the QR algorithm computes the Schur form of a matrix and is by far the most popular approach for solving dense nonsymmetric eigenvalue problems. Multishift and aggressive early deflation techniques have led to significantly more e cient sequential implementations of the QR algorithm during the last decade. For a brief survey and a discussion of the parallelization of the QR algorithm, see [6].
3.8Summary
The QR algorithm is a very powerful algorithm to stably compute the eigenvalues and (if needed) the corresponding eigenvectors or Schur vectors. All steps of the algorithm cost O(n3) floating point operations, see Table 3.1. The one exception is the case where only eigenvalues are desired of a symmetric tridiagonal matrix. The linear algebra software package LAPACK [1] contains subroutines for all possible ways the QR algorithm may be employed.
We finish by repeating, that the QR algorithm is a method for dense matrix problems. The reduction of a sparse matrix to tridiagonal or Hessenberg form produces fill-in, thus destroying the sparsity structure which one almost always tries to preserve.
76 |
CHAPTER 3. |
THE QR ALGORITHM |
||||
|
|
|
|
|
||
|
|
|
nonsymmetric case |
symmetric case |
||
|
|
|
without |
with |
without |
with |
|
|
|
Schurvectors |
eigenvectors |
||
|
|
|
|
|
|
|
|
transformation to Hessenberg/tridiagonal form |
|
10 n3 |
14 n3 |
4 n3 |
8 n3 |
|
|
|
3 |
3 |
3 |
3 |
|
|
|
|
|
|
|
|
real double step Hessenberg/tridiagonal QR al- |
|
20 n3 |
50 n3 |
24n2 |
6n3 |
|
gorithm (2 steps per eigenvalues assumed) |
|
3 |
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
total |
|
10n3 |
25n3 |
4 n3 |
9n3 |
|
|
|
|
|
3 |
|
|
|
|
|
|
|
|
Table 3.1: Complexity in flops to compute eigenvalues and eigenvectors/Schur vectors of a real n × n matrix
Bibliography
[1]E. ANDERSON, Z. BAI, C. BISCHOF, J. DEMMEL, J. DONGARRA, J. D. CROZ, A. GREENBAUM, S. HAMMARLING, A. MCKENNEY, S. OSTROUCHOV,
AND D. SORENSEN, LAPACK Users’ Guide – Release 2.0, SIAM, |
Philadel- |
|
phia, PA, 1994. |
(Software and guide are available from Netlib |
at URL |
http://www.netlib.org/lapack/). |
|
[2]P. ARBENZ AND G. H. GOLUB, Matrix shapes invariant under the symmetric QR algorithm, Numer. Linear Algebra Appl., 2 (1995), pp. 87–93.
[3]J. W. DEMMEL, Applied Numerical Linear Algebra, SIAM, Philadelphia, PA, 1997.
[4]J. G. F. FRANCIS, The QR transformation – Parts 1 and 2, Computer J., 4 (1961– 1962), pp. 265–271 and 332–345.
[5]G. H. GOLUB AND C. F. VAN LOAN, Matrix Computations, The Johns Hopkins University Press, Baltimore, MD, 2nd ed., 1989.
[6]B. K˚AGSTROM¨ , D. KRESSNER, AND M. SHAO, On aggressive early deflation in parallel variants of the QR algorithm, in Applied Parallel and Scientific Computing (PARA 2010), K. J´onasson, ed., Heidelberg, 2012, Springer, pp. 1–10. (Lecture Notes in Computer Science, 7133).
[7]B. N. PARLETT, The QR algorithm, Computing Sci. Eng., 2 (2000), pp. 38–42.
[8]H. RUTISHAUSER, Solution of eigenvalue problems with the LR-transformation, NBS Appl. Math. Series, 49 (1958), pp. 47–81.
[9]J. H. WILKINSON, The Algebraic Eigenvalue Problem, Clarendon Press, Oxford, 1965.