Beispiel #1
0
        /// <summary>
        ///   Sets a region of a matrix to the given values.
        /// </summary>
        ///
        /// <param name="destination">The matrix where elements will be set.</param>
        /// <param name="value">The matrix of values to which matrix elements will be set.</param>
        /// <param name="startRow">Starting row index</param>
        /// <param name="endRow">End row index</param>
        /// <param name="startCol">Starting column index</param>
        /// <param name="endCol">End column index</param>
        ///
        public static void Set <T>(this T[,] destination, T value, int startRow, int endRow, int startCol, int endCol)
        {
            var values        = Matrix.Create <T>(destination.Rows(), destination.Columns(), value);
            var rowIndices    = Accord.Math.Vector.Range(startRow, end(endRow, destination.Rows()));
            var columnIndices = Accord.Math.Vector.Range(startCol, end(endCol, destination.Columns()));

            set(destination, rowIndices, columnIndices, values, rowIndices, columnIndices);
        }
Beispiel #2
0
        /// <summary>
        ///   Creates a centering matrix of size <c>N x N</c> in the
        ///   form <c>(I - 1N)</c> where <c>1N</c> is a matrix with
        ///   all elements equal to <c>1 / N</c>.
        /// </summary>
        public static double[,] Centering(int size)
        {
            if (size < 0)
            {
                throw new ArgumentOutOfRangeException("size", size,
                                                      "The size of the centering matrix must be a positive integer.");
            }

            double[,] C = Matrix.Create(size, -1.0 / size);

            for (int i = 0; i < size; i++)
            {
                C[i, i] = 1.0 - 1.0 / size;
            }

            return(C);
        }
Beispiel #3
0
 /// <summary>
 ///   Sets a region of a matrix to the given values.
 /// </summary>
 ///
 /// <param name="destination">The matrix where elements will be set.</param>
 /// <param name="value">The value to which matrix elements will be set.</param>
 ///
 public static void Set <T>(this T[,] destination, T value)
 {
     Set(destination, Matrix.Create(destination.Rows(), destination.Columns(), value));
 }
Beispiel #4
0
        /// <summary>
        ///   Sets a region of a matrix to the given values.
        /// </summary>
        ///
        /// <param name="destination">The matrix where elements will be set.</param>
        /// <param name="value">The matrix of values to which matrix elements will be set.</param>
        /// <param name="rowIndices">Array of row indices</param>
        /// <param name="columnIndices">Array of column indices</param>
        ///
        public static void Set <T>(this T[,] destination, T value, int[] rowIndices, int[] columnIndices)
        {
            var values = Matrix.Create <T>(destination.Rows(), destination.Columns(), value);

            set(destination, rowIndices, columnIndices, values, rowIndices, columnIndices);
        }
Beispiel #5
0
 /// <summary>
 ///   Sets a region of a matrix to the given values.
 /// </summary>
 ///
 /// <param name="destination">The matrix where elements will be set.</param>
 /// <param name="value">The matrix of values to which matrix elements will be set.</param>
 /// <param name="startRow">Starting row index</param>
 /// <param name="endRow">End row index</param>
 /// <param name="columnIndices">Array of column indices</param>
 ///
 public static void Set <T>(this T[,] destination, T value, int startRow, int endRow, int[] columnIndices)
 {
     T[,] source = Matrix.Create(destination.Rows(), destination.Columns(), value);
     Set(destination, source, startRow, endRow, columnIndices);
 }
Beispiel #6
0
 /// <summary>
 ///   Sets a region of a matrix to the given values.
 /// </summary>
 ///
 /// <param name="destination">The matrix where elements will be set.</param>
 /// <param name="value">The matrix of values to which matrix elements will be set.</param>
 /// <param name="rowIndices">Array of row indices</param>
 /// <param name="startColumn">Start column index</param>
 /// <param name="endColumn">End column index</param>
 ///
 public static void Set <T>(this T[,] destination, T value, int[] rowIndices, int startColumn, int endColumn)
 {
     T[,] source = Matrix.Create(destination.Rows(), destination.Columns(), value);
     Set(destination, source, rowIndices, startColumn, endColumn);
 }
Beispiel #7
0
 /// <summary>
 ///   Creates a centering matrix of size n x n in the form (I - 1n)
 ///   where 1n is a matrix with all entries 1/n.
 /// </summary>
 public static double[,] Centering(int size)
 {
     return(Matrix.Identity(size).Subtract(Matrix.Create(size, 1.0 / size)));
 }