Class Matrix
A matrix.
Inheritance
Inherited Members
Namespace:numl.Math.LinearAlgebra
Assembly:numl.dll
Syntax
public class Matrix
Constructors
View SourceMatrix(Double[][])
Create matrix n x n matrix.
Declaration
public Matrix(double[][] m)
Parameters
Type | Name | Description |
---|---|---|
System.Double[][] | m | initial matrix. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the requested operation is invalid. |
Matrix(Double[,])
Create new matrix with prepopulated vals.
Declaration
public Matrix(double[, ] m)
Parameters
Type | Name | Description |
---|---|---|
System.Double[,] | m | initial matrix. |
Matrix(Int32)
Create matrix n x n matrix.
Declaration
public Matrix(int n)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | n | size. |
Matrix(Int32, Int32)
Create new n x d matrix.
Declaration
public Matrix(int n, int d)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | n | rows. |
System.Int32 | d | cols. |
Properties
View SourceCols
Gets or sets the cols.
Declaration
public int Cols { get; }
Property Value
Type | Description |
---|---|
System.Int32 | The cols. |
Item[IEnumerable<Int32[]>]
Indexer to set items within this collection using an n x 2 array of indices to set.
Declaration
public double this[IEnumerable<int[]> slice] { set; }
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<System.Int32[]> | slice | An n x 2 array of indices to set. |
Property Value
Type | Description |
---|---|
System.Double |
Item[Func<Vector, Boolean>, VectorType]
Indexer to get items within this collection using array index syntax.
Declaration
public Matrix this[Func<Vector, bool> f, VectorType t] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.Func<Vector, System.Boolean> | f | The Func<Vector,bool> to process. |
VectorType | t | The VectorType to process. |
Property Value
Type | Description |
---|---|
Matrix | The indexed item. |
Item[Func<Double, Boolean>]
Indexer to set items within this collection using array index syntax.
Declaration
public double this[Func<double, bool> f] { set; }
Parameters
Type | Name | Description |
---|---|---|
System.Func<System.Double, System.Boolean> | f | The Func<double,bool> to process. |
Property Value
Type | Description |
---|---|
System.Double | The indexed item. |
Item[Int32]
Returns row vector specified at index i.
Declaration
public virtual Vector this[int i] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | row index. |
Property Value
Type | Description |
---|---|
Vector | The indexed item. |
Item[Int32, VectorType]
returns col/row vector at index j.
Declaration
public virtual Vector this[int i, VectorType t] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | Col/Row. |
VectorType | t | Row or Column. |
Property Value
Type | Description |
---|---|
Vector | Vector. |
Item[Int32, Int32]
Accessor.
Declaration
public virtual double this[int i, int j] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | Row. |
System.Int32 | j | Column. |
Property Value
Type | Description |
---|---|
System.Double | The indexed item. |
Rows
Gets or sets the rows.
Declaration
public int Rows { get; }
Property Value
Type | Description |
---|---|
System.Int32 | The rows. |
T
Returns read-only transpose (uses matrix reference to save space) It will throw an exception if there is an attempt to write to the matrix.
Declaration
public Matrix T { get; }
Property Value
Type | Description |
---|---|
Matrix | The t. |
Methods
View SourceCenter(VectorType)
In place centering. WARNING: WILL UPDATE MATRIX!
Declaration
public Matrix Center(VectorType t)
Parameters
Type | Name | Description |
---|---|---|
VectorType | t | . |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
Cholesky(Matrix)
Cholesky Factorization of a Matrix.
Declaration
public static Matrix Cholesky(Matrix m)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m | Input Matrix. |
Returns
Type | Description |
---|---|
Matrix | Cholesky Faxtorization (R.T would be other matrix) |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the requested operation is invalid. |
SingularMatrixException | Thrown when a Singular Matrix error condition occurs. |
Col(Int32)
Cols.
Declaration
public Vector Col(int i)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | Zero-based index of the. |
Returns
Type | Description |
---|---|
Vector | A Vector. |
Copy()
create deep copy of matrix.
Declaration
public Matrix Copy()
Returns
Type | Description |
---|---|
Matrix | Matrix. |
Correlation(Matrix, VectorType)
Correlations.
Declaration
public static Matrix Correlation(Matrix source, VectorType t = VectorType.Col)
Parameters
Type | Name | Description |
---|---|---|
Matrix | source | Source for the. |
VectorType | t | (Optional) Row or Column sum. |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
Covariance(Matrix, VectorType)
Covariances.
Declaration
public static Matrix Covariance(Matrix source, VectorType t = VectorType.Col)
Parameters
Type | Name | Description |
---|---|---|
Matrix | source | Source for the. |
VectorType | t | (Optional) Row or Column sum. |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
CovarianceDiag(Matrix, VectorType)
Covariance diagram.
Declaration
public static Vector CovarianceDiag(Matrix source, VectorType t = VectorType.Col)
Parameters
Type | Name | Description |
---|---|---|
Matrix | source | Source for the. |
VectorType | t | (Optional) Row or Column sum. |
Returns
Type | Description |
---|---|
Vector | A Vector. |
Create(Int32, Func<Double>)
Creates a new Matrix.
Declaration
public static Matrix Create(int n, Func<double> f)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | n | Size. |
System.Func<System.Double> | f | The Func<int,int,double> to process. |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
Create(Int32, Func<Int32, Int32, Double>)
Creates a new Matrix.
Declaration
public static Matrix Create(int n, Func<int, int, double> f)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | n | Size. |
System.Func<System.Int32, System.Int32, System.Double> | f | The Func<int,int,double> to process. |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
Create(Int32, Int32, Func<Double>)
Creates a new Matrix.
Declaration
public static Matrix Create(int n, int d, Func<double> f)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | n | Size. |
System.Int32 | d | cols. |
System.Func<System.Double> | f | The Func<int,int,double> to process. |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
Create(Int32, Int32, Func<Int32, Int32, Double>)
Creates a new Matrix.
Declaration
public static Matrix Create(int n, int d, Func<int, int, double> f)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | n | Size. |
System.Int32 | d | cols. |
System.Func<System.Int32, System.Int32, System.Double> | f | The Func<int,int,double> to process. |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
Det(Matrix)
Dets the given x coordinate.
Declaration
public static double Det(Matrix x)
Parameters
Type | Name | Description |
---|---|---|
Matrix | x | Matrix x. |
Returns
Type | Description |
---|---|
System.Double | A double. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the requested operation is invalid. |
Diag(Matrix)
Diagrams the given m.
Declaration
public static Vector Diag(Matrix m)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m | Input Matrix. |
Returns
Type | Description |
---|---|
Vector | A Vector. |
Dot(Matrix, Vector)
Dot product between a matrix and a vector.
Declaration
public static Vector Dot(Matrix x, Vector v)
Parameters
Type | Name | Description |
---|---|---|
Matrix | x | Matrix x. |
Vector | v | Vector v. |
Returns
Type | Description |
---|---|
Vector | Vector dot product. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the requested operation is invalid. |
Dot(Vector, Matrix)
Dot product between a matrix and a vector.
Declaration
public static Vector Dot(Vector v, Matrix x)
Parameters
Type | Name | Description |
---|---|---|
Vector | v | Vector v. |
Matrix | x | Matrix x. |
Returns
Type | Description |
---|---|
Vector | Vector dot product. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the requested operation is invalid. |
Each(Matrix, Matrix, Func<Double, Double, Double>)
Performs an element-wise operation on the input Matrices.
Declaration
public static Matrix Each(Matrix m1, Matrix m2, Func<double, double, double> fnElementWiseOp)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m1 | First Matrix. |
Matrix | m2 | Second Matrix. |
System.Func<System.Double, System.Double, System.Double> | fnElementWiseOp | Operation to perform on the value from the first and second matrices. |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
Each(Matrix, Func<Double, Double>)
Performs an element wise operation on the input Matrix.
Declaration
public static Matrix Each(Matrix m, Func<double, double> fnElementWiseOp)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m | Matrix. |
System.Func<System.Double, System.Double> | fnElementWiseOp | Function to apply. |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
Each(Matrix, Func<Double, Int32, Int32, Double>)
Performs an element wise operation on the input Matrix.
Declaration
public static Matrix Each(Matrix m, Func<double, int, int, double> fnElementWiseOp)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m | Matrix. |
System.Func<System.Double, System.Int32, System.Int32, System.Double> | fnElementWiseOp | Function to update each cell specified by the value and cell coordinates. |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
Equals(Matrix, Double)
Determines whether the specified System.Object is equal to the current System.Object.
Declaration
public bool Equals(Matrix m, double tol)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m | initial matrix. |
System.Double | tol | Double to be compared. |
Returns
Type | Description |
---|---|
System.Boolean | true if the specified System.Object is equal to the current System.Object; otherwise, false. |
Equals(Object)
Determines whether the specified System.Object is equal to the current System.Object.
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | The object to compare with the current object. |
Returns
Type | Description |
---|---|
System.Boolean | true if the specified System.Object is equal to the current System.Object; otherwise, false. |
Overrides
Evd(Matrix)
Eigen Decomposition.
Declaration
public static Tuple<Vector, Matrix> Evd(Matrix A)
Parameters
Type | Name | Description |
---|---|---|
Matrix | A | Input Matrix. |
Returns
Type | Description |
---|---|
System.Tuple<Vector, Matrix> | Tuple(Eigen Values, Eigen Vectors) |
Extract(Matrix, Int32, Int32, Int32, Int32, Boolean)
Extracts this object.
Declaration
public static Matrix Extract(Matrix m, int x, int y, int width, int height, bool safe = true)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m | Input Matrix. |
System.Int32 | x | Matrix x. |
System.Int32 | y | The y coordinate. |
System.Int32 | width | The width. |
System.Int32 | height | The height. |
System.Boolean | safe | (Optional) true to safe. |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
FrobeniusNorm(Matrix)
Matrix Frobenius Norm.
Declaration
public static double FrobeniusNorm(Matrix A)
Parameters
Type | Name | Description |
---|---|---|
Matrix | A | Input Matrix. |
Returns
Type | Description |
---|---|
System.Double | Frobenius Norm (double) |
GetCols()
Gets the cols in this collection.
Declaration
public IEnumerable<Vector> GetCols()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Vector> | An enumerator that allows foreach to be used to process the cols in this collection. |
GetHashCode()
Serves as a hash function for a particular type.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 | A hash code for the current System.Object. |
Overrides
GetMatrix(Int32, Int32, Int32, Int32)
Gets a matrix.
Declaration
public Matrix GetMatrix(int d1, int d2, int n1, int n2)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | d1 | The first int. |
System.Int32 | d2 | The second int. |
System.Int32 | n1 | The first int. |
System.Int32 | n2 | The second int. |
Returns
Type | Description |
---|---|
Matrix | The matrix. |
GetRows()
Gets the rows in this collection.
Declaration
public IEnumerable<Vector> GetRows()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Vector> | An enumerator that allows foreach to be used to process the rows in this collection. |
GetVector(Int32, Int32, Int32, VectorType)
Gets a vector.
Declaration
public Vector GetVector(int index, int from, int to, VectorType type)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | Zero-based index of the. |
System.Int32 | from | Source for the. |
System.Int32 | to | to. |
VectorType | type | The type. |
Returns
Type | Description |
---|---|
Vector | The vector. |
Identity(Int32)
n x n identity matrix.
Declaration
public static Matrix Identity(int n)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | n | Size. |
Returns
Type | Description |
---|---|
Matrix | Matrix. |
Identity(Int32, Int32)
n x d identity matrix.
Declaration
public static Matrix Identity(int n, int d)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | n | rows. |
System.Int32 | d | cols. |
Returns
Type | Description |
---|---|
Matrix | Matrix. |
Indices(Matrix, Func<Vector, Boolean>)
Enumerates indices in this collection.
Declaration
public static IEnumerable<int> Indices(Matrix source, Func<Vector, bool> f)
Parameters
Type | Name | Description |
---|---|---|
Matrix | source | Source for the. |
System.Func<Vector, System.Boolean> | f | The Func<Vector,bool> to process. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Int32> | An enumerator that allows foreach to be used to process indices in this collection. |
Indices(Matrix, Func<Vector, Boolean>, VectorType)
Enumerates indices in this collection.
Declaration
public static IEnumerable<int> Indices(Matrix source, Func<Vector, bool> f, VectorType t)
Parameters
Type | Name | Description |
---|---|---|
Matrix | source | Source for the. |
System.Func<Vector, System.Boolean> | f | The Func<Vector,bool> to process. |
VectorType | t | Row or Column sum. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Int32> | An enumerator that allows foreach to be used to process indices in this collection. |
Insert(Vector, Int32, VectorType, Boolean)
Returns a new Matrix with the Vector inserted at the specified position
Declaration
public Matrix Insert(Vector v, int index, VectorType t, bool insertAfter = true)
Parameters
Type | Name | Description |
---|---|---|
Vector | v | Vector to insert |
System.Int32 | index | The zero based row / column. |
VectorType | t | Vector orientation |
System.Boolean | insertAfter | Insert after or before the last row / column |
Returns
Type | Description |
---|---|
Matrix |
Inverse()
Creates an inverse of the current matrix
Declaration
public Matrix Inverse()
Returns
Type | Description |
---|---|
Matrix |
Load(String)
Loads the given stream.
Declaration
public static Matrix Load(string file)
Parameters
Type | Name | Description |
---|---|---|
System.String | file | The file to load. |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the requested file is not present. |
LU(Matrix)
NOT IMPLEMENTED!
Declaration
public static Tuple<Matrix, Matrix, Matrix> LU(Matrix A)
Parameters
Type | Name | Description |
---|---|---|
Matrix | A | . |
Returns
Type | Description |
---|---|
System.Tuple<Matrix, Matrix, Matrix> | A Tuple<Matrix,Matrix,Matrix> |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the requested operation is invalid. |
Max(Matrix)
Determines the maximum of the given parameters.
Declaration
public static double Max(Matrix source)
Parameters
Type | Name | Description |
---|---|---|
Matrix | source | Source for the. |
Returns
Type | Description |
---|---|
System.Double | The maximum value. |
Max(Matrix, VectorType)
Returns a vector of the maximum values for each row/column.
Declaration
public static Vector Max(Matrix source, VectorType t = VectorType.Col)
Parameters
Type | Name | Description |
---|---|---|
Matrix | source | |
VectorType | t | Use column or row (default: Col) |
Returns
Type | Description |
---|---|
Vector |
Mean(Matrix, VectorType)
Determines the mean of the given parameters.
Declaration
public static Vector Mean(Matrix source, VectorType t)
Parameters
Type | Name | Description |
---|---|---|
Matrix | source | Source for the. |
VectorType | t | Row or Column sum. |
Returns
Type | Description |
---|---|
Vector | The mean value. |
Median(Matrix, VectorType)
Returns a vector of the median values for each row or column.
Declaration
public static Vector Median(Matrix source, VectorType t = VectorType.Col)
Parameters
Type | Name | Description |
---|---|---|
Matrix | source | Matrix. |
VectorType | t | VectorType. |
Returns
Type | Description |
---|---|
Vector |
Min(Matrix)
Determines the minimum of the given parameters.
Declaration
public static double Min(Matrix source)
Parameters
Type | Name | Description |
---|---|---|
Matrix | source | Source for the. |
Returns
Type | Description |
---|---|
System.Double | The minimum value. |
Min(Matrix, VectorType)
Returns a vector of the minimum values for each row/column.
Declaration
public static Vector Min(Matrix source, VectorType t = VectorType.Col)
Parameters
Type | Name | Description |
---|---|---|
Matrix | source | |
VectorType | t | Use column or row (default: Col) |
Returns
Type | Description |
---|---|
Vector |
Norm(Matrix, Double)
Standard Matrix Norm.
Declaration
public static double Norm(Matrix A, double p)
Parameters
Type | Name | Description |
---|---|---|
Matrix | A | Input Matrix. |
System.Double | p | The double to process. |
Returns
Type | Description |
---|---|
System.Double | Standard Norm (double) |
Normalize(VectorType)
In place normalization. WARNING: WILL UPDATE MATRIX!
Declaration
public void Normalize(VectorType t)
Parameters
Type | Name | Description |
---|---|---|
VectorType | t | . |
NormRand(Vector, Vector, Int32)
Normalise random.
Declaration
public static Matrix NormRand(Vector means, Vector stdDev, int n)
Parameters
Type | Name | Description |
---|---|---|
Vector | means | The means. |
Vector | stdDev | The standard development. |
System.Int32 | n | Size. |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the requested operation is invalid. |
NormRand(Int32, Double)
Normalise random.
Declaration
public static Matrix NormRand(int n, double min = 0)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | n | Size. |
System.Double | min | (Optional) the minimum. |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
NormRand(Int32, Int32, Double)
Normalise random.
Declaration
public static Matrix NormRand(int n, int d, double min = 0)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | n | Size. |
System.Int32 | d | cols. |
System.Double | min | (Optional) the minimum. |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
Parse(String)
Parses a string containing MATLAB style Matrix syntax, i.e. "[[1, 2, 3]; [3, 4, 5]]"
Declaration
public static Matrix Parse(string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | Input string to parse. |
Returns
Type | Description |
---|---|
Matrix | Matrix. |
Pivot(Matrix)
Pivots the given m.
Declaration
public static Matrix Pivot(Matrix M)
Parameters
Type | Name | Description |
---|---|---|
Matrix | M | The Matrix to process. |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the requested operation is invalid. |
QR(Matrix)
Modified Gram-Schmidt QR Factorization.
Declaration
public static Tuple<Matrix, Matrix> QR(Matrix A)
Parameters
Type | Name | Description |
---|---|---|
Matrix | A | Matrix A. |
Returns
Type | Description |
---|---|
System.Tuple<Matrix, Matrix> | Tuple(Q, R) |
Rand(Int32, Double)
Generate a matrix n x d with numbers 0 less than x less than 1 drawn uniformly at random.
Declaration
public static Matrix Rand(int n, double min = 0)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | n | rows. |
System.Double | min | (Optional) the minimum. |
Returns
Type | Description |
---|---|
Matrix | n x d Matrix. |
Rand(Int32, Int32, Double)
Generate a matrix n x d with numbers 0 less than x less than 1 drawn uniformly at random.
Declaration
public static Matrix Rand(int n, int d, double min = 0)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | n | rows. |
System.Int32 | d | cols. |
System.Double | min | (Optional) the minimum. |
Returns
Type | Description |
---|---|
Matrix | n x d Matrix. |
Remove(Int32, VectorType)
Removes this object.
Declaration
public Matrix Remove(int index, VectorType t)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | Zero-based index of the. |
VectorType | t | . |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
Reshape(Matrix, Int32, Int32)
Reshapes the supplied matrix into a new matrix shape.
Declaration
public static Matrix Reshape(Matrix m, int rows, int cols)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m | Matrix to reshape. |
System.Int32 | rows | Number of rows of the new matrix. |
System.Int32 | cols | Number of columns of the new matrix. |
Returns
Type | Description |
---|---|
Matrix | Matrix. |
Reshape(Vector, Int32, VectorType, VectorType)
Reshapes the supplied Vector into a Matrix form.
Declaration
public static Matrix Reshape(Vector v, int dimension, VectorType dimensionType = VectorType.Col, VectorType byVector = VectorType.Row)
Parameters
Type | Name | Description |
---|---|---|
Vector | v | Source vector to act on. |
System.Int32 | dimension | Length of the specified dimension. |
VectorType | dimensionType | Dimension type to use for creating a dimension by n matrix. |
VectorType | byVector | Direction to process, i.e. Row = Fill Down then Right, or Col = Fill Right then Down |
Returns
Type | Description |
---|---|
Matrix |
Reshape(Vector, Int32, Int32, VectorType)
Reshapes the supplied Vector into a Matrix form.
Declaration
public static Matrix Reshape(Vector v, int rows, int columns, VectorType byVector = VectorType.Row)
Parameters
Type | Name | Description |
---|---|---|
Vector | v | Vector to reshape. |
System.Int32 | rows | Height of the matrix to return |
System.Int32 | columns | Width of the matrix to return |
VectorType | byVector | Direction to process, i.e. Row = Fill Down then Right, or Col = Fill Right then Down |
Returns
Type | Description |
---|---|
Matrix |
Reverse(Matrix, VectorType)
Enumerates reverse in this collection.
Declaration
public static IEnumerable<Vector> Reverse(Matrix source, VectorType t = VectorType.Row)
Parameters
Type | Name | Description |
---|---|---|
Matrix | source | Source for the. |
VectorType | t | (Optional) Row or Column sum. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Vector> | An enumerator that allows foreach to be used to process reverse in this collection. |
Round(Matrix, Int32)
Matrix Roundoff.
Declaration
public static Matrix Round(Matrix m, int decimals = 0)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m | Input Matrix. |
System.Int32 | decimals | (Optional) Max number of decimals (default 0 - integral members) |
Returns
Type | Description |
---|---|
Matrix | Rounded Matrix. |
Row(Int32)
Rows.
Declaration
public Vector Row(int i)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | i | Zero-based index of the. |
Returns
Type | Description |
---|---|
Vector | A Vector. |
Save(String)
Save matrix to file
Declaration
public void Save(string file)
Parameters
Type | Name | Description |
---|---|---|
System.String | file | file to save |
Slice(Matrix, IEnumerable<Int32>)
Slices.
Declaration
public static Matrix Slice(Matrix m, IEnumerable<int> indices)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m | Input Matrix. |
System.Collections.Generic.IEnumerable<System.Int32> | indices | The indices. |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
Slice(Matrix, IEnumerable<Int32>, VectorType)
Slices.
Declaration
public static Matrix Slice(Matrix m, IEnumerable<int> indices, VectorType t)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m | Input Matrix. |
System.Collections.Generic.IEnumerable<System.Int32> | indices | The indices. |
VectorType | t | Row or Column sum. |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
Sort(Matrix, Func<Vector, Double>, VectorType, Boolean)
Sorts the given Matrix by the specified row or column selector and returns the new Matrix
Declaration
public static Matrix Sort(Matrix source, Func<Vector, double> keySelector, VectorType t, bool ascending = true)
Parameters
Type | Name | Description |
---|---|---|
Matrix | source | The Matrix |
System.Func<Vector, System.Double> | keySelector | Property selector to sort by. |
VectorType | t | Specifies whether to sort horizontally or vertically. |
System.Boolean | ascending | Determines whether to sort ascending or descending (Default: True) |
Returns
Type | Description |
---|---|
Matrix | New Matrix and Vector of original indices. |
Sort(Matrix, Func<Vector, Double>, VectorType, Boolean, out Vector)
Sorts the given Matrix by the specified row or column selector and returns the new Matrix along with the original indices.
Declaration
public static Matrix Sort(Matrix source, Func<Vector, double> keySelector, VectorType t, bool ascending, out Vector indices)
Parameters
Type | Name | Description |
---|---|---|
Matrix | source | The Matrix |
System.Func<Vector, System.Double> | keySelector | Property selector to sort by. |
VectorType | t | Specifies whether to sort horizontally or vertically. |
System.Boolean | ascending | Determines whether to sort ascending or descending (Default: True) |
Vector | indices | Vector of t indices in the original Matrix before the sort operation. |
Returns
Type | Description |
---|---|
Matrix | New Matrix and Vector of original indices. |
Stack(Matrix, Matrix)
Stack a set of vectors into a matrix.
Declaration
public static Matrix Stack(Matrix m, Matrix t)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m | Input Matrix. |
Matrix | t | Row or Column sum. |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the requested operation is invalid. |
Stack(Vector[])
Stack a set of vectors into a matrix.
Declaration
public static Matrix Stack(params Vector[] vectors)
Parameters
Type | Name | Description |
---|---|---|
Vector[] | vectors | . |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
Stats(Matrix, VectorType)
Statistics.
Declaration
public static Matrix[] Stats(Matrix x, VectorType t = VectorType.Row)
Parameters
Type | Name | Description |
---|---|---|
Matrix | x | Matrix x. |
VectorType | t | (Optional) Row or Column sum. |
Returns
Type | Description |
---|---|
Matrix[] | A Matrix[]. |
StdDev(Matrix, VectorType)
Computes the standard deviation of the given matrix
Declaration
public static Vector StdDev(Matrix source, VectorType t = VectorType.Col)
Parameters
Type | Name | Description |
---|---|---|
Matrix | source | |
VectorType | t | Use column or row (default: Col) |
Returns
Type | Description |
---|---|
Vector |
Sum(Matrix)
Computes the sum of every element of the matrix.
Declaration
public static double Sum(Matrix m)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m | Input Matrix. |
Returns
Type | Description |
---|---|
System.Double | sum. |
Sum(Matrix, VectorType)
Computes the sum of either the rows or columns of a matrix and returns a vector.
Declaration
public static Vector Sum(Matrix m, VectorType t)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m | Input Matrix. |
VectorType | t | Row or Column sum. |
Returns
Type | Description |
---|---|
Vector | Vector Sum. |
Sum(Matrix, Int32, VectorType)
Computes the sum of every element of the matrix.
Declaration
public static double Sum(Matrix m, int i, VectorType t)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m | Input Matrix. |
System.Int32 | i | Zero-based index of the. |
VectorType | t | Row or Column sum. |
Returns
Type | Description |
---|---|
System.Double | sum. |
SVD(Matrix)
Singular Value Decomposition.
Declaration
public static Tuple<Matrix, Vector, Matrix> SVD(Matrix A)
Parameters
Type | Name | Description |
---|---|---|
Matrix | A | Input Matrix. |
Returns
Type | Description |
---|---|
System.Tuple<Matrix, Vector, Matrix> | Tuple(Matrix U, Vector S, Matrix V) |
Exceptions
Type | Condition |
---|---|
System.NotImplementedException | Thrown when the requested operation is unimplemented. |
Swap(Int32, Int32, VectorType)
Swaps.
Declaration
public void Swap(int from, int to, VectorType t)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | from | Source for the. |
System.Int32 | to | to. |
VectorType | t | . |
SwapCol(Int32, Int32)
Swap col.
Declaration
public void SwapCol(int from, int to)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | from | Source for the. |
System.Int32 | to | to. |
SwapRow(Int32, Int32)
Swap row.
Declaration
public void SwapRow(int from, int to)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | from | Source for the. |
System.Int32 | to | to. |
ToString()
Returns a string that represents the current object.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A string that represents the current object. |
Overrides
ToVector()
Converts this object to a vector.
Declaration
public Vector ToVector()
Returns
Type | Description |
---|---|
Vector | This object as a Vector. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the requested operation is invalid. |
Trace(Matrix)
Computes the trace of a matrix.
Declaration
public static double Trace(Matrix m)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m | Input Matrix. |
Returns
Type | Description |
---|---|
System.Double | trace. |
Transpose()
Deep copy transpose.
Declaration
public Matrix Transpose()
Returns
Type | Description |
---|---|
Matrix | Matrix. |
Unshape(Matrix, VectorType)
Unshapes the given Matrix into a Vector form along the dimensionType axis.
Reads from the source Matrix and stacks from right to left when dimensionType equals 'Col' otherwise uses a bottom up approach.
Declaration
public static Vector Unshape(Matrix m, VectorType dimensionType = VectorType.Col)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m | The Matrix to act on. |
VectorType | dimensionType | Type of the dimension to use when unrolling the Matrix. |
Returns
Type | Description |
---|---|
Vector | Matrix. |
VStack(Matrix, Matrix)
Stacks.
Declaration
public static Matrix VStack(Matrix m, Matrix t)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m | Input Matrix. |
Matrix | t | Row or Column sum. |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the requested operation is invalid. |
VStack(Vector[])
Stacks.
Declaration
public static Matrix VStack(params Vector[] vectors)
Parameters
Type | Name | Description |
---|---|---|
Vector[] | vectors | . |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
Zeros(Int32)
Initial Zero Matrix (n by n)
Declaration
public static Matrix Zeros(int n)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | n | Size. |
Returns
Type | Description |
---|---|
Matrix | Matrix. |
Zeros(Int32, Int32)
Initial zero matrix.
Declaration
public static Matrix Zeros(int n, int d)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | n | . |
System.Int32 | d | . |
Returns
Type | Description |
---|---|
Matrix | A Matrix. |
Operators
View SourceAddition(Matrix, Matrix)
Addition operator.
Declaration
public static Matrix operator +(Matrix m1, Matrix m2)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m1 | The first Matrix. |
Matrix | m2 | The second Matrix. |
Returns
Type | Description |
---|---|
Matrix | The result of the operation. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the requested operation is invalid. |
Addition(Matrix, Double)
In memory addition of double to matrix.
Declaration
public static Matrix operator +(Matrix m, double s)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m | Matrix. |
System.Double | s | double. |
Returns
Type | Description |
---|---|
Matrix | The result of the operation. |
Addition(Double, Matrix)
Addition operator.
Declaration
public static Matrix operator +(double s, Matrix m)
Parameters
Type | Name | Description |
---|---|---|
System.Double | s | The double to process. |
Matrix | m | The Matrix to process. |
Returns
Type | Description |
---|---|
Matrix | The result of the operation. |
Division(Matrix, Vector)
Solves Ax = b for x If A is not square or the system is overdetermined, this operation solves the linear least squares A.T * A x = A.T * b.
Declaration
public static Vector operator /(Matrix A, Vector b)
Parameters
Type | Name | Description |
---|---|---|
Matrix | A | Matrix A. |
Vector | b | Vector b. |
Returns
Type | Description |
---|---|
Vector | x. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the requested operation is invalid. |
Division(Matrix, Double)
Division operator.
Declaration
public static Matrix operator /(Matrix A, double b)
Parameters
Type | Name | Description |
---|---|---|
Matrix | A | The Matrix to process. |
System.Double | b | The double to process. |
Returns
Type | Description |
---|---|
Matrix | The result of the operation. |
Equality(Matrix, Matrix)
Equality operator.
Declaration
public static bool operator ==(Matrix m1, Matrix m2)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m1 | The first Matrix. |
Matrix | m2 | The second Matrix. |
Returns
Type | Description |
---|---|
System.Boolean | The result of the operation. |
Equality(Matrix, Double)
Returns an array of index (i, j) pairs matching indices that are equal to the supplied value.
Declaration
public static IEnumerable<int[]> operator ==(Matrix mat, double val)
Parameters
Type | Name | Description |
---|---|---|
Matrix | mat | Matrix. |
System.Double | val | Value. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Int32[]> |
ExclusiveOr(Matrix, Int32)
Matrix inverse using pivoted Gauss-Jordan elimination with partial pivoting See:http://www.cse.illinois.edu/iem/linear_equations/gauss_jordan/for python implementaion.
Declaration
public static Matrix operator ^(Matrix mat, int n)
Parameters
Type | Name | Description |
---|---|---|
Matrix | mat | Matrix. |
System.Int32 | n | -1. |
Returns
Type | Description |
---|---|
Matrix | Inverse (or exception if matrix is singular) |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the requested operation is invalid. |
GreaterThan(Matrix, Double)
Returns an array of index (i, j) pairs matching indices that are greater than the supplied value.
Declaration
public static IEnumerable<int[]> operator>(Matrix mat, double val)
Parameters
Type | Name | Description |
---|---|---|
Matrix | mat | Matrix. |
System.Double | val | Value. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Int32[]> |
GreaterThanOrEqual(Matrix, Double)
Returns an array of index (i, j) pairs matching indices that are greater than or equal to the supplied value.
Declaration
public static IEnumerable<int[]> operator >=(Matrix mat, double val)
Parameters
Type | Name | Description |
---|---|---|
Matrix | mat | Matrix. |
System.Double | val | Value. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Int32[]> |
Implicit(Double[][] to Matrix)
Performs an implicit conversion from System.Double to Matrix.
Declaration
public static implicit operator Matrix(double[][] m)
Parameters
Type | Name | Description |
---|---|---|
System.Double[][] | m | The m. |
Returns
Type | Description |
---|---|
Matrix | The result of the conversion. |
Implicit(Double[,] to Matrix)
Matrix casting operator.
Declaration
public static implicit operator Matrix(double[, ] m)
Parameters
Type | Name | Description |
---|---|---|
System.Double[,] | m | Matrix. |
Returns
Type | Description |
---|---|
Matrix |
Implicit(Int32[,] to Matrix)
Matrix casting operator.
Declaration
public static implicit operator Matrix(int[, ] m)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[,] | m | Matrix. |
Returns
Type | Description |
---|---|
Matrix |
Inequality(Matrix, Matrix)
Inequality operator.
Declaration
public static bool operator !=(Matrix m1, Matrix m2)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m1 | The first Matrix. |
Matrix | m2 | The second Matrix. |
Returns
Type | Description |
---|---|
System.Boolean | The result of the operation. |
Inequality(Matrix, Double)
Returns an array of index (i, j) pairs matching indices that are not equal to the supplied value.
Declaration
public static IEnumerable<int[]> operator !=(Matrix mat, double val)
Parameters
Type | Name | Description |
---|---|---|
Matrix | mat | Matrix. |
System.Double | val | Value. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Int32[]> |
LessThan(Matrix, Double)
Returns an array of index (i, j) pairs matching indices that are less than the supplied value.
Declaration
public static IEnumerable<int[]> operator <(Matrix mat, double val)
Parameters
Type | Name | Description |
---|---|---|
Matrix | mat | Matrix. |
System.Double | val | Value. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Int32[]> |
LessThanOrEqual(Matrix, Double)
Returns an array of index (i, j) pairs matching indices that are less than or equal to the supplied value.
Declaration
public static IEnumerable<int[]> operator <=(Matrix mat, double val)
Parameters
Type | Name | Description |
---|---|---|
Matrix | mat | Matrix. |
System.Double | val | Value. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Int32[]> |
Multiply(Matrix, Matrix)
matrix multiplication.
Declaration
public static Matrix operator *(Matrix m1, Matrix m2)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m1 | left hand side. |
Matrix | m2 | right hand side. |
Returns
Type | Description |
---|---|
Matrix | matrix. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the requested operation is invalid. |
Multiply(Matrix, Vector)
Multiplication operator.
Declaration
public static Matrix operator *(Matrix m, Vector v)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m | The Matrix to process. |
Vector | v | The Vector to process. |
Returns
Type | Description |
---|---|
Matrix | The result of the operation. |
Multiply(Matrix, Double)
reverse.
Declaration
public static Matrix operator *(Matrix m, double s)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m | . |
System.Double | s | . |
Returns
Type | Description |
---|---|
Matrix | The result of the operation. |
Multiply(Vector, Matrix)
Multiplication operator.
Declaration
public static Matrix operator *(Vector v, Matrix m)
Parameters
Type | Name | Description |
---|---|---|
Vector | v | The Vector to process. |
Matrix | m | The Matrix to process. |
Returns
Type | Description |
---|---|
Matrix | The result of the operation. |
Multiply(Double, Matrix)
Scalar matrix multiplication.
Declaration
public static Matrix operator *(double s, Matrix m)
Parameters
Type | Name | Description |
---|---|---|
System.Double | s | scalar. |
Matrix | m | matrix. |
Returns
Type | Description |
---|---|
Matrix | matrix. |
Subtraction(Matrix, Matrix)
Subtraction operator.
Declaration
public static Matrix operator -(Matrix m1, Matrix m2)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m1 | The first Matrix. |
Matrix | m2 | The second Matrix. |
Returns
Type | Description |
---|---|
Matrix | The result of the operation. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the requested operation is invalid. |
Subtraction(Matrix, Double)
Subtract double from every element in the Matrix.
Declaration
public static Matrix operator -(Matrix m, double s)
Parameters
Type | Name | Description |
---|---|---|
Matrix | m | Matrix. |
System.Double | s | Double. |
Returns
Type | Description |
---|---|
Matrix | The result of the operation. |
Subtraction(Double, Matrix)
Subtraction operator.
Declaration
public static Matrix operator -(double s, Matrix m)
Parameters
Type | Name | Description |
---|---|---|
System.Double | s | The double to process. |
Matrix | m | The Matrix to process. |
Returns
Type | Description |
---|---|
Matrix | The result of the operation. |