Esempio n. 1
0
        /**
         * <p>
         * The condition p = 2 number of a matrix is used to measure the sensitivity of the linear
         * system <b>Ax=b</b>.  A value near one indicates that it is a well conditioned matrix.<br>
         * <br>
         * &kappa;<sub>2</sub> = ||A||<sub>2</sub>||A<sup>-1</sup>||<sub>2</sub>
         * </p>
         * <p>
         * This is also known as the spectral condition number.
         * </p>
         *
         * @param A The matrix.
         * @return The condition number.
         */
        public static float conditionP2(FMatrixRMaj A)
        {
            SingularValueDecomposition_F32 <FMatrixRMaj> svd =
                DecompositionFactory_FDRM.svd(A.numRows, A.numCols, false, false, true);

            svd.decompose(A);

            float[] singularValues = svd.getSingularValues();

            int n = SingularOps_FDRM.rank(svd, UtilEjml.TEST_F32);

            if (n == 0)
            {
                return(0);
            }

            float smallest = float.MaxValue;
            float largest  = float.MinValue;

            foreach (float s in singularValues)
            {
                if (s < smallest)
                {
                    smallest = s;
                }
                if (s > largest)
                {
                    largest = s;
                }
            }

            return(largest / smallest);
        }
Esempio n. 2
0
        /**
         * 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));
        }