コード例 #1
0
        /// <summary>
        /// Initializes a square <see cref="DiagonalMatrix"/> with all zero's except for ones on the diagonal.
        /// </summary>
        /// <param name="order">the size of the square matrix.</param>
        /// <returns>A diagonal identity matrix.</returns>
        /// <exception cref="ArgumentException">
        /// If <paramref name="order"/> is less than one.
        /// </exception>
        public static DiagonalMatrix Identity(int order)
        {
            var m = new DiagonalMatrix(order);

            for (var i = 0; i < order; i++)
            {
                m._data[i] = 1.0;
            }

            return(m);
        }
コード例 #2
0
ファイル: DiagonalMatrix.cs プロジェクト: sfukui/MNNPlus
 /// <summary>
 /// Returns the transpose of this matrix.
 /// </summary>        
 /// <returns>The transpose of this matrix.</returns>
 public override Matrix<double> Transpose()
 {
     var ret = new DiagonalMatrix(ColumnCount, RowCount);
     Buffer.BlockCopy(_data, 0, ret._data, 0, _data.Length * Constants.SizeOfDouble);
     return ret;
 }
コード例 #3
0
ファイル: DiagonalMatrix.cs プロジェクト: sfukui/MNNPlus
        /// <summary>
        /// Subtracts another matrix from this matrix.
        /// </summary>
        /// <param name="other">The matrix to subtract.</param>
        /// <returns>The result of the subtraction.</returns>
        /// <exception cref="ArgumentNullException">If the other matrix is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
        public override Matrix<double> Subtract(Matrix<double> other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            if (other.RowCount != RowCount || other.ColumnCount != ColumnCount)
            {
                throw DimensionsDontMatch<ArgumentOutOfRangeException>(this, other, "other");
            }

            Matrix<double> result;
            if (other is DiagonalMatrix)
            {
                result = new DiagonalMatrix(RowCount, ColumnCount);
            }
            else
            {
                result = new DenseMatrix(RowCount, ColumnCount);
            }

            Subtract(other, result);
            return result;
        }
コード例 #4
0
ファイル: DiagonalMatrix.cs プロジェクト: sfukui/MNNPlus
        /// <summary>
        /// Initializes a square <see cref="DiagonalMatrix"/> with all zero's except for ones on the diagonal.
        /// </summary>
        /// <param name="order">the size of the square matrix.</param>
        /// <returns>A diagonal identity matrix.</returns>
        /// <exception cref="ArgumentException">
        /// If <paramref name="order"/> is less than one.
        /// </exception>
        public static DiagonalMatrix Identity(int order)
        {
            var m = new DiagonalMatrix(order);
            for (var i = 0; i < order; i++)
            {
                m._data[i] = 1.0;
            }

            return m;
        }
コード例 #5
0
        public void CanGetSubMatrix_Issue35()
        {
            // [ 1 0 0 ]
            // [ 0 2 0 ]
            // [ 0 0 3 ]
            var diagMatrix = new DiagonalMatrix(3);
            for (int i = 0; i < 3; i++)
            {
                diagMatrix[i, i] = i + 1;
            }

            // [ 0 0 ]
            // [ 2 0 ]
            var subM2 = diagMatrix.SubMatrix(0, 2, 1, 2);
            Assert.IsTrue(subM2.Equals(Matrix<double>.Build.Dense(2, 2, new[] { 0d, 2d, 0d, 0d })));

            // [ 0 0 ]
            // [ 2 0 ]
            // [ 0 3 ]
            var subM3 = diagMatrix.SubMatrix(0, 3, 1, 2);
            Assert.IsTrue(subM3.Equals(Matrix<double>.Build.Dense(3, 2, new[] { 0d, 2d, 0d, 0d, 0d, 3d })));
        }
コード例 #6
0
 public void CanCreateMatrixWithUniformValues()
 {
     var matrix = new DiagonalMatrix(10, 10, 10.0);
     for (var i = 0; i < matrix.RowCount; i++)
     {
         Assert.AreEqual(matrix[i, i], 10.0);
     }
 }
コード例 #7
0
 public void MatrixFrom1DArrayIsReference()
 {
     var data = new double[] {1, 2, 3, 4, 5};
     var matrix = new DiagonalMatrix(5, 5, data);
     matrix[0, 0] = 10.0;
     Assert.AreEqual(10.0, data[0]);
 }
コード例 #8
0
        /// <summary>
        /// Adds another matrix to this matrix.
        /// </summary>
        /// <param name="other">The matrix to add to this matrix.</param>
        /// <returns>The result of the addition.</returns>
        /// <exception cref="ArgumentNullException">If the other matrix is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">If the two matrices don't have the same dimensions.</exception>
        public override Matrix<double> Add(Matrix<double> other)
        {
            if (other == null)
            {
                throw new ArgumentNullException("other");
            }

            if (other.RowCount != RowCount || other.ColumnCount != ColumnCount)
            {
                throw new ArgumentOutOfRangeException("other", Resources.ArgumentMatrixDimensions);
            }

            Matrix<double> result;
            if (other is DiagonalMatrix)
            {
                result = new DiagonalMatrix(RowCount, ColumnCount);
            }
            else
            {
                result = new DenseMatrix(RowCount, ColumnCount);
            }

            Add(other, result);
            return result;
        }
コード例 #9
0
ファイル: Form1.cs プロジェクト: room-340/CCS_Reader
 private double[] single_correction(double[] coefs, double xdata, double ydata, double zdata)
 {
     double[] result = new double[3];
     Matrix B = new DiagonalMatrix(3, 3, 1);
     Matrix A = new DenseMatrix(3, 3);
     A.At(0, 0, coefs[0]);
     A.At(0, 1, coefs[3]);
     A.At(0, 2, coefs[4]);
     A.At(1, 0, coefs[5]);
     A.At(1, 1, coefs[1]);
     A.At(1, 2, coefs[6]);
     A.At(2, 0, coefs[7]);
     A.At(2, 1, coefs[8]);
     A.At(2, 2, coefs[2]);
     Matrix B1 = Kalman_class.Matrix_Minus(B, A);
     Matrix C = new DenseMatrix(3, 1);
     C.At(0, 0, xdata);
     C.At(1, 0, ydata);
     C.At(2, 0, zdata);
     Matrix D = new DenseMatrix(3, 1);
     D.At(0, 0, coefs[9]);
     D.At(1, 0, coefs[10]);
     D.At(2, 0, coefs[11]);
     Matrix res = new DenseMatrix(3, 1);
     res = Kalman_class.Matrix_Mult(B1, Kalman_class.Matrix_Minus(C, D));
     result[0] = res.At(0, 0);
     result[1] = res.At(1, 0);
     result[2] = res.At(2, 0);
     return result;
 }