/**
         * <p>
         * Checks to see if the matrix is positive semidefinite:
         * </p>
         * <p>
         * x<sup>T</sup> A x &ge; 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 bool isPositiveSemidefinite(FMatrixRMaj A)
        {
            if (!isSquare(A))
            {
                return(false);
            }

            EigenDecomposition_F32 <FMatrixRMaj> eig = DecompositionFactory_FDRM.eig(A.numCols, false);

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

            for (int i = 0; i < A.numRows; i++)
            {
                Complex_F32 v = eig.getEigenvalue(i);

                if (v.getReal() < 0)
                {
                    return(false);
                }
            }

            return(true);
        }
        /**
         * <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;
        }
        /**
         * Computes the nullity of a matrix using the specified tolerance.
         *
         * @param A Matrix whose rank is to be calculated.  Not modified.
         * @param threshold The numerical threshold used to determine a singular value.
         * @return The matrix's nullity.
         */
        public static int nullity(FMatrixRMaj A, float threshold)
        {
            SingularValueDecomposition_F32 <FMatrixRMaj> svd =
                DecompositionFactory_FDRM.svd(A.numRows, A.numCols, false, false, true);

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

            if (!svd.decompose(A))
            {
                throw new InvalidOperationException("Decomposition failed");
            }

            return(SingularOps_FDRM.nullity(svd, threshold));
        }
        /**
         * Checks to see if the rows of the provided matrix are linearly independent.
         *
         * @param A Matrix whose rows are being tested for linear independence.
         * @return true if linearly independent and false otherwise.
         */
        public static bool isRowsLinearIndependent(FMatrixRMaj A)
        {
            // LU decomposition
            LUDecomposition <FMatrixRMaj> lu = DecompositionFactory_FDRM.lu(A.numRows, A.numCols);

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

            if (!lu.decompose(A))
            {
                throw new InvalidOperationException("Decompositon failed?");
            }

            // if they are linearly independent it should not be singular
            return(!lu.isSingular());
        }
Exemple #6
0
        public void setup(FMatrixRMaj A)
        {
            if (A.numRows != A.numCols)
            {
                throw new InvalidOperationException("Must be square");
            }

            if (N != A.numRows)
            {
                N = A.numRows;

                this.A = (FMatrixRMaj)A.copy();
                u      = new FMatrixRMaj(A.numRows, 1);

                _temp        = new FMatrixRMaj(A.numRows, 1);
                numStepsFind = new int[A.numRows];
            }
            else
            {
                this.A.set(A);
                UtilEjml.memset(numStepsFind, 0, numStepsFind.Length);
            }

            // zero all the off numbers that should be zero for a hessenberg matrix
            for (int i = 2; i < N; i++)
            {
                for (int j = 0; j < i - 1; j++)
                {
                    this.A.set(i, j, 0);
                }
            }

            eigenvalues = new Complex_F32[A.numRows];
            for (int i = 0; i < eigenvalues.Length; i++)
            {
                eigenvalues[i] = new Complex_F32();
            }

            numEigen        = 0;
            lastExceptional = 0;
            numExceptional  = 0;
            steps           = 0;
        }