 Jacobi eigenvalue algorithm - Wikiwand

# Jacobi eigenvalue algorithm

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.

## Description

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

$S'=GSG^{\top }\,$ is symmetric and similar to $S$ .

Furthermore, $S^{\prime )$ has entries:

{\begin{aligned}S'_{ii}&=c^{2}\,S_{ii}-2\,sc\,S_{ij}+s^{2}\,S_{jj}\\S'_{jj}&=s^{2}\,S_{ii}+2sc\,S_{ij}+c^{2}\,S_{jj}\\S'_{ij}&=S'_{ji}=(c^{2}-s^{2})\,S_{ij}+sc\,(S_{ii}-S_{jj})\\S'_{ik}&=S'_{ki}=c\,S_{ik}-s\,S_{jk}&k\neq i,j\\S'_{jk}&=S'_{kj}=s\,S_{ik}+c\,S_{jk}&k\neq i,j\\S'_{kl}&=S_{kl}&k,l\neq i,j\end{aligned)) where $s=\sin(\theta )$ and $c=\cos(\theta )$ .

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

$S'_{ij}=\cos(2\theta )S_{ij}+{\tfrac {1}{2))\sin(2\theta )(S_{ii}-S_{jj})$ Set this equal to 0, and rearrange:

$\tan(2\theta )={\frac {2S_{ij)){S_{jj}-S_{ii)))$ if $S_{jj}=S_{ii)$ $\theta ={\frac {\pi }{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_{kl)$ is a pivot element, then by definition $|S_{ij}|\leq |p|$ for $1\leq i,j\leq n,i\neq j$ . Let $\Gamma (S)^{2)$ denote the sum of squares of all off-diagonal entries of $S$ . Since $S$ has exactly $2N:=n(n-1)$ off-diagonal elements, we have $p^{2}\leq \Gamma (S)^{2}\leq 2Np^{2)$ or $2p^{2}\geq \Gamma (S)^{2}/N$ . Now $\Gamma (S^{J})^{2}=\Gamma (S)^{2}-2p^{2)$ . This implies $\Gamma (S^{J})^{2}\leq (1-1/N)\Gamma (S)^{2)$ or $\Gamma (S^{J})\leq (1-1/N)^{1/2}\Gamma (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^{\sigma )$ denote the result. The previous estimate yields

$\Gamma (S^{\sigma })\leq \left(1-{\frac {1}{N))\right)^{N/2}\Gamma (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 $\lambda _{1},...,\lambda _{m)$ with multiplicities $\nu _{1},...,\nu _{m)$ and let d > 0 be the smallest distance of two different eigenvalues. Let us call a number of

$N_{S}:={\frac {n(n-1)}{2))-\sum _{\mu =1}^{m}{\frac {1}{2))\nu _{\mu }(\nu _{\mu }-1)\leq N$ Jacobi rotations a Schönhage-sweep. If $S^{s)$ denotes the result then

$\Gamma (S^{s})\leq {\sqrt ((\frac {n}{2))-1))\left({\frac {\gamma ^{2)){d-2\gamma ))\right),\quad \gamma :=\Gamma (S)$ .

Thus convergence becomes quadratic as soon as $\Gamma (S)<{\frac {d}{2+{\sqrt ((\frac {n}{2))-1))))$ ## 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 $m_{1},\,\dots \,,\,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 the indices of the pivot (k, l) must be one of the pairs $(i,m_{i})$ . 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 $m_{i)$ is neither k nor l, it suffices to compare the old maximum at $m_{i)$ to the new entries and update $m_{i)$ if necessary. If $m_{i)$ 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 $m_{i)$ 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 $N_{S} .

## 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(S ∈ Rn×n; out e ∈ Rn; out E ∈ Rn×n)
var
i, k, l, m, state ∈ N
s, c, t, p, y, d, r ∈ R
ind ∈ Nn
changed ∈ Ln

function maxind(k ∈ N) ∈ N ! index of largest off-diagonal element in row k
m := k+1
for i := k+2 to n do
if │Ski│ > │Skm│ then m := i endif
endfor
return m
endfunc

procedure update(k ∈ N; t ∈ R) ! 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 (y≠ek) then changedk := true; state := state+1
endif
endproc

procedure rotate(k,l,i,j ∈ N) ! perform rotation of Sij, Skl
┌   ┐    ┌     ┐┌   ┐
│Skl│    │c  −s││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
if │Sk indk│ > │Sm indm│ then m := k endif
endfor
k := m; l := indm; p := Skl
! calculate c = cos φ, s = sin φ
y := (el−ek)/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│    │c  −s││Eik│
│   │ := │     ││   │
│Eil│    │s   c││Eil│
└   ┘    └     ┘└   ┘
endfor
! rows k, l have changed, update rows indk, indl
indk := maxind(k); indl := maxind(l)
loop
endproc


## 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
The 2-norm of a matrix A is the norm based on the Euclidean vectornorm, i.e. the largest value $\|Ax\|_{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 the 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 ${\mbox{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}{\mbox{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}\leq 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}{\mbox{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 $\|Ax-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}{\mbox{Diag))(e^{+})Eb$ .
Matrix exponential
From $S=E^{T}{\mbox{Diag))(e)E$ one finds $\exp S=E^{T}{\mbox{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}{\mbox{Diag))(\exp te)Ea$ . If $a=\sum _{i=1}^{n}a_{i}E_{i)$ is the expansion of a by the eigenvectors of S, then $x(t)=\sum _{i=1}^{n}a_{i}\exp(te_{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\in W^{s)$ then ${\mbox{lim))_{t\ \infty }x(t)=0$ i.e. the equilibrium point 0 is attractive to x(t). If $a\in W^{u)$ then ${\mbox{lim))_{t\ \infty }x(t)=\infty$ , 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\to \infty$ .

## 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 $JSJ^{T}=JA^{T}AJ^{T}=JA^{T}J^{T}JAJ^{T}=B^{T}B$ with $B\,:=JAJ^{T)$ .

The Jacobi Method is also well suited for parallelism.

1. ^ Jacobi, C.G.J. (1846). "Über ein leichtes Verfahren, die in der Theorie der Säkularstörungen vorkommenden Gleichungen numerisch aufzulösen". Crelle's Journal (in German). 1846 (30): 51–94. doi:10.1515/crll.1846.30.51.
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". Numerische Mathematik (in German). 6 (1): 410–412. doi:10.1007/BF01386091. MR 0174171.