public static void checkSquare(DenseMatrix64F m) { if (!MatrixFeatures.isSquare(m)) throw new RuntimeException("Matrix is not square: " + m); }
public static void checkSquare(DenseMatrix64F m) { if (!MatrixFeatures.isSquare(m)) throw new RuntimeException("Matrix is not square: " + m); }
/** * <p> * Checks to see if the matrix is positive definite. * </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 definite and false if it is not. */ public static boolean isPositiveDefinite( DenseMatrix64F A ) { if( !isSquare(A)) return false; CholeskyDecompositionInner_D64 chol = new CholeskyDecompositionInner_D64(true); if( chol.inputModified() ) A = A.copy(); return chol.decompose(A); }
/** * <p> * Checks to see if the matrix is positive definite. * </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 definite and false if it is not. */ public static boolean isPositiveDefinite( DenseMatrix64F A ) { if( !isSquare(A)) return false; CholeskyDecompositionInner_D64 chol = new CholeskyDecompositionInner_D64(true); if( chol.inputModified() ) A = A.copy(); return chol.decompose(A); }
/** * <p> * Checks to see if the matrix is positive definite. * </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 definite and false if it is not. */ public static boolean isPositiveDefinite( DenseMatrix64F A ) { if( !isSquare(A)) return false; CholeskyDecompositionInner_D64 chol = new CholeskyDecompositionInner_D64(true); if( chol.inputModified() ) A = A.copy(); return chol.decompose(A); }
/** * <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; }