/** * * @param computeVectors * @param tol Tolerance for a matrix being symmetric */ public SwitchingEigenDecomposition( int matrixSize , boolean computeVectors , double tol ) { symmetricAlg = DecompositionFactory.eig(matrixSize,computeVectors,true); generalAlg = DecompositionFactory.eig(matrixSize,computeVectors,false); this.computeVectors = computeVectors; this.tol = tol; }
/** * * @param computeVectors * @param tol Tolerance for a matrix being symmetric */ public SwitchingEigenDecomposition( int matrixSize , boolean computeVectors , double tol ) { symmetricAlg = DecompositionFactory.eig(matrixSize,computeVectors,true); generalAlg = DecompositionFactory.eig(matrixSize,computeVectors,false); this.computeVectors = computeVectors; this.tol = tol; }
/** * * @param computeVectors * @param tol Tolerance for a matrix being symmetric */ public SwitchingEigenDecomposition( int matrixSize , boolean computeVectors , double tol ) { symmetricAlg = DecompositionFactory.eig(matrixSize,computeVectors,true); generalAlg = DecompositionFactory.eig(matrixSize,computeVectors,false); this.computeVectors = computeVectors; this.tol = tol; }
public SimpleEVD( DenseMatrix64F mat ) { this.mat = mat; eig = DecompositionFactory.eig(mat.numCols,true); if( !eig.decompose(mat)) throw new RuntimeException("Eigenvalue Decomposition failed"); }
public SimpleEVD( DenseMatrix64F mat ) { this.mat = mat; eig = DecompositionFactory.eig(mat.numCols,true); if( !eig.decompose(mat)) throw new RuntimeException("Eigenvalue Decomposition failed"); }
public SimpleEVD( DenseMatrix64F mat ) { this.mat = mat; eig = DecompositionFactory.eig(mat.numCols,true); if( !eig.decompose(mat)) throw new RuntimeException("Eigenvalue Decomposition failed"); }
private static void checkEigenValuesRealAndPositive(Matrix3D matrix, double epsilon) { DenseMatrix64F denseMatrix = new DenseMatrix64F(3, 3); matrix.get(denseMatrix); EigenDecomposition<DenseMatrix64F> eig = DecompositionFactory.eig(3, false); eig.decompose(denseMatrix); for (int i = 0; i < eig.getNumberOfEigenvalues(); i++) { double eigImaginaryPart = eig.getEigenvalue(i).getImaginary(); double eigRealPart = eig.getEigenvalue(i).getReal(); if (!EuclidCoreTools.epsilonEquals(0.0, eigImaginaryPart, epsilon)) throw new RuntimeException("The matrix has at least one imaginary eigen value."); if (eigRealPart <= 0.0) throw new RuntimeException("The matrix has at least one non-positive eigen value."); } } }
private static Complex64F[] findRoots(double... coefficients) { int N = coefficients.length - 1; // Construct the companion matrix. This is a square N x N matrix. final DenseMatrix64F c = new DenseMatrix64F(N, N); double a = coefficients[N]; for (int i = 0; i < N; i++) { c.set(i, N - 1, -coefficients[i] / a); } for (int i = 1; i < N; i++) { c.set(i, i - 1, 1); } // Use generalized eigenvalue decomposition to find the roots. EigenDecomposition<DenseMatrix64F> evd = DecompositionFactory.eig(N, false); evd.decompose(c); final Complex64F[] roots = new Complex64F[N]; for (int i = 0; i < N; i++) { roots[i] = evd.getEigenvalue(i); } return roots; }
/** * <p> * Checks to see if the matrix is positive semidefinite: * </p> * <p> * x<sup>T</sup> A x >= 0<br> * for all x where x is a non-zero vector and A is a symmetric matrix. * </p> * * @param A square symmetric matrix. Not modified. * * @return True if it is positive semidefinite and false if it is not. */ public static boolean isPositiveSemidefinite( DenseMatrix64F A ) { if( !isSquare(A)) return false; EigenDecomposition<DenseMatrix64F> eig = DecompositionFactory.eig(A.numCols,false); if( eig.inputModified() ) A = A.copy(); eig.decompose(A); for( int i = 0; i < A.numRows; i++ ) { Complex64F v = eig.getEigenvalue(i); if( v.getReal() < 0 ) return false; } return true; }
/** * <p> * Checks to see if the matrix is positive semidefinite: * </p> * <p> * x<sup>T</sup> A x >= 0<br> * for all x where x is a non-zero vector and A is a symmetric matrix. * </p> * * @param A square symmetric matrix. Not modified. * * @return True if it is positive semidefinite and false if it is not. */ public static boolean isPositiveSemidefinite( DenseMatrix64F A ) { if( !isSquare(A)) return false; EigenDecomposition<DenseMatrix64F> eig = DecompositionFactory.eig(A.numCols,false); if( eig.inputModified() ) A = A.copy(); eig.decompose(A); for( int i = 0; i < A.numRows; i++ ) { Complex64F v = eig.getEigenvalue(i); if( v.getReal() < 0 ) return false; } return true; }
/** * <p> * Checks to see if the matrix is positive semidefinite: * </p> * <p> * x<sup>T</sup> A x >= 0<br> * for all x where x is a non-zero vector and A is a symmetric matrix. * </p> * * @param A square symmetric matrix. Not modified. * * @return True if it is positive semidefinite and false if it is not. */ public static boolean isPositiveSemidefinite( DenseMatrix64F A ) { if( !isSquare(A)) return false; EigenDecomposition<DenseMatrix64F> eig = DecompositionFactory.eig(A.numCols,false); if( eig.inputModified() ) A = A.copy(); eig.decompose(A); for( int i = 0; i < A.numRows; i++ ) { Complex64F v = eig.getEigenvalue(i); if( v.getReal() < 0 ) return false; } return true; }
public Matrix[] eig() { EigenDecomposition<DenseMatrix64F> eig = DecompositionFactory.eig(matrix.numCols, true); eig.decompose(matrix); int N = matrix.numRows; DenseMatrix64F D = new DenseMatrix64F(N, N); DenseMatrix64F V = new DenseMatrix64F(N, N); for (int i = 0; i < N; i++) { Complex64F c = eig.getEigenvalue(i); if (c.isReal()) { D.set(i, i, c.real); Matrix64F v = eig.getEigenVector(i); if (v != null) { for (int j = 0; j < N; j++) { V.set(j, i, v.get(j, 0)); } } } } Matrix v = new EJMLDenseDoubleMatrix2D(V); Matrix d = new EJMLDenseDoubleMatrix2D(D); return new Matrix[] { v, d }; }