/** * <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 bool isPositiveDefinite(DMatrixRMaj A) { if (!isSquare(A)) { return(false); } CholeskyDecompositionInner_DDRM chol = new CholeskyDecompositionInner_DDRM(true); if (chol.inputModified()) { A = A.copy(); } return(chol.decompose(A)); }
/** * Creates a random distribution with the specified mean and covariance. The references * to the variables are not saved, their value are copied. * * @param rand Used to create the random numbers for the draw. Reference is saved. * @param cov The covariance of the distribution. Not modified. */ public CovarianceRandomDraw_DDRM(Random rand, DMatrixRMaj cov) { r = new DMatrixRMaj(cov.numRows, 1); CholeskyDecompositionInner_DDRM cholesky = new CholeskyDecompositionInner_DDRM(true); if (cholesky.inputModified()) { cov = cov.copy(); } if (!cholesky.decompose(cov)) { throw new SystemException("Decomposition failed!"); } A = cholesky.getT(); //this.rand = rand; this.rand = new Java.Util.Random(); }
/** * Creates a solver for symmetric positive definite matrices. * * @return A new solver for symmetric positive definite matrices. */ public static LinearSolverDense <DMatrixRMaj> symmPosDef(int matrixWidth) { if (matrixWidth < EjmlParameters.SWITCH_BLOCK64_CHOLESKY) { CholeskyDecompositionCommon_DDRM decomp = new CholeskyDecompositionInner_DDRM(true); return(new LinearSolverChol_DDRM(decomp)); } else { if (EjmlParameters.MEMORY == EjmlParameters.MemoryUsage.FASTER) { return(new LinearSolverChol_DDRB()); } else { CholeskyDecompositionCommon_DDRM decomp = new CholeskyDecompositionInner_DDRM(true); return(new LinearSolverChol_DDRM(decomp)); } } }