Content deleted Content added
m convert special characters (via WP:JWB) |
WikiBuddy2 (talk | contribs) Link suggestions feature: 3 links added. |
||
(30 intermediate revisions by 18 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
Line 6 ⟶ 7:
|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
Line 14 ⟶ 15:
|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</math> be a symmetric matrix, and <math>G=G(i,j,\theta)</math> be a [[Givens rotation|Givens rotation matrix]]. Then:
:<math>S'=G^\top S G
is symmetric and [[similar (linear algebra)|similar]] to <math>S</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 element]] with the largest [[absolute value]], called the ''pivot''.
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> . Let <math>\Gamma(S)^2</math> denote the sum of squares of all off-diagonal entries of <math>S</math>. Since <math>S</math> has exactly <math> 2N := n(n-1) </math> off-diagonal elements, we have <math> p^2 \le \Gamma(S )^2 \le 2 N p^2 </math> or <math> 2 p^2 \ge \Gamma(S )^2 / N </math> . Now <math>\Gamma(S^J)^2=\Gamma(S)^2-2p^2</math>. This implies
<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> N </math> Jacobi rotations is called a sweep; let <math> S^{\sigma} </math> denote the result. The previous estimate yields
: <math> \Gamma(S^{\sigma} ) \le \left(1 - \frac{1}{N} \right)^{N / 2} \Gamma(S ) </math>
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{n (n - 1)}{2} - \sum_{\mu = 1}^{m} \frac{1}{2} \nu_{\mu} (\nu_{\mu} - 1) \le N </math>
Line 80 ⟶ 84:
== Cost ==
Each
=== Caching row maximums === We can reduce 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
'''procedure''' jacobi(''S'' ∈ '''R'''<sup>''n''×''n''</sup>; '''out''' ''e'' ∈ '''R'''<sup>''n''</sup>; '''out''' ''E'' ∈ '''R'''<sup>''n''×''n''</sup>)
Line 145 ⟶ 163:
└ <sub> </sub>┘ └ ┘└ <sub> </sub>┘
'''endfor'''
! ''
''
'''loop'''
'''endproc'''
Line 230 ⟶ 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 261 ⟶ 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 269 ⟶ 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 276 ⟶ 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 291 ⟶ 383:
|doi=10.1007/BF01385654 |mr=1098865
|citeseerx=10.1.1.134.3566
|s2cid=13904356
}}
* {{cite journal
Line 298 ⟶ 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 306 ⟶ 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}}
|