Exemplo n.º 1
0
        /**
         * <p>
         * Used to retrieve real valued eigenvectors.  If an eigenvector is associated with a complex eigenvalue
         * then null is returned instead.
         * </p>
         *
         * @param index Index of the eigenvalue eigenvector pair.
         * @return If the associated eigenvalue is real then an eigenvector is returned, null otherwise.
         */
        public SimpleBase <T> getEigenVector(int index)
        {
            T v = eig.getEigenVector(index);

            if (v == null)
            {
                return(null);
            }
            return(SimpleMatrix <T> .wrap(v));
        }
Exemplo n.º 2
0
        public /**/ double quality()
        {
            if (is64)
            {
                var m   = mat as DMatrixRMaj;
                var um  = U.getMatrix() as DMatrixRMaj;
                var wm  = W.getMatrix() as DMatrixRMaj;
                var vmt = V.transpose().getMatrix() as DMatrixRMaj;
                return(DecompositionFactory_DDRM.quality(m, um, wm, vmt));
            }
            else
            {
                var m   = mat as FMatrixRMaj;
                var um  = U.getMatrix() as FMatrixRMaj;
                var wm  = W.getMatrix() as FMatrixRMaj;
                var vmt = V.transpose().getMatrix() as FMatrixRMaj;
                return(DecompositionFactory_FDRM.quality(m, um, wm, vmt));
            }
        }

        /**
         * Computes the null space from an SVD.  For more information see {@link SingularOps_DDRM#nullSpace}.
         * @return Null space vector.
         */
        public SimpleMatrix <T> nullSpace()
        {
            // TODO take advantage of the singular values being ordered already
            if (is64)
            {
                var ns = SingularOps_DDRM.nullSpace((SingularValueDecomposition_F64 <DMatrixRMaj>)svd,
                                                    null, tol);
                return(SimpleMatrix <T> .wrap(ns as T));
            }
            else
            {
                var ns = SingularOps_FDRM.nullSpace((SingularValueDecomposition_F32 <FMatrixRMaj>)svd,
                                                    null, (float)tol);
                return(SimpleMatrix <T> .wrap(ns as T));
            }
        }
Exemplo n.º 3
0
        public SimpleSVD(Matrix mat, bool compact)
        {
            this.mat  = mat;
            this.is64 = mat is DMatrixRMaj;
            if (is64)
            {
                DMatrixRMaj m = (DMatrixRMaj)mat;
                svd = (SingularValueDecomposition <T>)DecompositionFactory_DDRM.svd(m.numRows, m.numCols, true, true, compact);
            }
            else
            {
                FMatrixRMaj m = (FMatrixRMaj)mat;
                svd = (SingularValueDecomposition <T>)DecompositionFactory_FDRM.svd(m.numRows, m.numCols, true, true, compact);
            }

            if (!svd.decompose((T)mat))
            {
                throw new InvalidOperationException("Decomposition failed");
            }
            U = SimpleMatrix <T> .wrap(svd.getU(null, false));

            W = SimpleMatrix <T> .wrap(svd.getW(null));

            V = SimpleMatrix <T> .wrap(svd.getV(null, false));

            // order singular values from largest to smallest
            if (is64)
            {
                var um = U.getMatrix() as DMatrixRMaj;
                var wm = W.getMatrix() as DMatrixRMaj;
                var vm = V.getMatrix() as DMatrixRMaj;
                SingularOps_DDRM.descendingOrder(um, false, wm, vm, false);
                tol = SingularOps_DDRM.singularThreshold((SingularValueDecomposition_F64 <DMatrixRMaj>)svd);
            }
            else
            {
                var um = U.getMatrix() as FMatrixRMaj;
                var wm = W.getMatrix() as FMatrixRMaj;
                var vm = V.getMatrix() as FMatrixRMaj;
                SingularOps_FDRM.descendingOrder(um, false, wm, vm, false);
                tol = SingularOps_FDRM.singularThreshold((SingularValueDecomposition_F32 <FMatrixRMaj>)svd);
            }
        }
Exemplo n.º 4
0
        /**
         * <p>Converts the block matrix into a SimpleMatrix.</p>
         *
         * @param A Block matrix that is being converted.  Not modified.
         * @return Equivalent SimpleMatrix.
         */
        public static SimpleMatrix <T> convertSimple <T>(DMatrixRBlock A) where T : class, Matrix
        {
            var B = ConvertDMatrixStruct.convert(A, null) as T;

            return(SimpleMatrix <T> .wrap(B));
        }