Jacobi eigenvalue algorithm

From HandWiki

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,[1] but only became widely used in the 1950s with the advent of computers.[2]

Description

Let [math]\displaystyle{ S }[/math] be a symmetric matrix, and [math]\displaystyle{ G=G(i,j,\theta) }[/math] be a Givens rotation matrix. Then:

[math]\displaystyle{ S'=G S G^\top \, }[/math]

is symmetric and similar to [math]\displaystyle{ S }[/math].

Furthermore, [math]\displaystyle{ S^\prime }[/math] has entries:

[math]\displaystyle{ \begin{align} S'_{ii} &= c^2\, S_{ii} - 2\, s c \,S_{ij} + s^2\, S_{jj} \\ S'_{jj} &= s^2 \,S_{ii} + 2 s c\, S_{ij} + c^2 \, S_{jj} \\ S'_{ij} &= S'_{ji} = (c^2 - s^2 ) \, S_{ij} + s c \, (S_{ii} - S_{jj} ) \\ S'_{ik} &= S'_{ki} = c \, S_{ik} - s \, S_{jk} & k \ne i,j \\ S'_{jk} &= S'_{kj} = s \, S_{ik} + c \, S_{jk} & k \ne i,j \\ S'_{kl} &= S_{kl} &k,l \ne i,j \end{align} }[/math]

where [math]\displaystyle{ s=\sin(\theta) }[/math] and [math]\displaystyle{ c=\cos(\theta) }[/math].

Since [math]\displaystyle{ G }[/math] is orthogonal, [math]\displaystyle{ S }[/math] and [math]\displaystyle{ S^\prime }[/math] have the same Frobenius norm [math]\displaystyle{ ||\cdot||_F }[/math] (the square-root sum of squares of all components), however we can choose [math]\displaystyle{ \theta }[/math] such that [math]\displaystyle{ S^\prime_{ij}=0 }[/math], in which case [math]\displaystyle{ S^\prime }[/math] has a larger sum of squares on the diagonal:

[math]\displaystyle{ S'_{ij} = \cos(2\theta) S_{ij} + \tfrac{1}{2} \sin(2\theta) (S_{ii} - S_{jj}) }[/math]

Set this equal to 0, and rearrange:

[math]\displaystyle{ \tan(2\theta) = \frac{2 S_{ij}}{S_{jj} - S_{ii}} }[/math]

if [math]\displaystyle{ S_{jj} = S_{ii} }[/math]

[math]\displaystyle{ \theta = \frac{\pi} {4} }[/math]

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 [math]\displaystyle{ p = S_{kl} }[/math] is a pivot element, then by definition [math]\displaystyle{ |S_{ij} | \le |p| }[/math] for [math]\displaystyle{ 1 \le i, j \le n, i \ne j }[/math] . Let [math]\displaystyle{ \Gamma(S)^2 }[/math] denote the sum of squares of all off-diagonal entries of [math]\displaystyle{ S }[/math]. Since [math]\displaystyle{ S }[/math] has exactly [math]\displaystyle{ 2N := n(n-1) }[/math] off-diagonal elements, we have [math]\displaystyle{ p^2 \le \Gamma(S )^2 \le 2 N p^2 }[/math] or [math]\displaystyle{ 2 p^2 \ge \Gamma(S )^2 / N }[/math] . Now [math]\displaystyle{ \Gamma(S^J)^2=\Gamma(S)^2-2p^2 }[/math]. This implies [math]\displaystyle{ \Gamma(S^J )^2 \le (1 - 1 / N ) \Gamma (S )^2 }[/math] or [math]\displaystyle{ \Gamma (S^ J ) \le (1 - 1 / N )^{1 / 2} \Gamma(S ) }[/math]; that is, the sequence of Jacobi rotations converges at least linearly by a factor [math]\displaystyle{ (1 - 1 / N )^{1 / 2} }[/math] to a diagonal matrix.

A number of [math]\displaystyle{ N }[/math] Jacobi rotations is called a sweep; let [math]\displaystyle{ S^{\sigma} }[/math] denote the result. The previous estimate yields

[math]\displaystyle{ \Gamma(S^{\sigma} ) \le \left(1 - \frac{1}{N} \right)^{N / 2} \Gamma(S ) }[/math];

that is, the sequence of sweeps converges at least linearly with a factor ≈ [math]\displaystyle{ e ^{1 / 2} }[/math] .

However the following result of Schönhage[3] yields locally quadratic convergence. To this end let S have m distinct eigenvalues [math]\displaystyle{ \lambda_1, ... , \lambda_m }[/math] with multiplicities [math]\displaystyle{ \nu_1, ... , \nu_m }[/math] and let d > 0 be the smallest distance of two different eigenvalues. Let us call a number of

[math]\displaystyle{ N_S := \frac{n (n - 1)}{2} - \sum_{\mu = 1}^{m} \frac{1}{2} \nu_{\mu} (\nu_{\mu} - 1) \le N }[/math]

Jacobi rotations a Schönhage-sweep. If [math]\displaystyle{ S^ s }[/math] denotes the result then

[math]\displaystyle{ \Gamma(S^ s ) \le\sqrt{\frac{n}{2} - 1} \left(\frac{\gamma^2}{d - 2\gamma}\right), \quad \gamma := \Gamma(S ) }[/math] .

Thus convergence becomes quadratic as soon as [math]\displaystyle{ \Gamma(S ) \lt \frac{d}{2 + \sqrt{\frac{n}{2} - 1}} }[/math]

Cost

Each Jacobi rotation can be done in O(n) steps when the pivot element p is known. However the search for p requires inspection of all N ≈ 1/2 n2 off-diagonal elements. We can reduce this to O(n) complexity too if we introduce an additional index array [math]\displaystyle{ m_1, \, \dots \, , \, m_{n - 1} }[/math] with the property that [math]\displaystyle{ m_i }[/math] is the index of the largest element in row i, (i = 1, ..., n − 1) of the current S. Then the indices of the pivot (k, l) must be one of the pairs [math]\displaystyle{ (i, m_i) }[/math]. Also the updating of the index array can be done in O(n) average-case complexity: First, the maximum entry in the updated rows k and l can be found in O(n) steps. In the other rows i, only the entries in columns k and l change. Looping over these rows, if [math]\displaystyle{ m_i }[/math] is neither k nor l, it suffices to compare the old maximum at [math]\displaystyle{ m_i }[/math] to the new entries and update [math]\displaystyle{ m_i }[/math] if necessary. If [math]\displaystyle{ m_i }[/math] should be equal to k or l and the corresponding entry decreased during the update, the maximum over row i has to be found from scratch in O(n) complexity. However, this will happen on average only once per rotation. Thus, each rotation has O(n) and one sweep O(n3) average-case complexity, which is equivalent to one matrix multiplication. Additionally the [math]\displaystyle{ m_i }[/math] must be initialized before the process starts, which can be done in n2 steps.

Typically the Jacobi method converges within numerical precision after a small number of sweeps. Note that multiple eigenvalues reduce the number of iterations since [math]\displaystyle{ N_S \lt N }[/math].

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; that is, [math]\displaystyle{ e_i }[/math] is an eigenvalue and the column [math]\displaystyle{ E_i }[/math] an orthonormal eigenvector for [math]\displaystyle{ e_i }[/math], 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
    ! update all potentially changed indi
    for i := 1 to n do indi := maxind(i) endfor
  loop
endproc

Notes

1. The logical array changed holds the status of each eigenvalue. If the numerical value of [math]\displaystyle{ e_k }[/math] or [math]\displaystyle{ e_l }[/math] 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 [math]\displaystyle{ e_1,\, ...\, , e_n }[/math] 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 [math]\displaystyle{ S = \begin{pmatrix} 4 & -30 & 60 & -35 \\ -30 & 300 & -675 & 420 \\ 60 & -675 & 1620 & -1050 \\ -35 & 420 & -1050 & 700 \end{pmatrix} }[/math]

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

[math]\displaystyle{ e_1 = 2585.25381092892231 }[/math]

[math]\displaystyle{ E_1 = \begin{pmatrix}0.0291933231647860588\\ -0.328712055763188997\\ 0.791411145833126331\\ -0.514552749997152907\end{pmatrix} }[/math]

[math]\displaystyle{ e_2 = 37.1014913651276582 }[/math]

[math]\displaystyle{ E_2 = \begin{pmatrix}-0.179186290535454826\\ 0.741917790628453435\\ -0.100228136947192199\\ -0.638282528193614892\end{pmatrix} }[/math]

[math]\displaystyle{ e_3 = 1.4780548447781369 }[/math]

[math]\displaystyle{ E_3 = \begin{pmatrix}-0.582075699497237650\\ 0.370502185067093058\\ 0.509578634501799626\\ 0.514048272222164294\end{pmatrix} }[/math]

[math]\displaystyle{ e_4 = 0.1666428611718905 }[/math]

[math]\displaystyle{ E_4 = \begin{pmatrix}0.792608291163763585\\ 0.451923120901599794\\ 0.322416398581824992\\ 0.252161169688241933\end{pmatrix} }[/math]

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 [math]\displaystyle{ A }[/math] are the square roots of the (non-negative) eigenvalues of [math]\displaystyle{ A^T A }[/math]. In case of a symmetric matrix [math]\displaystyle{ S }[/math] we have of [math]\displaystyle{ S^T S = S^2 }[/math], hence the singular values of [math]\displaystyle{ S }[/math] are the absolute values of the eigenvalues of [math]\displaystyle{ S }[/math]
2-norm and spectral radius
The 2-norm of a matrix A is the norm based on the Euclidean vectornorm; that is, the largest value [math]\displaystyle{ \| A x\|_2 }[/math] when x runs through all vectors with [math]\displaystyle{ \|x\|_2 = 1 }[/math]. It is the largest singular value of [math]\displaystyle{ A }[/math]. In case of a symmetric matrix it is the largest absolute value of its eigenvectors and thus equal to its spectral radius.
Condition number
The condition number of a nonsingular matrix [math]\displaystyle{ A }[/math] is defined as [math]\displaystyle{ \mbox{cond} (A) = \| A \|_2 \| A^{-1}\|_2 }[/math]. 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 [math]\displaystyle{ A }[/math] has rank [math]\displaystyle{ r }[/math] if it has [math]\displaystyle{ r }[/math] columns that are linearly independent while the remaining columns are linearly dependent on these. Equivalently, [math]\displaystyle{ r }[/math] is the dimension of the range of [math]\displaystyle{ A }[/math]. 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 [math]\displaystyle{ A }[/math] is the unique matrix [math]\displaystyle{ X = A^+ }[/math] for which [math]\displaystyle{ AX }[/math] and [math]\displaystyle{ XA }[/math] are symmetric and for which [math]\displaystyle{ AXA = A, XAX = X }[/math] holds. If [math]\displaystyle{ A }[/math] is nonsingular, then [math]\displaystyle{ A^+ = A^{-1} }[/math].
When procedure jacobi (S, e, E) is called, then the relation [math]\displaystyle{ S = E^T \mbox{Diag} (e) E }[/math] holds where Diag(e) denotes the diagonal matrix with vector e on the diagonal. Let [math]\displaystyle{ e^+ }[/math] denote the vector where [math]\displaystyle{ e_i }[/math] is replaced by [math]\displaystyle{ 1/e_i }[/math] if [math]\displaystyle{ e_i \le 0 }[/math] and by 0 if [math]\displaystyle{ e_i }[/math] is (numerically close to) zero. Since matrix E is orthogonal, it follows that the pseudo-inverse of S is given by [math]\displaystyle{ S^+ = E^T \mbox{Diag} (e^+) E }[/math].
Least squares solution
If matrix [math]\displaystyle{ A }[/math] does not have full rank, there may not be a solution of the linear system [math]\displaystyle{ Ax=b }[/math]. However one can look for a vector x for which [math]\displaystyle{ \| Ax - b \|_2 }[/math] is minimal. The solution is [math]\displaystyle{ x = A^+ b }[/math]. In case of a symmetric matrix S as before, one has [math]\displaystyle{ x = S^+ b = E^T \mbox{Diag} (e^+) E b }[/math].
Matrix exponential
From [math]\displaystyle{ S = E^T \mbox{Diag} (e) E }[/math] one finds [math]\displaystyle{ \exp S = E^T \mbox{Diag} (\exp e) E }[/math] where exp [math]\displaystyle{ e }[/math] is the vector where [math]\displaystyle{ e_i }[/math] is replaced by [math]\displaystyle{ \exp e_i }[/math]. In the same way, [math]\displaystyle{ f(S) }[/math] can be calculated in an obvious way for any (analytic) function [math]\displaystyle{ f }[/math].
Linear differential equations
The differential equation [math]\displaystyle{ x'=Ax, x(0) =a }[/math] has the solution [math]\displaystyle{ x(t)=\exp(tA) }[/math]. For a symmetric matrix [math]\displaystyle{ S }[/math], it follows that [math]\displaystyle{ x(t) = E^T \mbox{Diag} (\exp t e) E a }[/math]. If [math]\displaystyle{ a = \sum_{i = 1}^n a_i E_i }[/math] is the expansion of [math]\displaystyle{ a }[/math] by the eigenvectors of [math]\displaystyle{ S }[/math], then [math]\displaystyle{ x(t) = \sum_{i = 1}^n a_i \exp(t e_i) E_i }[/math].
Let [math]\displaystyle{ W^s }[/math] be the vector space spanned by the eigenvectors of [math]\displaystyle{ S }[/math] which correspond to a negative eigenvalue and [math]\displaystyle{ W^u }[/math] analogously for the positive eigenvalues. If [math]\displaystyle{ a \in W^s }[/math] then [math]\displaystyle{ \mbox{lim}_{t \rightarrow \infty} x(t) = 0 }[/math]; that is, the equilibrium point 0 is attractive to [math]\displaystyle{ x(t) }[/math]. If [math]\displaystyle{ a \in W^u }[/math] then [math]\displaystyle{ \mbox{lim}_{t \rightarrow \infty} x(t) = \infty }[/math]; that is, 0 is repulsive to [math]\displaystyle{ x(t) }[/math]. [math]\displaystyle{ W^s }[/math] and [math]\displaystyle{ W^u }[/math] are called stable and unstable manifolds for [math]\displaystyle{ S }[/math]. If [math]\displaystyle{ a }[/math] has components in both manifolds, then one component is attracted and one component is repelled. Hence [math]\displaystyle{ x(t) }[/math] approaches [math]\displaystyle{ W^u }[/math] as [math]\displaystyle{ t \to \infty }[/math].

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 [math]\displaystyle{ S = A^T A }[/math] 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 [math]\displaystyle{ J S J^T = J A^T A J^T = J A^T J^T J A J^T = B^T B }[/math] with [math]\displaystyle{ B \, := J A J^T }[/math] .

The Jacobi Method is also well suited for parallelism.

References

  1. "Über ein leichtes Verfahren, die in der Theorie der Säkularstörungen vorkommenden Gleichungen numerisch aufzulösen" (in German). Crelle's Journal 1846 (30): 51–94. 1846. doi:10.1515/crll.1846.30.51. http://gdz.sub.uni-goettingen.de/dms/load/img/?PID=GDZPPN002144522. 
  2. Golub, G.H.; van der Vorst, H.A. (2000). "Eigenvalue computation in the 20th century". Journal of Computational and Applied Mathematics 123 (1–2): 35–65. doi:10.1016/S0377-0427(00)00413-1. 
  3. Schönhage, A. (1964). "Zur quadratischen Konvergenz des Jacobi-Verfahrens" (in German). Numerische Mathematik 6 (1): 410–412. doi:10.1007/BF01386091. 

Further reading


External links