Exemplo 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));
        }
        /**
         * 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;
        }