Puneet Varma (Editor)

Jacobi eigenvalue algorithm

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit

In numerical linear algebra, the Jacobi eigenvalue algorithm is an iterative method for the calculation of the eigenvalues and eigenvectors of a real symmetric matrix (a process known as diagonalization). It is named after Carl Gustav Jacob Jacobi, who first proposed the method in 1846, but only became widely used in the 1950s with the advent of computers.

Contents

Description

Let S be a symmetric matrix, and G = G ( i , j , θ ) be a Givens rotation matrix. Then:

S = G S G

is symmetric and similar to S .

Furthermore, S has entries:

S i i = c 2 S i i 2 s c S i j + s 2 S j j S j j = s 2 S i i + 2 s c S i j + c 2 S j j S i j = S j i = ( c 2 s 2 ) S i j + s c ( S i i S j j ) S i k = S k i = c S i k s S j k k i , j S j k = S k j = s S i k + c S j k k i , j S k l = S k l k , l i , j

where s = sin ( θ ) and c = cos ( θ ) .

Since G is orthogonal, S and S have the same Frobenius norm | | | | F (the square-root sum of squares of all components), however we can choose θ such that S i j = 0 , in which case S has a larger sum of squares on the diagonal:

S i j = cos ( 2 θ ) S i j + 1 2 sin ( 2 θ ) ( S i i S j j )

Set this equal to 0, and rearrange:

tan ( 2 θ ) = 2 S i j S j j S i i

if S j j = S i i

θ = π 4

In order to optimize this effect, Sij should be the off-diagonal element with the largest absolute value, called the pivot.

The Jacobi eigenvalue method repeatedly performs rotations until the matrix becomes almost diagonal. Then the elements in the diagonal are approximations of the (real) eigenvalues of S.

Convergence

If p = S k l is a pivot element, then by definition | S i j | | p | for 1 i , j n , i j . Since S has exactly 2 N := n ( n - 1) off-diag elements, we have p 2 Γ ( S ) 2 2 N p 2 or 2 p 2 Γ ( S ) 2 / N . This implies Γ ( S J ) 2 ( 1 1 / N ) Γ ( S ) 2 or Γ ( S J ) ( 1 1 / N ) 1 / 2 Γ ( S ) , i.e. the sequence of Jacobi rotations converges at least linearly by a factor ( 1 1 / N ) 1 / 2 to a diagonal matrix.

A number of N Jacobi rotations is called a sweep; let S σ denote the result. The previous estimate yields

Γ ( S σ ) ( 1 1 / N ) N / 2 Γ ( S ) ,

i.e. the sequence of sweeps converges at least linearly with a factor ≈ e 1 / 2 .

However the following result of Schönhage yields locally quadratic convergence. To this end let S have m distinct eigenvalues λ 1 , . . . , λ m with multiplicities ν 1 , . . . , ν m and let d > 0 be the smallest distance of two different eigenvalues. Let us call a number of

N S := 1 2 n ( n 1 ) μ = 1 m 1 2 ν μ ( ν μ 1 ) N

Jacobi rotations a Schönhage-sweep. If S s denotes the result then

Γ ( S s ) n 2 1 γ 2 d 2 γ , γ := Γ ( S ) .

Thus convergence becomes quadratic as soon as Γ ( S ) < d / ( 2 + n 2 1 )

Cost

Each Jacobi rotation can be done in n steps when the pivot element p is known. However the search for p requires inspection of all N ≈ ½ n2 off-diagonal elements. We can reduce this to n steps too if we introduce an additional index array m 1 , , m n 1 with the property that m i is the index of the largest element in row i, (i = 1, …, n − 1) of the current S. Then (k, l) must be one of the pairs ( i , m i ) . Since only columns k and l change, only m k and m l must be updated, which again can be done in n steps. Thus each rotation has O(n) cost and one sweep has O(n3) cost which is equivalent to one matrix multiplication. Additionally the m i must be initialized before the process starts, this can be done in n2 steps.

(Problem with the above proposed O(n) algorithm: Jacobi rotations affect both columns k and l, AND rows k and l. So the O(n) scheme described above doesn't necessarily in fact find the pivot element corresponding to the largest off-diagonal element after a Jacobi rotation. You also have to check that the updates to rows k and l (for all other columns on the upper or lower triangular part of the matrix) don't also change the corresponding m i , for i not equal to k or l. In general, these will be altered by the rotation. In worst case the correct update is O(n2). )

Typically the Jacobi method converges within numerical precision after a small number of sweeps. Note that multiple eigenvalues reduce the number of iterations since N S < N .

(Note: Sweeps refer to cyclic Jacobi, not discussed in this article, where the pivot choice simply cycles over all upper (or lower) off-diagonal elements, not classic Jacobi which searches for the maximum (magnitude) off-diagonal element as the pivot.)

Algorithm

The following algorithm is a description of the Jacobi method in math-like notation. It calculates a vector e which contains the eigenvalues and a matrix E which contains the corresponding eigenvectors, i.e. e i is an eigenvalue and the column E i an orthonormal eigenvector for e i , i = 1, …, n.

procedure jacobi(SRn×n; out eRn; out ERn×n) var i, k, l, m, stateN s, c, t, p, y, d, rR indNn changedLn function maxind(kN) ∈ N ! index of largest off-diagonal element in row k m := k+1 for i := k+2 to n do ifSki│ > │Skmthen m := i endif endfor return m endfunc procedure update(kN; tR) ! update ek and its status y := ek; ek := y+t if changedk and (y=ek) then changedk := false; state := state−1 elsif (not changedk) and (yek) then changedk := true; state := state+1 endif endproc procedure rotate(k,l,i,jN) ! perform rotation of Sij, Skl ┐ ┌ ┐┌ ┐ │Skl│ │cs││Skl│ │ │ := │ ││ │ │Sij│ │s c││Sij│ └ ┘ └ ┘└ endproc ! init e, E, and arrays ind, changed E := I; state := n for k := 1 to n do indk := maxind(k); ek := Skk; changedk := true endfor while state≠0 do ! next rotation m := 1 ! find index (k,l) of pivot p for k := 2 to n−1 do ifSk indk│ > │Sm indmthen m := k endif endfor k := m; l := indm; p := Skl ! calculate c = cos φ, s = sin φ y := (elek)/2; d := │y│+√(p2+y2) r := √(p2+d2); c := d/r; s := p/r; t := p2/d if y<0 then s := −s; t := −t endif Skl := 0.0; update(k,−t); update(l,t) ! rotate rows and columns k and l for i := 1 to k−1 do rotate(i,k,i,l) endfor for i := k+1 to l−1 do rotate(k,i,i,l) endfor for i := l+1 to n do rotate(k,i,l,i) endfor ! rotate eigenvectors for i := 1 to n do ┐ ┌ ┐┌ ┐ │Eik│ │cs││Eik│ │ │ := │ ││ │ │Eil│ │s c││Eil│ └ ┘ └ ┘└ endfor ! rows k, l have changed, update rows indk, indl indk := maxind(k); indl := maxind(l) loop endproc

Notes

1. The logical array changed holds the status of each eigenvalue. If the numerical value of e k or e l changes during an iteration, the corresponding component of changed is set to true, otherwise to false. The integer state counts the number of components of changed which have the value true. Iteration stops as soon as state = 0. This means that none of the approximations e 1 , . . . , e n has recently changed its value and thus it is not very likely that this will happen if iteration continues. Here it is assumed that floating point operations are optimally rounded to the nearest floating point number.

2. The upper triangle of the matrix S is destroyed while the lower triangle and the diagonal are unchanged. Thus it is possible to restore S if necessary according to

for k := 1 to n−1 do ! restore matrix S for l := k+1 to n do Skl := Slk endfor endfor

3. The eigenvalues are not necessarily in descending order. This can be achieved by a simple sorting algorithm.

for k := 1 to n−1 do m := k for l := k+1 to n do if el > em then m := l endif endfor if km then swap em,ek; swap Em,Ek endif endfor

4. The algorithm is written using matrix notation (1 based arrays instead of 0 based).

5. When implementing the algorithm, the part specified using matrix notation must be performed simultaneously.

6. This implementation does not correctly account for the case in which one dimension is an independent subspace. For example, if given a diagonal matrix, the above implementation will never terminate, as none of the eigenvalues will change. Hence, in real implementations, extra logic must be added to account for this case.

Example

Let S = ( 4 30 60 35 30 300 675 420 60 675 1620 1050 35 420 1050 700 )

Then jacobi produces the following eigenvalues and eigenvectors after 3 sweeps (19 iterations) :

e 1 = 2585.25381092892231

E 1 = ( 0.0291933231647860588 0.328712055763188997 0.791411145833126331 0.514552749997152907 )

e 2 = 37.1014913651276582

E 2 = ( 0.179186290535454826 0.741917790628453435 0.100228136947192199 0.638282528193614892 )

e 3 = 1.4780548447781369

E 3 = ( 0.582075699497237650 0.370502185067093058 0.509578634501799626 0.514048272222164294 )

e 4 = 0.1666428611718905

E 4 = ( 0.792608291163763585 0.451923120901599794 0.322416398581824992 0.252161169688241933 )

Applications for real symmetric matrices

When the eigenvalues (and eigenvectors) of a symmetric matrix are known, the following values are easily calculated.

Singular values
The singular values of a (square) matrix A are the square roots of the (non-negative) eigenvalues of A T A . In case of a symmetric matrix S we have of S T S = S 2 , hence the singular values of S are the absolute values of the eigenvalues of S
2-norm and spectral radius
The 2-norm of a matrix A is the norm based on the Euclidean vectornorm, i.e. the largest value A x 2 when x runs through all vectors with x 2 = 1 . It is the largest singular value of A. In case of a symmetric matrix it is largest absolute value of its eigenvectors and thus equal to its spectral radius.
Condition number
The condition number of a nonsingular matrix A is defined as cond ( A ) = A 2 A 1 2 . In case of a symmetric matrix it is the absolute value of the quotient of the largest and smallest eigenvalue. Matrices with large condition numbers can cause numerically unstable results: small perturbation can result in large errors. Hilbert matrices are the most famous ill-conditioned matrices. For example, the fourth-order Hilbert matrix has a condition of 15514, while for order 8 it is 2.7 × 108.
Rank
A matrix A has rank r if it has r columns that are linearly independent while the remaining columns are linearly dependent on these. Equivalently, r is the dimension of the range of A. Furthermore it is the number of nonzero singular values. In case of a symmetric matrix r is the number of nonzero eigenvalues. Unfortunately because of rounding errors numerical approximations of zero eigenvalues may not be zero (it may also happen that a numerical approximation is zero while the true value is not). Thus one can only calculate the numerical rank by making a decision which of the eigenvalues are close enough to zero.
Pseudo-inverse
The pseudo inverse of a matrix A is the unique matrix X = A + for which AX and XA are symmetric and for which AXA = A, XAX = X holds. If A is nonsingular, then ' A + = A 1 . When procedure jacobi (S, e, E) is called, then the relation S = E T Diag ( e ) E holds where Diag(e) denotes the diagonal matrix with vector e on the diagonal. Let e + denote the vector where e i is replaced by 1 / e i if e i 0 and by 0 if e i is (numerically close to) zero. Since matrix E is orthogonal, it follows that the pseudo-inverse of S is given by S + = E T Diag ( e + ) E .
Least squares solution
If matrix A does not have full rank, there may not be a solution of the linear system Ax = b. However one can look for a vector x for which A x b 2 is minimal. The solution is x = A + b . In case of a symmetric matrix S as before, one has x = S + b = E T Diag ( e + ) E b .
Matrix exponential
From S = E T Diag ( e ) E one finds exp S = E T Diag ( exp e ) E where exp e is the vector where e i is replaced by exp e i . In the same way, f(S) can be calculated in an obvious way for any (analytic) function f.
Linear differential equations
The differential equation x' Ax, x(0) = a has the solution x(t) = exp(t Aa. For a symmetric matrix S, it follows that x ( t ) = E T Diag ( exp t e ) E a . If a = i = 1 n a i E i is the expansion of a by the eigenvectors of S, then x ( t ) = i = 1 n a i exp ( t e i ) E i . Let W s be the vector space spanned by the eigenvectors of S which correspond to a negative eigenvalue and W u analogously for the positive eigenvalues. If a W s then lim t   x ( t ) = 0 i.e. the equilibrium point 0 is attractive to x(t). If a W u then lim t   x ( t ) = , i.e. 0 is repulsive to x(t). W s and W u are called stable and unstable manifolds for S. If a has components in both manifolds, then one component is attracted and one component is repelled. Hence x(t) approaches W u as t .

Generalizations

The Jacobi Method has been generalized to complex Hermitian matrices, general nonsymmetric real and complex matrices as well as block matrices.

Since singular values of a real matrix are the square roots of the eigenvalues of the symmetric matrix S = A T A it can also be used for the calculation of these values. For this case, the method is modified in such a way that S must not be explicitly calculated which reduces the danger of round-off errors. Note that J S J T = J A T A J T = J A T J T J A J T = B T B with B := J A J T .

The Jacobi Method is also well suited for parallelism.

References

Jacobi eigenvalue algorithm Wikipedia