Ejemplo n.º 1
0
        /**
         * <p>
         * Checks to see if the matrix is positive definite.
         * </p>
         * <p>
         * x<sup>T</sup> A x &gt; 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(FMatrixRMaj A)
        {
            if (!isSquare(A))
            {
                return(false);
            }

            CholeskyDecompositionInner_FDRM chol = new CholeskyDecompositionInner_FDRM(true);

            if (chol.inputModified())
            {
                A = (FMatrixRMaj)A.copy();
            }

            return(chol.decompose(A));
        }
Ejemplo n.º 2
0
        /**
         * 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_FDRM(IMersenneTwister rand, FMatrixRMaj cov)
        {
            r = new FMatrixRMaj(cov.numRows, 1);
            CholeskyDecompositionInner_FDRM cholesky = new CholeskyDecompositionInner_FDRM(true);

            if (cholesky.inputModified())
            {
                cov = (FMatrixRMaj)cov.copy();
            }
            if (!cholesky.decompose(cov))
            {
                throw new InvalidOperationException("Decomposition failed!");
            }

            A         = cholesky.getT();
            this.rand = rand;
        }
Ejemplo n.º 3
0
 /**
  * Creates a solver for symmetric positive definite matrices.
  *
  * @return A new solver for symmetric positive definite matrices.
  */
 public static LinearSolverDense <FMatrixRMaj> symmPosDef(int matrixWidth)
 {
     if (matrixWidth < EjmlParameters.SWITCH_BLOCK64_CHOLESKY)
     {
         CholeskyDecompositionCommon_FDRM decomp = new CholeskyDecompositionInner_FDRM(true);
         return(new LinearSolverChol_FDRM(decomp));
     }
     else
     {
         if (EjmlParameters.MEMORY == EjmlParameters.MemoryUsage.FASTER)
         {
             return(new LinearSolverChol_FDRB());
         }
         else
         {
             CholeskyDecompositionCommon_FDRM decomp = new CholeskyDecompositionInner_FDRM(true);
             return(new LinearSolverChol_FDRM(decomp));
         }
     }
 }