コード例 #1
0
        public static bool isTranspose(DMatrixSparseCSC A, DMatrixSparseCSC B, double tol)
        {
            if (A.numCols != B.numRows || A.numRows != B.numCols)
            {
                return(false);
            }
            if (A.nz_length != B.nz_length)
            {
                return(false);
            }
            if (!A.indicesSorted)
            {
                throw new ArgumentException("A must have sorted indicies");
            }

            DMatrixSparseCSC Btran = new DMatrixSparseCSC(B.numCols, B.numRows, B.nz_length);

            CommonOps_DSCC.transpose(B, Btran, null);
            Btran.sortIndices(null);

            for (int i = 0; i < B.nz_length; i++)
            {
                if (A.nz_rows[i] != Btran.nz_rows[i])
                {
                    return(false);
                }
                if (Math.Abs(A.nz_values[i] - Btran.nz_values[i]) > tol)
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #2
0
        /**
         * <p>
         * Checks to see if a matrix is orthogonal or isometric.
         * </p>
         *
         * @param Q The matrix being tested. Not modified.
         * @param tol Tolerance.
         * @return True if it passes the test.
         */
        public static bool isOrthogonal(DMatrixSparseCSC Q, double tol)
        {
            if (Q.numRows < Q.numCols)
            {
                throw new ArgumentException("The number of rows must be more than or equal to the number of columns");
            }

            IGrowArray gw = new IGrowArray();
            DGrowArray gx = new DGrowArray();

            for (int i = 0; i < Q.numRows; i++)
            {
                for (int j = i + 1; j < Q.numCols; j++)
                {
                    double val = CommonOps_DSCC.dotInnerColumns(Q, i, Q, j, gw, gx);

                    if (!(Math.Abs(val) <= tol))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
コード例 #3
0
        public static DMatrixSparseCSC triangleUpper(int dimen, int hessenberg, int nz_total,
                                                     double min, double max, IMersenneTwister rand)
        {
            DMatrixSparseCSC L = triangleLower(dimen, hessenberg, nz_total, min, max, rand);
            DMatrixSparseCSC U = (DMatrixSparseCSC)L.createLike();

            CommonOps_DSCC.transpose(L, U, null);
            return(U);
        }
コード例 #4
0
ファイル: NormOps_DSCC.cs プロジェクト: lulzzz/BraneCloud
        public static double normF(DMatrixSparseCSC A)
        {
            double total = 0;
            double max   = CommonOps_DSCC.elementMaxAbs(A);

            for (int i = 0; i < A.nz_length; i++)
            {
                double x = A.nz_values[i] / max;
                total += x * x;
            }

            return(max * Math.Sqrt(total));
        }
コード例 #5
0
        /**
         * Creates a random symmetric positive definite matrix.
         * @param width number of columns and rows
         * @param nz_total Used to adjust number of non-zero values. Exact amount in matrix will be more than this.
         * @param rand random number generator
         * @return Random matrix
         */
        public static DMatrixSparseCSC symmetricPosDef(int width, int nz_total, IMersenneTwister rand)
        {
            DMatrixSparseCSC A = rectangle(width, width, nz_total, rand);

            // to ensure it's SPD assign non-zero values to all the diagonal elements
            for (int i = 0; i < width; i++)
            {
                A.set(i, i, Math.Max(0.5, rand.NextDouble()));
            }

            DMatrixSparseCSC spd = new DMatrixSparseCSC(width, width, 0);

            CommonOps_DSCC.multTransB(A, A, spd, null, null);


            return(spd);
        }