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
| Modifier and Type | Class and Description |
|---|---|
| private static class | EigenDecomposition.
Specialized solver. |
| Modifier and Type | Field and Description |
|---|---|
| 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 final double | EPSILON
Internally used epsilon criteria. |
| private double[] | imagEigenvalues
Imaginary part of the realEigenvalues. |
| private final 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). |
| Access | Constructor and Description |
|---|---|
| public | EigenDecomposition(final RealMatrix
Matrix to decompose. matrix)Calculates the eigen decomposition of the given real matrix. |
| public | EigenDecomposition(final RealMatrix
Matrix to decompose. matrix, final double Dummy parameter (present for backward
compatibility only). splitTolerance)
Deprecated
in 3.1 (to be removed in 4.0) due to unused parameter
Calculates the eigen decomposition of the given real matrix. |
| public | EigenDecomposition(final double[]
Main diagonal of the symmetric tridiagonal form. main, final double[] Secondary of the tridiagonal form. secondary)Calculates the eigen decomposition of the symmetric tridiagonal matrix. |
| public | EigenDecomposition(final double[]
Main diagonal of the symmetric tridiagonal form. main, final double[] Secondary of the tridiagonal form. secondary, final double Dummy parameter (present for backward
compatibility only). splitTolerance)
Deprecated
in 3.1 (to be removed in 4.0) due to unused parameter
Calculates the eigen decomposition of the symmetric tridiagonal matrix. |
| Modifier and Type | Method and Description |
|---|---|
| private Complex | Returns: result of the complex divisionreal part of the first number xr, final double imaginary part of the first number xi, final double real part of the second number yr, final double imaginary part of the second number yi)Performs a division of two complex numbers. |
| private void | findEigenVectors(final double[][]
Householder matrix of the transformation
to tridiagonal form. householderMatrix)Find eigenvalues and eigenvectors (Dubrulle et al., 1971) |
| private void | findEigenVectorsFromSchur(final SchurTransformer
the schur transformation of the matrix schur)Find eigenvectors from a matrix transformed to Schur form. |
| public RealMatrix | |
| public double | |
| public RealVector | Returns: a copy of the ith eigenvector of the original matrix.Index of the eigenvector (counting from 0). i)Gets a copy of the ith eigenvector of the original matrix. |
| public double | Returns: the imaginary part of the ith eigenvalue of the original matrix.Index of the eigenvalue (counting from 0). i)Gets the imaginary part of the ith eigenvalue of the original matrix. |
| public double[] | Returns: a copy of the imaginary parts of the eigenvalues of the original matrix.Gets a copy of the imaginary parts of the eigenvalues of the original matrix. |
| public double | Returns: real part of the ith eigenvalue of the original matrix.index of the eigenvalue (counting from 0) i)Returns the real part of the ith eigenvalue of the original matrix. |
| public double[] | Returns: a copy of the real parts of the eigenvalues of the original matrix.Gets a copy of the real parts of the eigenvalues of the original matrix. |
| public DecompositionSolver | |
| public RealMatrix | |
| public RealMatrix | |
| public RealMatrix | Returns: the transpose of the V matrix.Gets the transpose of the matrix V of the decomposition. |
| public boolean | Returns: true if the eigen values are complex, false otherwiseReturns whether the calculated eigen values are complex or real. |
| private SchurTransformer | Returns: theShur transform for this matrixMatrix to transform. matrix)Transforms the matrix to Schur form and calculates the eigenvalues. |
| private void | transformToTridiagonal(final RealMatrix
Matrix to transform. matrix)Transforms the matrix to tridiagonal form. |
| cachedD | back to summary |
|---|---|
| private RealMatrix cachedD Cached value of D. | |
| cachedV | back to summary |
|---|---|
| private RealMatrix cachedV Cached value of V. | |
| cachedVt | back to summary |
|---|---|
| private RealMatrix cachedVt Cached value of Vt. | |
| eigenvectors | back to summary |
|---|---|
| private ArrayRealVector[] eigenvectors Eigenvectors. | |
| EPSILON | back to summary |
|---|---|
| private static final double EPSILON Internally used epsilon criteria. | |
| imagEigenvalues | back to summary |
|---|---|
| private double[] imagEigenvalues Imaginary part of the realEigenvalues. | |
| isSymmetric | back to summary |
|---|---|
| private final boolean isSymmetric Whether the matrix is symmetric. | |
| main | back to summary |
|---|---|
| private double[] main Main diagonal of the tridiagonal matrix. | |
| maxIter | back to summary |
|---|---|
| private byte maxIter Maximum number of iterations accepted in the implicit QL transformation | |
| realEigenvalues | back to summary |
|---|---|
| private double[] realEigenvalues Real part of the realEigenvalues. | |
| secondary | back to summary |
|---|---|
| private double[] secondary Secondary diagonal of the tridiagonal matrix. | |
| transformer | back to summary |
|---|---|
| private TriDiagonalTransformer transformer Transformer to tridiagonal (may be null if matrix is already tridiagonal). | |
| EigenDecomposition | back to summary |
|---|---|
| public EigenDecomposition(final RealMatrix matrix) throws MathArithmeticException Calculates the eigen decomposition of the given real matrix. Supports decomposition of a general matrix since 3.1.
| |
| EigenDecomposition | back to summary |
|---|---|
| public EigenDecomposition(final RealMatrix matrix, final double splitTolerance) throws MathArithmeticException
Deprecated in 3.1 (to be removed in 4.0) due to unused parameter Calculates the eigen decomposition of the given real matrix.
| |
| EigenDecomposition | back to summary |
|---|---|
| public EigenDecomposition(final double[] main, final double[] secondary) Calculates the eigen decomposition of the symmetric tridiagonal matrix. The Householder matrix is assumed to be the identity matrix.
| |
| EigenDecomposition | back to summary |
|---|---|
| public EigenDecomposition(final double[] main, final double[] secondary, final double splitTolerance)
Deprecated in 3.1 (to be removed in 4.0) due to unused parameter Calculates the eigen decomposition of the symmetric tridiagonal matrix. The Householder matrix is assumed to be the identity matrix.
| |
| cdiv | back to summary |
|---|---|
| private Complex cdiv(final double xr, final double xi, final double yr, final double yi) Performs a division of two complex numbers.
| |
| findEigenVectors | back to summary |
|---|---|
| private void findEigenVectors(final double[][] householderMatrix) Find eigenvalues and eigenvectors (Dubrulle et al., 1971)
| |
| findEigenVectorsFromSchur | back to summary |
|---|---|
| private void findEigenVectorsFromSchur(final SchurTransformer schur) throws MathArithmeticException Find eigenvectors from a matrix transformed to Schur form.
| |
| getD | back to summary |
|---|---|
| public RealMatrix getD() Gets the block diagonal matrix D of the decomposition. D is a block diagonal matrix. Real eigenvalues are on the diagonal while complex values are on 2x2 blocks { {real +imaginary}, {-imaginary, real} }.
| |
| getDeterminant | back to summary |
|---|---|
| public double getDeterminant() Computes the determinant of the matrix.
| |
| getEigenvector | back to summary |
|---|---|
| public RealVector getEigenvector(final int i) Gets a copy of the ith eigenvector of the original matrix.
| |
| getImagEigenvalue | back to summary |
|---|---|
| public double getImagEigenvalue(final int i) Gets the imaginary part of the ith eigenvalue of the original matrix.
| |
| getImagEigenvalues | back to summary |
|---|---|
| public double[] getImagEigenvalues() Gets a copy of the imaginary parts of the eigenvalues of the original matrix.
| |
| getRealEigenvalue | back to summary |
|---|---|
| public double getRealEigenvalue(final int i) Returns the real part of the ith eigenvalue of the original matrix.
| |
| getRealEigenvalues | back to summary |
|---|---|
| public double[] getRealEigenvalues() Gets a copy of the real parts of the eigenvalues of the original matrix.
| |
| getSolver | back to summary |
|---|---|
| public DecompositionSolver getSolver() Gets a solver for finding the A × X = B solution in exact linear sense.
Since 3.1, eigen decomposition of a general matrix is supported,
but the
| |
| getSquareRoot | back to summary |
|---|---|
| public RealMatrix getSquareRoot() Computes the square-root of the matrix. This implementation assumes that the matrix is symmetric and positive definite.
| |
| getV | back to summary |
|---|---|
| public RealMatrix getV() Gets the matrix V of the decomposition. V is an orthogonal matrix, i.e. its transpose is also its inverse. The columns of V are the eigenvectors of the original matrix. No assumption is made about the orientation of the system axes formed by the columns of V (e.g. in a 3-dimension space, V can form a left- or right-handed system).
| |
| getVT | back to summary |
|---|---|
| public RealMatrix getVT() Gets the transpose of the matrix V of the decomposition. V is an orthogonal matrix, i.e. its transpose is also its inverse. The columns of V are the eigenvectors of the original matrix. No assumption is made about the orientation of the system axes formed by the columns of V (e.g. in a 3-dimension space, V can form a left- or right-handed system).
| |
| hasComplexEigenvalues | back to summary |
|---|---|
| public boolean hasComplexEigenvalues() Returns whether the calculated eigen values are complex or real. The method performs a zero check for each element of the
| |
| transformToSchur | back to summary |
|---|---|
| private SchurTransformer transformToSchur(final RealMatrix matrix) Transforms the matrix to Schur form and calculates the eigenvalues.
| |
| transformToTridiagonal | back to summary |
|---|---|
| private void transformToTridiagonal(final RealMatrix matrix) Transforms the matrix to tridiagonal form.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final ArrayRealVector[] | eigenvectors
Eigenvectors. |
| private double[] | imagEigenvalues
Imaginary part of the realEigenvalues. |
| private double[] | realEigenvalues
Real part of the realEigenvalues. |
| Access | Constructor and Description |
|---|---|
| private | Solver(final double[]
Real parts of the eigenvalues. realEigenvalues, final double[] Imaginary parts of the eigenvalues. imagEigenvalues, final ArrayRealVector[] Eigenvectors. eigenvectors)Builds a solver from decomposed matrix. |
| Modifier and Type | Method and Description |
|---|---|
| private double | Returns: the norm of ith (complex) eigenvalue.which eigenvalue to find the norm of i)
|
| public RealMatrix | Returns: the inverse matrix.Implements org. Get the inverse of the decomposed matrix. |
| public boolean | Returns: true if the decomposed matrix is non-singular.Implements org. Checks whether the decomposed matrix is non-singular. |
| public RealVector | Returns: a Vector X that minimizes the two norm of A × X - B.Right-hand side of the equation A × X = B. b)Implements org. Solves the linear equation A × X = B for symmetric matrices A. |
| public RealMatrix | solve(RealMatrix
right-hand side of the equation A × X = B b)Implements org. Solve the linear equation A × X = B for matrices A. |
| eigenvectors | back to summary |
|---|---|
| private final ArrayRealVector[] eigenvectors Eigenvectors. | |
| imagEigenvalues | back to summary |
|---|---|
| private double[] imagEigenvalues Imaginary part of the realEigenvalues. | |
| realEigenvalues | back to summary |
|---|---|
| private double[] realEigenvalues Real part of the realEigenvalues. | |
| Solver | back to summary |
|---|---|
| private Solver(final double[] realEigenvalues, final double[] imagEigenvalues, final ArrayRealVector[] eigenvectors) Builds a solver from decomposed matrix.
| |
| eigenvalueNorm | back to summary |
|---|---|
private double eigenvalueNorm(int i)
| |
| getInverse | back to summary |
|---|---|
| public RealMatrix getInverse() Implements org. Get the inverse of the decomposed matrix.
| |
| isNonSingular | back to summary |
|---|---|
| public boolean isNonSingular() Implements org. Checks whether the decomposed matrix is non-singular.
| |
| solve | back to summary |
|---|---|
| public RealVector solve(final RealVector b) Implements org. Solves the linear equation A × X = B for symmetric matrices A. This method only finds exact linear solutions, i.e. solutions for which ||A × X - B|| is exactly 0.
| |
| solve | back to summary |
|---|---|
| public RealMatrix solve(RealMatrix b) Implements org. Doc from org. Solve the linear equation A × X = B for matrices A. The A matrix is implicit, it is provided by the underlying decomposition algorithm.
| |