Show / Hide Table of Contents

Class Matrix

A matrix.

Inheritance
System.Object
Matrix
Inherited Members
System.Object.Equals(System.Object, System.Object)
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace:numl.Math.LinearAlgebra
Assembly:numl.dll
Syntax
public class Matrix

Constructors

View Source

Matrix(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.

View Source

Matrix(Double[,])

Create new matrix with prepopulated vals.

Declaration
public Matrix(double[, ] m)
Parameters
Type Name Description
System.Double[,] m

initial matrix.

View Source

Matrix(Int32)

Create matrix n x n matrix.

Declaration
public Matrix(int n)
Parameters
Type Name Description
System.Int32 n

size.

View Source

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 Source

Cols

Gets or sets the cols.

Declaration
public int Cols { get; }
Property Value
Type Description
System.Int32

The cols.

View Source

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
View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

Rows

Gets or sets the rows.

Declaration
public int Rows { get; }
Property Value
Type Description
System.Int32

The rows.

View Source

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 Source

Center(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.

View Source

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.

View Source

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.

View Source

Copy()

create deep copy of matrix.

Declaration
public Matrix Copy()
Returns
Type Description
Matrix

Matrix.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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
System.Object.Equals(System.Object)
View Source

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)

View Source

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.

View Source

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)

View Source

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.

View Source

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
System.Object.GetHashCode()
View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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
View Source

Inverse()

Creates an inverse of the current matrix

Declaration
public Matrix Inverse()
Returns
Type Description
Matrix
View Source

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.

View Source

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.

View Source

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.

View Source

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
View Source

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.

View Source

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
View Source

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.

View Source

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
View Source

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)

View Source

Normalize(VectorType)

In place normalization. WARNING: WILL UPDATE MATRIX!

Declaration
public void Normalize(VectorType t)
Parameters
Type Name Description
VectorType t

.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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)

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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
View Source

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
View Source

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.

View Source

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.

View Source

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.

View Source

Save(String)

Save matrix to file

Declaration
public void Save(string file)
Parameters
Type Name Description
System.String file

file to save

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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[].

View Source

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
View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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

.

View Source

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.

View Source

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.

View Source

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
System.Object.ToString()
View Source

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.

View Source

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.

View Source

Transpose()

Deep copy transpose.

Declaration
public Matrix Transpose()
Returns
Type Description
Matrix

Matrix.

View Source

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.

View Source

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.

View Source

VStack(Vector[])

Stacks.

Declaration
public static Matrix VStack(params Vector[] vectors)
Parameters
Type Name Description
Vector[] vectors

.

Returns
Type Description
Matrix

A Matrix.

View Source

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.

View Source

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 Source

Addition(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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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[]>
View Source

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.

View Source

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[]>
View Source

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[]>
View Source

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.

View Source

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
View Source

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
View Source

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.

View Source

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[]>
View Source

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[]>
View Source

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[]>
View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

View Source

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.

Extension Methods

MatrixExtensions.ToBinary(Func<Double, Boolean>, Double, Double)
MatrixExtensions.Each(Func<Double, Double>)
MatrixExtensions.Each(Func<Double, Int32, Int32, Double>)
MatrixExtensions.Each(Matrix, Func<Double, Double, Double>)
MatrixExtensions.Stack(Matrix)
MatrixExtensions.VStack(Matrix)
MatrixExtensions.Unshape()
MatrixExtensions.Sort(Func<Vector, Double>, VectorType, Boolean)
MatrixExtensions.Sort(Func<Vector, Double>, VectorType, Boolean, Vector)
MatrixExtensions.Mean(VectorType)
MatrixExtensions.StdDev(VectorType)
MatrixExtensions.Max(VectorType)
MatrixExtensions.Max()
MatrixExtensions.Min()
MatrixExtensions.Min(VectorType)
MatrixExtensions.Median(VectorType)
MatrixExtensions.Covariance(VectorType)
MatrixExtensions.CovarianceDiag(VectorType)
MatrixExtensions.Correlation(VectorType)
MatrixExtensions.Reverse(VectorType)
MatrixExtensions.Indices(Func<Vector, Boolean>)
MatrixExtensions.Indices(Func<Vector, Boolean>, VectorType)
MatrixExtensions.Slice(IEnumerable<Int32>)
MatrixExtensions.Slice(IEnumerable<Int32>, VectorType)
MatrixExtensions.Slice(Int32, Int32, VectorType)
MatrixExtensions.Slice(IEnumerable<IEnumerable<Int32>>, VectorType)
MatrixExtensions.Extract(Int32, Int32, Int32, Int32, Boolean)
MatrixExtensions.Cholesky()
MatrixExtensions.Round(Int32)
MatrixExtensions.Norm()
MatrixExtensions.Norm(Double)
MatrixExtensions.Eigs()
MatrixExtensions.SVD()
MatrixExtensions.Trace()
MatrixExtensions.Sum()
MatrixExtensions.Sum(VectorType)
MatrixExtensions.Diag()
MatrixExtensions.Stats()
MatrixExtensions.Stats(VectorType)
MatrixExtensions.Det()
  • View Source
©2017 — Seth Juarez
numl v0.9.20-beta
MIT License
docs by docfx