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]
Let
S
G=G(i,j,\theta)
S'=G\topSG
is symmetric and similar to
S
Furthermore,
S\prime
\begin{align} S'ii&=c2Sii-2scSij+s2Sjj\\ S'jj&=s2Sii+2scSij+c2Sjj\\ S'ij&=S'ji=(c2-s2)Sij+sc(Sii-Sjj)\\ S'ik&=S'ki=cSik-sSjk&k\nei,j\\ S'jk&=S'kj=sSik+cSjk&k\nei,j\\ S'kl&=Skl&k,l\nei,j \end{align}
where
s=\sin(\theta)
c=\cos(\theta)
Since
G
S
S\prime
|| ⋅ ||F
\theta
\prime | |
S | |
ij |
=0
S\prime
S'ij=\cos(2\theta)Sij+\tfrac{1}{2}\sin(2\theta)(Sii-Sjj)
Set this equal to 0, and rearrange:
\tan(2\theta)=
2Sij | |
Sjj-Sii |
if
Sjj=Sii
\theta=
\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.
If
p=Skl
|Sij|\le|p|
1\lei,j\len,i\nej
\Gamma(S)2
S
S
2N:=n(n-1)
p2\le\Gamma(S)2\le2Np2
2p2\ge\Gamma(S)2/N
\Gamma(SJ)2=\Gamma(S)2-2p2
\Gamma(SJ)2\le(1-1/N)\Gamma(S)2
\Gamma(SJ)\le(1-1/N)1\Gamma(S)
(1-1/N)1
A number of
N
S\sigma
\Gamma(S\sigma)\le\left(1-
1 | |
N |
\right)N\Gamma(S)
e1
However the following result of Schönhage[3] yields locally quadratic convergence. To this end let S have m distinct eigenvalues
λ1,...,λm
\nu1,...,\num
NS:=
n(n-1) | |
2 |
-
m | |
\sum | |
\mu=1 |
1 | |
2 |
\nu\mu(\nu\mu-1)\leN
Jacobi rotations a Schönhage-sweep. If
Ss
\Gamma(Ss)\le\sqrt{
n | |
2 |
-1}\left(
\gamma2 | |
d-2\gamma |
\right), \gamma:=\Gamma(S)
Thus convergence becomes quadratic as soon as
\Gamma(S)<
d | |||||
|
Each Givens 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 ≈ n2 off-diagonal elements. We can reduce this to O(n) complexity too if we introduce an additional index array
m1,...,mn
mi
(i,mi)
mi
mi
mi
mi
mi
Typically the Jacobi method converges within numerical precision after a small number of sweeps. Note that multiple eigenvalues reduce the number of iterations since
NS<N
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,
ei
Ei
ei
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 ! update all potentially changed indi for i := 1 to n do indi := maxind(i) endfor loop endproc
1. The logical array changed holds the status of each eigenvalue. If the numerical value of
ek
el
e1,...,en
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 k ≠ m 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.
Let
S=\begin{pmatrix}4&-30&60&-35\ -30&300&-675&420\ 60&-675&1620&-1050\ -35&420&-1050&700\end{pmatrix}
Then jacobi produces the following eigenvalues and eigenvectors after 3 sweeps (19 iterations) :
e1=2585.25381092892231
E1=\begin{pmatrix}0.0291933231647860588\ -0.328712055763188997\ 0.791411145833126331\ -0.514552749997152907\end{pmatrix}
e2=37.1014913651276582
E2=\begin{pmatrix}-0.179186290535454826\ 0.741917790628453435\ -0.100228136947192199\ -0.638282528193614892\end{pmatrix}
e3=1.4780548447781369
E3=\begin{pmatrix}-0.582075699497237650\ 0.370502185067093058\ 0.509578634501799626\ 0.514048272222164294\end{pmatrix}
e4=0.1666428611718905
E4=\begin{pmatrix}0.792608291163763585\ 0.451923120901599794\ 0.322416398581824992\ 0.252161169688241933\end{pmatrix}
When the eigenvalues (and eigenvectors) of a symmetric matrix are known, the followingvalues are easily calculated.
A
ATA
S
STS=S2
S
S
\|Ax\|2
\|x\|2=1
A
A
cond(A)=\|A\|2\|A-1\|2
A
r
r
r
A
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.
A
X=A+
AX
XA
AXA=A,XAX=X
A
A+=A-1
When procedure jacobi (S, e, E) is called, then the relation
S=ETDiag(e)E
e+
ei
1/ei
ei\le0
ei
S+=ETDiag(e+)E
A
Ax=b
\|Ax-b\|2
x=A+b
x=S+b=ETDiag(e+)Eb
S=ETDiag(e)E
\expS=ETDiag(\expe)E
e
ei
\expei
f(S)
f
x'=Ax,x(0)=a
x(t)=\exp(tA)
S
x(t)=ETDiag(\expte)Ea
a=
n | |
\sum | |
i=1 |
aiEi
a
S
x(t)=
n | |
\sum | |
i=1 |
ai\exp(tei)Ei
Let
Ws
S
Wu
a\inWs
limtx(t)=0
x(t)
a\inWu
limtx(t)=infty
x(t)
Ws
Wu
S
a
x(t)
Wu
t\toinfty
The following code is a straight-forward implementation of the mathematical description of the Jacobi eigenvalue algorithm in the Julia programming language.
function find_pivot(Sprime) n = size(Sprime,1) pivot_i = pivot_j = 0 pivot = 0.0
for j = 1:n for i = 1:(j-1) if abs(Sprime[i,j]) > pivot pivot_i = i pivot_j = j pivot = abs(Sprime[i,j]) end end end
return (pivot_i, pivot_j, pivot)end
function givens_rotation_matrix(n,i,j,θ) G = Matrix(I,(n,n)) G[i,i] = G[j,j] = cos(θ) G[i,j] = sin(θ) G[j,i] = -sin(θ) return Gend
n = 4sqrtS = randn(n,n);S = sqrtS*sqrtS';
tol = 1e-14
Sprime = copy(S)U = Matrix(I,(n,n))
while true (pivot_i, pivot_j, pivot) = find_pivot(Sprime)
if pivot < tol break end
θ = atan(2*Sprime[pivot_i,pivot_j]/(Sprime[pivot_j,pivot_j] - Sprime[pivot_i,pivot_i])) / 2
G = givens_rotation_matrix(n,pivot_i,pivot_j,θ)
# update Sprime and U Sprime .= G'*Sprime*G U .= U * Gend
λ = diag(Sprime)
i = sortperm(λ)λ = λ[i]U = U[:,i]
@test S ≈ U * diagm(λ) * U'
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=ATA
JSJT=JATAJT=JATJTJAJT=BTB
B:=JAJT
The Jacobi Method is also well suited for parallelism.