コード例 #1
0
        /// <summary>
        /// Computes the singular value decomposition of the matrix.
        /// </summary>
        /// <returns>The SVD of the matrix.</returns>
        public SingularValueDecomposition SingularValueDecomposition()
        {
            if (rows >= cols)
            {
                // copy the matrix so as not to distrub the original
                double[] copy = MatrixAlgorithms.Copy(store, offset, rowStride, colStride, rows, cols);

                // bidiagonalize it
                double[] a, b;
                MatrixAlgorithms.Bidiagonalize(copy, rows, cols, out a, out b);

                // form the U and V matrices
                double[] left  = MatrixAlgorithms.AccumulateBidiagonalU(copy, rows, cols);
                double[] right = MatrixAlgorithms.AccumulateBidiagonalV(copy, rows, cols);

                // find the singular values of the bidiagonal matrix
                MatrixAlgorithms.ExtractSingularValues(a, b, left, right, rows, cols);

                // sort them
                MatrixAlgorithms.SortValues(a, left, right, rows, cols);

                // package it all up
                return(new SingularValueDecomposition(left, a, right, rows, cols));
            }
            else
            {
                double[] scratch = MatrixAlgorithms.Transpose(store, rows, cols);

                double[] a, b;
                MatrixAlgorithms.Bidiagonalize(scratch, cols, rows, out a, out b);

                double[] left  = MatrixAlgorithms.AccumulateBidiagonalU(scratch, cols, rows);
                double[] right = MatrixAlgorithms.AccumulateBidiagonalV(scratch, cols, rows);

                MatrixAlgorithms.ExtractSingularValues(a, b, left, right, cols, rows);

                MatrixAlgorithms.SortValues(a, left, right, cols, rows);

                left  = MatrixAlgorithms.Transpose(left, cols, cols);
                right = MatrixAlgorithms.Transpose(right, rows, rows);

                return(new SingularValueDecomposition(right, a, left, rows, cols));
            }
        }
コード例 #2
0
 /// <summary>
 /// Returns the transpose of the matrix.
 /// </summary>
 /// <returns>M<sup>T</sup></returns>
 public RectangularMatrix Transpose()
 {
     double[] tStore = MatrixAlgorithms.Transpose(store, rows, cols);
     return(new RectangularMatrix(tStore, cols, rows));
 }
コード例 #3
0
        /*
         * IMatrix IMatrix.Clone () {
         *  return (Clone());
         * }
         */

        /// <summary>
        /// Creates a transpose of the matrix.
        /// </summary>
        /// <returns>The matrix transpose M<sup>T</sup>.</returns>
        public SquareMatrix Transpose()
        {
            double[] tStore = MatrixAlgorithms.Transpose(store, dimension, dimension);
            return(new SquareMatrix(tStore, dimension));
        }
コード例 #4
0
 /// <summary>
 /// The orthogonal matrix Q.
 /// </summary>
 /// <returns>The orthogonal matrix Q.</returns>
 public SquareMatrix QMatrix()
 {
     double[] qStore = MatrixAlgorithms.Transpose(qtStore, dimension, dimension);
     return(new SquareMatrix(qStore, dimension));
 }
コード例 #5
0
 /// <summary>
 /// Returns the left transform matrix.
 /// </summary>
 /// <returns>The matrix U, such that A = U S V<sup>T</sup>.</returns>
 public SquareMatrix LeftTransformMatrix()
 {
     double[] left = MatrixAlgorithms.Transpose(utStore, rows, rows);
     return(new SquareMatrix(left, rows));
 }