/// <summary>
        /// Creates a matrix which contains values from the requested sub-matrix
        /// </summary>
        /// <param name="rowsToInclude">A list of the keys of rows to include in the new matrix</param>
        /// <param name="columnsToInclude">A list of the keys of columns to include in the new matrix</param>
        /// <returns>A KeyedMatrix which contains values from the requested sub-matrix</returns>
        public KeyedRowColumnMatrix <TRowKey, TColumnKey> SubMatrix(IList <TRowKey> rowsToInclude, IList <TColumnKey> columnsToInclude)
        {
            KeyedRowColumnMatrix <TRowKey, TColumnKey> subMatrix = new KeyedRowColumnMatrix <TRowKey, TColumnKey>(rowsToInclude, columnsToInclude);

            foreach (TRowKey rowKey in rowsToInclude)
            {
                foreach (TColumnKey columnKey in columnsToInclude)
                {
                    subMatrix.At(rowKey, columnKey, this.At(rowKey, columnKey));
                }
            }

            return(subMatrix);
        }
Example #2
0
        public new KeyedSquareMatrix <TKey> NormalizeRows(int p)
        {
            KeyedRowColumnMatrix <TKey, TKey> result = base.NormalizeRows(p);

            return(new KeyedSquareMatrix <TKey>(result));
        }
Example #3
0
        public KeyedSquareMatrix <TKey> TransposeThisAndMultiply(KeyedSquareMatrix <TKey> other)
        {
            KeyedRowColumnMatrix <TKey, TKey> result = base.TransposeThisAndMultiply(other);

            return(new KeyedSquareMatrix <TKey>(result));
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public new KeyedSquareMatrix <TKey> Transpose()
        {
            KeyedRowColumnMatrix <TKey, TKey> result = base.Transpose();

            return(new KeyedSquareMatrix <TKey>(result));
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public new KeyedSquareMatrix <TKey> Inverse()
        {
            KeyedRowColumnMatrix <TKey, TKey> result = base.Inverse();

            return(new KeyedSquareMatrix <TKey>(result));
        }
Example #6
0
        public KeyedSquareMatrix <TKey> Add(KeyedSquareMatrix <TKey> other)
        {
            KeyedRowColumnMatrix <TKey, TKey> result = base.Add(other);

            return(new KeyedSquareMatrix <TKey>(result));
        }
Example #7
0
        public new KeyedSquareMatrix <TKey> Multiply(double scalar)
        {
            KeyedRowColumnMatrix <TKey, TKey> result = base.Multiply(scalar);

            return(new KeyedSquareMatrix <TKey>(result));
        }
Example #8
0
 public KeyedSquareMatrix(KeyedRowColumnMatrix <TKey, TKey> matrix)
     : base(matrix)
 {
     // empty
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="KeyedMatrix{TKey}" /> class.
 /// </summary>
 /// <param name="matrix">The matrix which holds the keys and data to copy into this new matrix</param>
 protected KeyedRowColumnMatrix(KeyedRowColumnMatrix <TRowKey, TColumnKey> matrix)
     : this(matrix.keysForRows, matrix.keysForColumns, matrix.underlyingMatrix)
 {
     // empty
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="KeyedMatrix{TKey}" /> class.
        /// </summary>
        /// <param name="matrix">The matrix which holds the keys and data to copy into this new matrix</param>
        protected KeyedRowColumnMatrix(IList <TRowKey> rowKeys, IList <TColumnKey> columnKeys, KeyedRowColumnMatrix <TRowKey, TColumnKey> matrix)
        {
            IEnumerable <TRowKey>    unionOfRowKeys    = rowKeys.Union(matrix.RowKeys);
            IEnumerable <TColumnKey> unionOfColumnKeys = columnKeys.Union(matrix.ColumnKeys);

            this.CheckAndAddKeys(unionOfRowKeys, unionOfColumnKeys);
            foreach (TRowKey rowKey in matrix.RowKeys)
            {
                foreach (TColumnKey columnKey in matrix.ColumnKeys)
                {
                    this.At(rowKey, columnKey, matrix.At(rowKey, columnKey));
                }
            }
        }
        public KeyedRowColumnMatrix <TColumnKey, TOtherColumnKey> TransposeThisAndMultiply <TOtherColumnKey>(KeyedRowColumnMatrix <TRowKey, TOtherColumnKey> other)
        {
            Matrix <double> result = this.underlyingMatrix.TransposeThisAndMultiply(other.underlyingMatrix);

            return(new KeyedRowColumnMatrix <TColumnKey, TOtherColumnKey>(this.keysForColumns, other.keysForColumns, result));
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="other"></param>
        /// <returns></returns>
        public KeyedRowColumnMatrix <TRowKey, TOtherColumnKey> Multiply <TOtherRowKey, TOtherColumnKey>(KeyedRowColumnMatrix <TOtherRowKey, TOtherColumnKey> other)
        {
            KeyCompatibilityValidator <TColumnKey, TOtherRowKey> kcv = new KeyCompatibilityValidator <TColumnKey, TOtherRowKey>(this.ColumnKeys, other.RowKeys);

            kcv.ThrowIfInvalid();

            ////FIXME If the column keys and other row keys are compatible but are stored or returned in the wrong order then this will return the wrong results.  Need to swap the vector items and keys to match exactly

            Matrix <double> multipliedUnderlyingMatrix = this.underlyingMatrix.Multiply(other.underlyingMatrix);

            return(new KeyedRowColumnMatrix <TRowKey, TOtherColumnKey>(this.keysForRows, other.keysForColumns, multipliedUnderlyingMatrix));
        }
        public KeyedRowColumnMatrix <TRowKey, TColumnKey> Add(KeyedRowColumnMatrix <TRowKey, TColumnKey> other)
        {
            Matrix <double> result = this.underlyingMatrix.Add(other.underlyingMatrix);

            return(new KeyedRowColumnMatrix <TRowKey, TColumnKey>(this.keysForRows, this.keysForColumns, result));
        }