|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.math3.linear.EigenDecomposition
public class EigenDecomposition
Calculates the eigen decomposition of a real matrix.
The eigen decomposition of matrix A is a set of two matrices: V and D such that A = V × D × VT. A, V and D are all m × m matrices.
This class is similar in spirit to the EigenvalueDecomposition
class from the JAMA
library, with the following changes:
getVt
method has been added,getRealEigenvalue
and getImagEigenvalue
methods to pick up a single eigenvalue have been added,getEigenvector
method to pick up a single
eigenvector has been added,getDeterminant
method has been added.getSolver
method has been added.As of 3.1, this class supports general real matrices (both symmetric and non-symmetric):
If A is symmetric, then A = V*D*V' where the eigenvalue matrix D is diagonal and the eigenvector matrix V is orthogonal, i.e. A = V.multiply(D.multiply(V.transpose())) and V.multiply(V.transpose()) equals the identity matrix.
If A is not symmetric, then the eigenvalue matrix D is block diagonal with the real eigenvalues in 1-by-1 blocks and any complex eigenvalues, lambda + i*mu, in 2-by-2 blocks:
[lambda, mu ] [ -mu, lambda]The columns of V represent the eigenvectors in the sense that A*V = V*D, i.e. A.multiply(V) equals V.multiply(D). The matrix V may be badly conditioned, or even singular, so the validity of the equation A = V*D*inverse(V) depends upon the condition of V.
This implementation is based on the paper by A. Drubrulle, R.S. Martin and J.H. Wilkinson "The Implicit QL Algorithm" in Wilksinson and Reinsch (1971) Handbook for automatic computation, vol. 2, Linear algebra, Springer-Verlag, New-York
Nested Class Summary | |
---|---|
private static class |
EigenDecomposition.Solver
Specialized solver. |
Field Summary | |
---|---|
private RealMatrix |
cachedD
Cached value of D. |
private RealMatrix |
cachedV
Cached value of V. |
private RealMatrix |
cachedVt
Cached value of Vt. |
private ArrayRealVector[] |
eigenvectors
Eigenvectors. |
private static double |
EPSILON
Internally used epsilon criteria. |
private double[] |
imagEigenvalues
Imaginary part of the realEigenvalues. |
private boolean |
isSymmetric
Whether the matrix is symmetric. |
private double[] |
main
Main diagonal of the tridiagonal matrix. |
private byte |
maxIter
Maximum number of iterations accepted in the implicit QL transformation |
private double[] |
realEigenvalues
Real part of the realEigenvalues. |
private double[] |
secondary
Secondary diagonal of the tridiagonal matrix. |
private TriDiagonalTransformer |
transformer
Transformer to tridiagonal (may be null if matrix is already tridiagonal). |
Constructor Summary | |
---|---|
EigenDecomposition(double[] main,
double[] secondary)
Calculates the eigen decomposition of the symmetric tridiagonal matrix. |
|
EigenDecomposition(double[] main,
double[] secondary,
double splitTolerance)
Deprecated. in 3.1 (to be removed in 4.0) due to unused parameter |
|
EigenDecomposition(RealMatrix matrix)
Calculates the eigen decomposition of the given real matrix. |
|
EigenDecomposition(RealMatrix matrix,
double splitTolerance)
Deprecated. in 3.1 (to be removed in 4.0) due to unused parameter |
Method Summary | |
---|---|
private Complex |
cdiv(double xr,
double xi,
double yr,
double yi)
Performs a division of two complex numbers. |
private void |
findEigenVectors(double[][] householderMatrix)
Find eigenvalues and eigenvectors (Dubrulle et al., 1971) |
private void |
findEigenVectorsFromSchur(SchurTransformer schur)
Find eigenvectors from a matrix transformed to Schur form. |
RealMatrix |
getD()
Gets the block diagonal matrix D of the decomposition. |
double |
getDeterminant()
Computes the determinant of the matrix. |
RealVector |
getEigenvector(int i)
Gets a copy of the ith eigenvector of the original matrix. |
double |
getImagEigenvalue(int i)
Gets the imaginary part of the ith eigenvalue of the original matrix. |
double[] |
getImagEigenvalues()
Gets a copy of the imaginary parts of the eigenvalues of the original matrix. |
double |
getRealEigenvalue(int i)
Returns the real part of the ith eigenvalue of the original matrix. |
double[] |
getRealEigenvalues()
Gets a copy of the real parts of the eigenvalues of the original matrix. |
DecompositionSolver |
getSolver()
Gets a solver for finding the A × X = B solution in exact linear sense. |
RealMatrix |
getSquareRoot()
Computes the square-root of the matrix. |
RealMatrix |
getV()
Gets the matrix V of the decomposition. |
RealMatrix |
getVT()
Gets the transpose of the matrix V of the decomposition. |
boolean |
hasComplexEigenvalues()
Returns whether the calculated eigen values are complex or real. |
private SchurTransformer |
transformToSchur(RealMatrix matrix)
Transforms the matrix to Schur form and calculates the eigenvalues. |
private void |
transformToTridiagonal(RealMatrix matrix)
Transforms the matrix to tridiagonal form. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final double EPSILON
private byte maxIter
private double[] main
private double[] secondary
private TriDiagonalTransformer transformer
private double[] realEigenvalues
private double[] imagEigenvalues
private ArrayRealVector[] eigenvectors
private RealMatrix cachedV
private RealMatrix cachedD
private RealMatrix cachedVt
private final boolean isSymmetric
Constructor Detail |
---|
public EigenDecomposition(RealMatrix matrix) throws MathArithmeticException
Supports decomposition of a general matrix since 3.1.
matrix
- Matrix to decompose.
MaxCountExceededException
- if the algorithm fails to converge.
MathArithmeticException
- if the decomposition of a general matrix
results in a matrix with zero norm@Deprecated public EigenDecomposition(RealMatrix matrix, double splitTolerance) throws MathArithmeticException
matrix
- Matrix to decompose.splitTolerance
- Dummy parameter (present for backward
compatibility only).
MathArithmeticException
- if the decomposition of a general matrix
results in a matrix with zero norm
MaxCountExceededException
- if the algorithm fails to converge.public EigenDecomposition(double[] main, double[] secondary)
main
- Main diagonal of the symmetric tridiagonal form.secondary
- Secondary of the tridiagonal form.
MaxCountExceededException
- if the algorithm fails to converge.@Deprecated public EigenDecomposition(double[] main, double[] secondary, double splitTolerance)
main
- Main diagonal of the symmetric tridiagonal form.secondary
- Secondary of the tridiagonal form.splitTolerance
- Dummy parameter (present for backward
compatibility only).
MaxCountExceededException
- if the algorithm fails to converge.Method Detail |
---|
public RealMatrix getV()
public RealMatrix getD()
getRealEigenvalues()
,
getImagEigenvalues()
public RealMatrix getVT()
public boolean hasComplexEigenvalues()
The method performs a zero check for each element of the
getImagEigenvalues()
array and returns true
if any
element is not equal to zero.
true
if the eigen values are complex, false
otherwisepublic double[] getRealEigenvalues()
getD()
,
getRealEigenvalue(int)
,
getImagEigenvalues()
public double getRealEigenvalue(int i)
i
- index of the eigenvalue (counting from 0)
getD()
,
getRealEigenvalues()
,
getImagEigenvalue(int)
public double[] getImagEigenvalues()
getD()
,
getImagEigenvalue(int)
,
getRealEigenvalues()
public double getImagEigenvalue(int i)
i
- Index of the eigenvalue (counting from 0).
getD()
,
getImagEigenvalues()
,
getRealEigenvalue(int)
public RealVector getEigenvector(int i)
i
- Index of the eigenvector (counting from 0).
getD()
public double getDeterminant()
public RealMatrix getSquareRoot()
MathUnsupportedOperationException
- if the matrix is not
symmetric or not positive definite.public DecompositionSolver getSolver()
Since 3.1, eigen decomposition of a general matrix is supported,
but the DecompositionSolver
only supports real eigenvalues.
MathUnsupportedOperationException
- if the decomposition resulted in
complex eigenvaluesprivate void transformToTridiagonal(RealMatrix matrix)
matrix
- Matrix to transform.private void findEigenVectors(double[][] householderMatrix)
householderMatrix
- Householder matrix of the transformation
to tridiagonal form.private SchurTransformer transformToSchur(RealMatrix matrix)
matrix
- Matrix to transform.
Shur transform
for this matrixprivate Complex cdiv(double xr, double xi, double yr, double yi)
xr
- real part of the first numberxi
- imaginary part of the first numberyr
- real part of the second numberyi
- imaginary part of the second number
private void findEigenVectorsFromSchur(SchurTransformer schur) throws MathArithmeticException
schur
- the schur transformation of the matrix
MathArithmeticException
- if the Schur form has a norm of zero
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |