Matrix class abstract

An algebraic matrix with extended functionality, adapted for data science applications

Implemented types
Available Extensions

Constructors

Matrix.column(List<double> source, {DType dtype = DType.float32})
Creates a matrix, consisting of just one column (aka Column matrix)
factory
Matrix.diagonal(List<double> source, {DType dtype = DType.float32})
Creates a matrix, where elements from source are the elements for the matrix main diagonal, the rest of the elements are zero
factory
Matrix.empty({DType dtype = DType.float32})
Creates a matrix of shape 0 x 0 (no rows, no columns)
factory
Matrix.fromByteData(ByteData data, int rowCount, int columnCount, {DType dtype = DType.float32})
Creates a matrix from byte data of rowCount * columnCount elements
factory
Matrix.fromColumns(List<Vector> source, {DType dtype = DType.float32})
Creates a matrix with predefined column vectors
factory
Matrix.fromFlattenedList(List<double> source, int rowCount, int columnCount, {DType dtype = DType.float32})
Creates a matrix from flattened list of length equal to rowCount * columnCount
factory
Matrix.fromJson(Map<String, dynamic> json)
Returns a restored matrix from a serializable map
factory
Matrix.fromList(List<List<double>> source, {DType dtype = DType.float32})
Creates a matrix from a two dimensional list, every nested list is a source for a matrix row.
factory
Matrix.fromRows(List<Vector> source, {DType dtype = DType.float32})
Creates a matrix with predefined row vectors
factory
Matrix.identity(int size, {DType dtype = DType.float32})
Creates a matrix of size * size dimension, where all the main diagonal elements are equal to 1, the rest of the elements are 0
factory
Matrix.random(int rowCount, int columnCount, {DType dtype = DType.float32, num min = -1000, num max = 1000, int? seed})
Returns randomly filled matrix of rowCountxcolumnCount dimension
factory
Matrix.randomSPD(int size, {DType dtype = DType.float32, num min = -1000, num max = 1000, int? seed})
Returns randomly filled symmetric and positive definite matrix of sizexsize dimension
factory
Matrix.row(List<double> source, {DType dtype = DType.float32})
Creates a matrix, consisting of just one row (aka Row matrix)
factory
Matrix.scalar(double scalar, int size, {DType dtype = DType.float32})
Creates a matrix of size * size dimension, where all the main diagonal elements are equal to scalar, the rest of the elements are 0
factory

Properties

asFlattenedList List<double>
Returns a representation of the matrix as a flattened list:
no setter
columnCount int
Returns a number of matrix columns
no setter
columnIndices Iterable<int>
Returns a lazy iterable of column indices
no setter
columns Iterable<Vector>
Returns a lazy iterable of column vectors of the matrix
no setter
columnsNum int
Returns a number of matrix columns
no setter
dtype DType
A data type of Matrix elements
no setter
first Iterable<double>
The first element.
no setterinherited
hasData bool
Returns true if the Matrix is not empty. Use it instead of isEmpty getter from Iterable interface, since the latter may return falsy true
no setter
hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
Whether this collection has no elements.
no setterinherited
isNotEmpty bool
Whether this collection has at least one element.
no setterinherited
isSquare bool
Returns true if the Matrix's columnCount and rowCount are equal
no setter
iterator Iterator<Iterable<double>>
A new Iterator that allows iterating the elements of this Iterable.
no setterinherited
last Iterable<double>
The last element.
no setterinherited
length int
The number of elements in this.
no setterinherited
rowCount int
Returns a number of matrix rows
no setter
rowIndices Iterable<int>
Returns a lazy iterable of row indices
no setter
rows Iterable<Vector>
Returns a lazy iterable of row vectors of the matrix
no setter
rowsNum int
Returns a number of matrix rows
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
single Iterable<double>
Checks that this iterable has only one element, and returns that element.
no setterinherited

Methods

any(bool test(Iterable<double> element)) bool
Checks whether any element of this iterable satisfies test.
inherited
cast<R>() Iterable<R>
A view of this iterable as an iterable of R instances.
inherited
contains(Object? element) bool
Whether the collection contains an element equal to element.
inherited
decompose([Decomposition decompositionType]) Iterable<Matrix>
Decomposes the original matrix into several matrices whose product results in the original matrix Default value id Decomposition.LU
deviation([Axis axis = Axis.columns]) Vector
Returns standard deviation values of matrix column/rows
eigen({EigenMethod method, Vector? initial, int iterationCount, int? seed}) Iterable<Eigen>
Returns a collection of pairs of an eigenvector and its corresponding eigenvalue
elementAt(int index) Iterable<double>
Returns the indexth element.
inherited
every(bool test(Iterable<double> element)) bool
Checks whether every element of this iterable satisfies test.
inherited
exp({bool skipCaching = false}) Matrix
Creates a new Matrix composed of Euler's numbers raised to powers which are the elements of this Matrix
expand<T>(Iterable<T> toElements(Iterable<double> element)) Iterable<T>
Expands each element of this Iterable into zero or more elements.
inherited
fastMap<E>(E mapper(E columnElement)) Matrix
Creates a new matrix, efficiently iterating through all the matrix elements (several floating point elements in a time) and applying the mapper function
filterColumns(bool predicate(Vector column, int idx)) Matrix
Returns a new matrix consisting of filtered columns of the original matrix
firstWhere(bool test(Iterable<double> element), {Iterable<double> orElse()?}) Iterable<double>
The first element that satisfies the given predicate test.
inherited
fold<T>(T initialValue, T combine(T previousValue, Iterable<double> element)) → T
Reduces a collection to a single value by iteratively combining each element of the collection with an existing value
inherited
followedBy(Iterable<Iterable<double>> other) Iterable<Iterable<double>>
Creates the lazy concatenation of this iterable and other.
inherited
forEach(void action(Iterable<double> element)) → void
Invokes action on each element of this iterable in iteration order.
inherited
getColumn(int index) Vector
Returns a column of the matrix on index
getRow(int index) Vector
Returns a row of the matrix on index
insertColumns(int index, List<Vector> columns) Matrix
Returns a new matrix with inserted columns
inverse([Inverse inverseType]) Matrix
Finds the inverse of the original matrix. Product of the inverse and the original matrix results in singular matrix Default value is Inverse.LU
join([String separator = ""]) String
Converts each element to a String and concatenates the strings.
inherited
lastWhere(bool test(Iterable<double> element), {Iterable<double> orElse()?}) Iterable<double>
The last element that satisfies the given predicate test.
inherited
log({bool skipCaching = false}) Matrix
Creates a new Matrix composed of natural logarithms of the source matrix elements
map<T>(T toElement(Iterable<double> e)) Iterable<T>
The current elements of this iterable modified by toElement.
inherited
mapColumns(Vector mapper(Vector column)) Matrix
Performs column-wise mapping of this Matrix to a new one via passed mapper function
mapElements(double mapper(double element)) Matrix
Performs element-wise mapping of this Matrix to a new one via passed mapper function
mapRows(Vector mapper(Vector row)) Matrix
Performs row-wise mapping of this Matrix to a new one via passed mapper function
max() double
Returns a max value of the matrix
mean([Axis axis = Axis.columns]) Vector
Returns mean values of matrix column/rows
min() double
Return a min value of the matrix
multiply(Matrix other) Matrix
Performs Hadamard product - element-wise matrices multiplication
norm([MatrixNorm norm]) double
Returns a norm of a matrix
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pow(num exponent) Matrix
Raise all the elements of the matrix to the power exponent and returns a new Matrix with these elements. Avoid raising a matrix to a float power, since it is a slow operation
prod() double
Returns the product of all the matrix elements
reduce(Iterable<double> combine(Iterable<double> value, Iterable<double> element)) Iterable<double>
Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
inherited
reduceColumns(Vector combiner(Vector combine, Vector vector), {Vector? initValue}) Vector
Reduces all the matrix columns to only column, using combiner function
reduceRows(Vector combiner(Vector combine, Vector vector), {Vector? initValue}) Vector
Reduces all the matrix rows to only row, using combiner function
sample({Iterable<int> rowIndices, Iterable<int> columnIndices}) Matrix
Samples a new Matrix from parts of this Matrix
singleWhere(bool test(Iterable<double> element), {Iterable<double> orElse()?}) Iterable<double>
The single element that satisfies test.
inherited
skip(int count) Iterable<Iterable<double>>
Creates an Iterable that provides all but the first count elements.
inherited
skipWhile(bool test(Iterable<double> value)) Iterable<Iterable<double>>
Creates an Iterable that skips leading elements while test is satisfied.
inherited
solve(Matrix B, [Inverse inverse]) Matrix
Returns a solution for a system of linear equations:
sort(double selectSortValue(Vector vector), [Axis axis = Axis.rows, SortDirection sortDir = SortDirection.asc]) Matrix
Returns a new matrix with sorted elements from this Matrix
sum() double
Returns the sum of all the matrix elements
take(int count) Iterable<Iterable<double>>
Creates a lazy iterable of the count first elements of this iterable.
inherited
takeWhile(bool test(Iterable<double> value)) Iterable<Iterable<double>>
Creates a lazy iterable of the leading elements satisfying test.
inherited
toJson() Map<String, dynamic>
Returns a serializable map
toList({bool growable = true}) List<Iterable<double>>
Creates a List containing the elements of this Iterable.
inherited
toSet() Set<Iterable<double>>
Creates a Set containing the same elements as this iterable.
inherited
toString() String
A string representation of this object.
inherited
toVector() Vector
Tries to convert the Matrix to a vector:
transpose() Matrix
Performs transposition of the matrix
uniqueRows() Matrix
Extracts non-repeated matrix rows and pack them into matrix
variance([Axis axis = Axis.columns]) Vector
Returns variance of matrix column/rows
where(bool test(Iterable<double> element)) Iterable<Iterable<double>>
Creates a new lazy Iterable with all elements that satisfy the predicate test.
inherited
whereType<T>() Iterable<T>
Creates a new lazy Iterable with all elements that have type T.
inherited

Operators

operator *(Object value) Matrix
Performs multiplication of the matrix and a matrix/ a vector/ a scalar/ whatever
operator +(Object value) Matrix
Performs sum of the matrix and a matrix/ a vector/ a scalar/ whatever
operator -(Object value) Matrix
Performs subtraction of the matrix and a matrix/ a vector/ a scalar/ whatever
operator /(Object value) Matrix
Performs division of the matrix by a matrix/ a vector/ a scalar
operator ==(Object other) bool
The equality operator.
inherited
operator [](int index) Vector
Returns a matrix row on an index (the operator is an alias for getRow method)