Content deleted Content added
WikiBuddy2 (talk | contribs) Link suggestions feature: 3 links added. |
|||
(59 intermediate revisions by 37 users not shown) | |||
Line 1:
{{short description|Numerical linear algebra algorithm}}
In [[numerical linear algebra]], the '''Jacobi eigenvalue algorithm''' is an [[iterative method]] for the calculation of the [[eigenvalue]]s and [[eigenvector]]s of a [[real number|real]] [[symmetric matrix]] (a process known as [[Matrix diagonalization#Diagonalization|diagonalization]]). It is named after [[Carl Gustav Jacob Jacobi]], who first proposed the method in 1846,<ref>{{cite journal
|last=Jacobi |first=C.G.J. |authorlink=Carl Gustav Jacob Jacobi
|url=http://
|title=Über ein leichtes Verfahren, die in der Theorie der Säkularstörungen vorkommenden Gleichungen numerisch aufzulösen
|journal=[[Crelle's Journal]]
|volume=1846 |issue=30 |year=1846 |pages=51–94
|language=German
|doi=10.1515/crll.1846.30.51 |s2cid=199546177 |url-access=subscription }}</ref> but it only became widely used in the 1950s with the advent of computers.<ref>{{cite journal
|
|first2=H.A. |last2=van der Vorst|author2-link=Henk van der Vorst
|title=Eigenvalue computation in the 20th century
|journal=Journal of Computational and Applied Mathematics
|volume=123 |issue=
|doi=10.1016/S0377-0427(00)00413-1
|doi-access=free}}</ref>
This algorithm is inherently a [[dense matrix]] algorithm: it draws little or no advantage from being applied to a sparse matrix, and it will destroy sparseness by creating fill-in. Similarly, it will not preserve structures such as being [[band matrix|banded]] of the matrix on which it operates.
== Description ==
Let
:<math>S'=G^\top S G
is symmetric and [[similar (linear algebra)|similar]] to
Furthermore,
:<math>\begin{align}
Line 33 ⟶ 36:
\end{align}</math>
where
Since
:<math> S'_{ij} = \cos(2\theta) S_{ij} + \tfrac{1}{2} \sin(2\theta) (S_{ii} - S_{jj}) </math>
Line 47 ⟶ 50:
:<math> \theta = \frac{\pi} {4} </math>
In order to optimize this effect, ''S''<sub>''ij''</sub> should be the [[off-diagonal
The Jacobi eigenvalue method repeatedly [[Jacobi rotation|performs rotations]] until the matrix becomes almost diagonal. Then the elements in the diagonal are approximations of the (real) eigenvalues of ''S''.
Line 53 ⟶ 56:
== Convergence ==
If <math> p = S_{kl} </math> is a [[pivot element]], then by definition <math> |S_{ij} | \le |p| </math> for <math> 1 \le i, j \le n, i \ne j</math> .
<math> \Gamma(S^J )^2 \le (1 - 1 / N ) \Gamma (S )^2 </math> or <math> \Gamma (S^ J ) \le (1 - 1 / N )^{1 / 2} \Gamma(S ) </math>
A number of
: <math> \Gamma(S^{\sigma} ) \le \left(1 - \frac{1
However the following result of [[Arnold Schönhage|Schönhage]]<ref>{{cite journal
|last=Schönhage |first=A.|authorlink=Arnold Schönhage
|title=Zur quadratischen Konvergenz des Jacobi-Verfahrens
|journal=Numerische Mathematik
Line 68 ⟶ 71:
|language=German
|doi=10.1007/BF01386091 |mr=174171
|s2cid=118301078
}}</ref> yields locally quadratic convergence. To this end let ''S'' have ''m'' distinct eigenvalues <math> \lambda_1, ... , \lambda_m </math> with multiplicities <math> \nu_1, ... , \nu_m </math> and let ''d'' > 0 be the smallest distance of two different eigenvalues. Let us call a number of
: <math> N_S := \frac{
Jacobi rotations a Schönhage-sweep. If <math> S^ s </math> denotes the result then
: <math> \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> \Gamma(S ) < \frac{d == Cost ==
Each
=== Caching row maximums ===
We can reduce the complexity of finding the pivot element from O(''N'') to O(''n'') if we introduce an additional index array <math> m_1, \, \dots \, , \, m_{n - 1} </math> with the property that <math> 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> (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> m_i </math> is neither ''k'' nor ''l'', it suffices to compare the old maximum at <math> m_i </math> to the new entries and update <math> m_i </math> if necessary. If <math> 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(''n''<sup>3</sup>) average-case complexity, which is equivalent to one [[matrix multiplication]]. Additionally the <math> m_i </math> must be initialized before the process starts, which can be done in ''n''<sup>2</sup> 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>N_S < N</math>.
=== Cyclic and parallel Jacobi ===
An alternative approach is to forego the search entirely, and simply have each sweep pivot every off-diagonal element once, in some predetermined order. It has been shown that this ''cyclic Jacobi'' attains quadratic convergence,<ref>{{cite journal |last=Wilkinson |first=J.H. |authorlink=James H. Wilkinson |title=Note on the Quadratic Convergence of the Cyclic Jacobi Process |journal=Numerische Mathematik |date=1962 |volume=6 |pages=296–300|doi=10.1007/BF01386321 }}</ref><ref>{{cite journal |last1=van Kempen |first1=H.P.M. |title=On Quadratic Convergence of the Special Cyclic Jacobi Method |journal=Numerische Mathematik |date=1966 |volume=9 |pages=19–22|doi=10.1007/BF02165225 }}</ref> just like the classical Jacobi.
The opportunity for parallelisation that is particular to Jacobi is based on combining cyclic Jacobi with the observation that Givens rotations for [[disjoint sets]] of indices commute, so that several can be applied in parallel. Concretely, if <math> G_1 </math> pivots between indices <math> i_1, j_1 </math> and <math> G_2 </math> pivots between indices <math> i_2, j_2 </math>, then from <math> \{i_1,j_1\} \cap \{i_2,j_2\} = \varnothing </math> follows <math> G_1 G_2 = G_2 G_1 </math> because in computing <math> G_1 G_2 A </math> or <math> G_2 G_1 A </math> the <math> G_1 </math> rotation only needs to access rows <math> i_1, j_1 </math> and the <math> G_2 </math> rotation only needs to access rows <math> i_2, j_2 </math>. Two processors can perform both rotations in parallel, because no matrix element is accessed for both.
Partitioning the set of index pairs of a sweep into classes that are pairwise disjoint is equivalent to partitioning the edge set of a [[complete graph]] into [[Matching (graph theory)|matching]]s, which is the same thing as [[edge colouring]] it; each colour class then becomes a round within the sweep. The minimal number of rounds is the [[chromatic index]] of the complete graph, and equals <math>n</math> for odd <math>n</math> but <math>n-1</math> for even <math>n</math>. A simple rule for odd <math>n</math> is to handle the pairs <math> \{i_1,j_1\} </math> and <math> \{i_2,j_2\} </math> in the same round if <math> i_1+j_1 \equiv i_2+j_2 \textstyle\pmod{n} </math>. For even <math>n</math> one may create <math> n-1 </math> rounds <math> k = 0, 1, \dotsc, n-2 </math> where a pair <math> \{i,j\} </math> for <math> 1 \leqslant i < j \leqslant n-1 </math> goes into round <math> (i+j) \bmod (n-1) </math> and additionally a pair <math> \{i,n\} </math> for <math> 1 \leqslant i \leqslant n-1 </math> goes into round <math> 2i \bmod (n-1) </math>. This brings the time complexity of a sweep down from <math> O(n^3) </math> to <math> O(n^2) </math>, if <math> n/2 </math> processors are available.
A round would consist of each processor first calculating <math>(c,s)</math> for its rotation, and then applying the rotation from the left (rotating between rows). Next, the processors [[synchronise]] before applying the transpose rotation from the right (rotating between columns), and finally synchronising again. A matrix element may be accessed by two processors during a round, but not by both during the same half of this round.
Further parallelisation is possible by dividing the work for a single rotation between several processors, but that might be getting too fine-grained to be practical.
== 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,
'''procedure''' jacobi(''S'' ∈ '''R'''<sup>''n''×''n''</sup>; '''out''' ''e'' ∈ '''R'''<sup>''n''</sup>; '''out''' ''E'' ∈ '''R'''<sup>''n''×''n''</sup>)
Line 126 ⟶ 143:
''m'' := 1 ! ''find index (k,l) of pivot p''
'''for''' ''k'' := 2 '''to''' ''n''−1 '''do'''
'''if''' │''S''<sub>''k'' ''ind''
'''endfor'''
''k'' := ''m''; ''l'' := ''ind''<sub>''m''</sub>; ''p'' := ''S''<sub>''kl''</sub>
! ''calculate c = cos
''y'' := (''e''<sub>''l''</sub>−''e''<sub>''k''</sub>)/2; ''d'' := │''y''│+√(''p''<sup>2</sup>+''y''<sup>2</sup>)
''r'' := √(''p''<sup>2</sup>+''d''<sup>2</sup>); ''c'' := ''d''/''r''; ''s'' := ''p''/''r''; ''t'' := ''p''<sup>2</sup>/''d''
Line 141 ⟶ 158:
'''for''' ''i'' := 1 '''to''' ''n'' '''do'''
┌ <sub> </sub>┐ ┌ ┐┌ <sub> </sub>┐
│''E''<sub>''
│ <sub> </sub>│ := │ ││ <sub> </sub>│
│''E''<sub>''
└ <sub> </sub>┘ └ ┘└ <sub> </sub>┘
'''endfor'''
! ''
''
'''loop'''
'''endproc'''
Line 158 ⟶ 175:
'''for''' ''k'' := 1 '''to''' ''n''−1 '''do''' ! ''restore matrix S''
'''for''' ''l'' := ''k''+1 '''to''' ''n'' '''do'''
''S''<sub>''kl''</sub> := ''S''<sub>''lk''</sub> '''endfor''' '''endfor'''
Line 164 ⟶ 183:
'''for''' ''k'' := 1 '''to''' ''n''−1 '''do'''
''m'' := ''k''
'''for''' ''l'' := ''k''+1 '''to''' ''n'' '''do'''
'''if''' ''e''<sub>''l''</sub> > ''e''<sub>''m''</sub> '''then'''
''m'' := ''l'' '''endif''' '''endfor'''
'''if''' ''k'' ≠ ''m'' '''then'''
swap ''e''<sub>''m''</sub>,''e''<sub>''k''</sub> swap ''E''<sub>''m''</sub>,''E''<sub>''k''</sub> '''endif''' '''endfor'''
Line 224 ⟶ 248:
;Singular values
:The singular values of a (square) matrix
;2-norm and spectral radius
:The 2-norm of a matrix ''A'' is the norm based on the Euclidean vectornorm
;Condition number
:The condition number of a nonsingular matrix
;Rank
:A matrix
: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
:When procedure jacobi (S, e, E) is called, then the relation <math> S = E^T \mbox{Diag} (e) E </math> holds where Diag(''e'') denotes the diagonal matrix with vector ''e'' on the diagonal. Let <math> e^+ </math> denote the vector where <math> e_i </math> is replaced by <math> 1/e_i </math> if <math> e_i \le 0 </math> and by 0 if <math> 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> S^+ = E^T \mbox{Diag} (e^+) E </math>.
;Least squares solution
:If matrix
;Matrix exponential
:From <math> S = E^T \mbox{Diag} (e) E </math> one finds <math> \exp S = E^T \mbox{Diag} (\exp e) E </math> where exp
;Linear differential equations
:The differential equation
:Let <math> W^s </math> be the vector space spanned by the eigenvectors of
== Julia implementation ==
The following code is a straight-forward implementation of the mathematical description of the Jacobi eigenvalue algorithm in the [[Julia (programming language)|Julia programming language]].
<syntaxhighlight lang="julia">
using LinearAlgebra, Test
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
# in practice one should not instantiate explicitly the Givens rotation matrix
function givens_rotation_matrix(n,i,j,θ)
G = Matrix{Float64}(I,(n,n))
G[i,i] = G[j,j] = cos(θ)
G[i,j] = sin(θ)
G[j,i] = -sin(θ)
return G
end
# S is a symmetric n by n matrix
n = 4
sqrtS = randn(n,n);
S = sqrtS*sqrtS';
# the largest allowed off-diagonal element of U' * S * U
# where U are the eigenvectors
tol = 1e-14
Sprime = copy(S)
U = Matrix{Float64}(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 * G
end
# Sprime is now (almost) a diagonal matrix
# extract eigenvalues
λ = diag(Sprime)
# sort eigenvalues (and corresponding eigenvectors U) by increasing values
i = sortperm(λ)
λ = λ[i]
U = U[:,i]
# S should be equal to U * diagm(λ) * U'
@test S ≈ U * diagm(λ) * U'
</syntaxhighlight>
== Generalizations ==
Line 255 ⟶ 354:
Since singular values of a real matrix are the square roots of the eigenvalues of the symmetric matrix <math> 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 error]]s. Note that <math> 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> B \, := J A J^T </math> .
== References ==
Line 263 ⟶ 360:
== Further reading ==
{{refbegin}}
*{{Citation | last1=Press | first1=WH | last2=Teukolsky | first2=SA | last3=Vetterling | first3=WT | last4=Flannery | first4=BP | year=2007 | title=Numerical Recipes: The Art of Scientific Computing | edition=3rd | publisher=Cambridge University Press |
* {{cite journal
|last=Rutishauser |first=H.
Line 270 ⟶ 367:
|volume=9 |issue=1 |year=1966 |pages=1–10
|doi=10.1007/BF02165223 |mr=1553948
|s2cid=120520713
}}
* {{cite journal
|last=Sameh |first=A.H.
Line 277 ⟶ 375:
|volume=25 |issue=115 |year=1971 |pages=579–590
|mr=297131 | jstor = 2005221 | doi = 10.1090/s0025-5718-1971-0297131-6
|doi-access=free }}
* {{cite journal
|last=Shroff |first=Gautam M.
Line 284 ⟶ 382:
|volume=58 |issue=1 |year=1991 |pages=779–805
|doi=10.1007/BF01385654 |mr=1098865
|citeseerx=10.1.1.134.3566
|s2cid=13904356
}}
* {{cite journal
|last=Veselić |first=K.
Line 291 ⟶ 391:
|volume=33 |issue=2 |year=1979 |pages=157–172
|doi=10.1007/BF01399551 |mr=549446
|s2cid=119919630
}}
* {{cite journal
|
|last2=Wenzel |first2=H. J.
|title=A quadratically convergent Jacobi-like method for real matrices with complex eigenvalues
Line 299 ⟶ 400:
|volume=33 |issue=4 |year=1979 |pages=425–435
|doi=10.1007/BF01399324 |mr=553351
|s2cid=119554420
}}
* Yousef Saad: "Revisiting the (block) Jacobi subspace rotation method for the symmetric eigenvalue problem", Numerical Algorithms, vol.92 (2023), pp.917-944. https://doi.org/10.1007/s11075-022-01377-w .
{{refend}}
== External links ==
*[https://groups.google.com/group/sci.math.num-analysis/msg/8282d0d412f72d2e Matlab implementation of Jacobi algorithm that avoids trigonometric functions]
*[https://github.com/jewettaij/jacobi_pd C++11 implementation]
{{Numerical linear algebra}}
|