public interface Matrix extends MetaAttributes, Externalizable, StorageOpsMetrics, Destroyable
Based on its flavor it can have vastly different implementations tailored for for different types of data (e.g. dense vs. sparse), different sizes of data or different operation optimizations.
Note also that not all operations can be supported by all underlying implementations. If an operation is not
supported a UnsupportedOperationException
is thrown. This exception can also be thrown in partial cases
where an operation is unsupported only in special cases, e.g. where a given operation cannot be deterministically
completed in polynomial time.
Based on ideas from Apache Mahout.
Modifier and Type | Interface and Description |
---|---|
static interface |
Matrix.Element
Holder for matrix's element.
|
Modifier and Type | Method and Description |
---|---|
Spliterator<Double> |
allSpliterator()
Gets spliterator for all values in this matrix.
|
Matrix |
assign(double val)
Assigns given value to all elements of this matrix.
|
Matrix |
assign(double[][] vals)
Assigns given values to this matrix.
|
Matrix |
assign(IntIntToDoubleFunction fun)
Assigns each matrix element to the value generated by given function.
|
Matrix |
assign(Matrix mtx)
Assigns values from given matrix to this matrix.
|
Matrix |
assignColumn(int col,
Vector vec)
Assigns values from given vector to the specified column in this matrix.
|
Matrix |
assignRow(int row,
Vector vec)
Assigns values from given vector to the specified row in this matrix.
|
int |
columnSize()
Gets number of columns in this matrix.
|
void |
compute(int row,
int col,
IgniteTriFunction<Integer,Integer,Double,Double> f)
Replace matrix entry with value oldVal at (row, col) with result of computing f(row, col, oldVal).
|
Matrix |
copy()
Clones this matrix.
|
boolean |
density(double threshold)
Calculates the density of the matrix based on supplied criteria.
|
default void |
destroy()
Destroys object if managed outside of JVM.
|
double |
determinant()
Returns matrix determinant using Laplace theorem.
|
Matrix |
divide(double x)
Divides each value in this matrix by the argument.
|
Vector |
foldColumns(IgniteFunction<Vector,Double> fun)
Collects the results of applying a given function to all columns in this matrix.
|
<T> T |
foldMap(IgniteBiFunction<T,Double,T> foldFun,
IgniteDoubleFunction<Double> mapFun,
T zeroVal)
Folds this matrix into a single value.
|
Vector |
foldRows(IgniteFunction<Vector,Double> fun)
Collects the results of applying a given function to all rows in this matrix.
|
double |
get(int row,
int col)
Gets the matrix value at the provided location.
|
Vector |
getCol(int col)
Get a specific row from matrix.
|
Matrix.Element |
getElement(int row,
int col)
Gets the matrix's element at the given coordinates.
|
Vector |
getRow(int row)
Get a specific row from matrix.
|
MatrixStorage |
getStorage()
Gets matrix storage model.
|
double |
getX(int row,
int col)
Gets the matrix value at the provided location without checking boundaries.
|
IgniteUuid |
guid()
Auto-generated globally unique matrix ID.
|
Matrix |
inverse()
Returns the inverse matrix of this matrix
|
default boolean |
isNumeric() |
Matrix |
like(int rows,
int cols)
Creates new empty matrix of the same underlying class but of different size.
|
Vector |
likeVector(int crd)
Creates new empty vector of compatible properties (similar or the same flavor) to this matrix.
|
Matrix |
map(IgniteDoubleFunction<Double> fun)
Maps all values in this matrix through a given function.
|
Matrix |
map(Matrix mtx,
IgniteBiFunction<Double,Double,Double> fun)
Maps all values in this matrix through a given function.
|
Matrix.Element |
maxElement()
Gets the maximum element in this matrix.
|
double |
maxValue()
Gets the maximum value in this matrix.
|
Matrix.Element |
minElement()
Gets the minimum element in this matrix.
|
Matrix |
minus(Matrix mtx)
Creates new matrix where each value is a difference between corresponding value of this matrix and
passed in argument matrix.
|
double |
minValue()
Gets the minimum value in this matrix.
|
int |
nonZeroElements()
Gets number of non-zero elements in this matrix.
|
Spliterator<Double> |
nonZeroSpliterator()
Gets spliterator for all non-zero values in this matrix.
|
Matrix |
plus(double x)
Creates new matrix where each value is a sum of the corresponding value of this matrix and
argument value.
|
Matrix |
plus(Matrix mtx)
Creates new matrix where each value is a sum of corresponding values of this matrix and
passed in argument matrix.
|
int |
rowSize()
Gets number of rows in this matrix.
|
Matrix |
set(int row,
int col,
double val)
Sets given value.
|
Matrix |
setColumn(int col,
double[] data)
Sets values for given column.
|
Matrix |
setRow(int row,
double[] data)
Sets values for given row.
|
Matrix |
setX(int row,
int col,
double val)
Sets given value without checking for index bounds.
|
double |
sum()
Gets sum of all elements in the matrix.
|
Matrix |
swapColumns(int col1,
int col2)
Swaps two columns in this matrix.
|
Matrix |
swapRows(int row1,
int row2)
Swaps two rows in this matrix.
|
Matrix |
times(double x)
Creates new matrix containing the product of given value and values in this matrix.
|
Matrix |
times(Matrix mtx)
Creates new matrix that is the product of multiplying this matrix and the argument matrix.
|
Vector |
times(Vector vec)
Creates new matrix that is the product of multiplying this matrix and the argument vector.
|
Matrix |
transpose()
Creates new matrix that is transpose of this matrix.
|
Vector |
viewColumn(int col)
Creates new view into matrix column .
|
Vector |
viewDiagonal()
Creates new view into matrix diagonal.
|
Vector |
viewRow(int row)
Creates new view into matrix row.
|
getAttribute, getMetaStorage, hasAttribute, removeAttribute, setAttribute
readExternal, writeExternal
isArrayBased, isDense, isDistributed
double maxValue()
double minValue()
Matrix.Element maxElement()
Matrix.Element minElement()
Matrix.Element getElement(int row, int col)
row
- Row index.col
- Column index.Matrix swapRows(int row1, int row2)
row1
- Row #1.row2
- Row #2.Matrix swapColumns(int col1, int col2)
col1
- Column #1.col2
- Column #2.Matrix assign(double val)
val
- Value to assign to all elements.Matrix assign(double[][] vals)
vals
- Values to assign.CardinalityException
- Thrown if cardinalities mismatch.Matrix assign(Matrix mtx)
mtx
- Matrix to assign to this matrix.CardinalityException
- Thrown if cardinalities mismatch.Matrix assign(IntIntToDoubleFunction fun)
fun
- Function that takes the row and column and returns the value to assign.Matrix map(IgniteDoubleFunction<Double> fun)
fun
- Mapping function.Matrix map(Matrix mtx, IgniteBiFunction<Double,Double,Double> fun)
For this matrix A
, argument matrix B
and the
function F
this method maps every cell x, y
as:
A(x,y) = fun(A(x,y), B(x,y))
.
mtx
- Argument matrix.fun
- Mapping function.CardinalityException
- Thrown if cardinalities mismatch.int nonZeroElements()
Spliterator<Double> allSpliterator()
Spliterator<Double> nonZeroSpliterator()
Matrix assignColumn(int col, Vector vec)
col
- Column index.vec
- Vector to get values from.CardinalityException
- Thrown if cardinalities mismatch.Matrix assignRow(int row, Vector vec)
row
- Row index.vec
- Vector to get values from.CardinalityException
- Thrown if cardinalities mismatch.Vector foldRows(IgniteFunction<Vector,Double> fun)
fun
- Aggregating function.Vector foldColumns(IgniteFunction<Vector,Double> fun)
fun
- Aggregating function.<T> T foldMap(IgniteBiFunction<T,Double,T> foldFun, IgniteDoubleFunction<Double> mapFun, T zeroVal)
T
- Type of the folded value.foldFun
- Folding function that takes two parameters: accumulator and the current value.mapFun
- Mapping function that is called on each matrix cell before its passed to the accumulator (as its
second parameter).zeroVal
- Zero value for fold function.boolean density(double threshold)
true
if this matrix is denser than threshold with at least 80% confidence.threshold
- the threshold value [0, 1] of non-zero elements above which the matrix is considered dense.int columnSize()
int rowSize()
Matrix divide(double x)
x
- Divider value.double get(int row, int col)
row
- Row index.col
- Column index.IndexException
- Thrown in case of index is out of bound.double getX(int row, int col)
get(int, int)
sibling.row
- Row index.col
- Column index.MatrixStorage getStorage()
Matrix copy()
NOTE: new matrix will have the same flavor as the this matrix but a different ID.
Matrix like(int rows, int cols)
NOTE: new matrix will have the same flavor as the this matrix but a different ID.
rows
- Number of rows for new matrix.cols
- Number of columns for new matrix.Vector likeVector(int crd)
crd
- Cardinality of the vector.Matrix minus(Matrix mtx)
mtx
- Argument matrix.CardinalityException
- Thrown if cardinalities mismatch.Matrix plus(double x)
x
- Value to add.Matrix plus(Matrix mtx)
mtx
- Argument matrix.CardinalityException
- Thrown if cardinalities mismatch.IgniteUuid guid()
Matrix set(int row, int col, double val)
row
- Row index.col
- Column index.val
- Value to set.IndexException
- Thrown in case of either index is out of bound.Matrix setRow(int row, double[] data)
row
- Row index.data
- Row data to set.IndexException
- Thrown in case of index is out of bound.CardinalityException
- Thrown if cardinalities mismatch.Vector getRow(int row)
row
- Row index.Matrix setColumn(int col, double[] data)
col
- Column index.data
- Column data to set.IndexException
- Thrown in case of index is out of bound.CardinalityException
- Thrown if cardinalities mismatch.Vector getCol(int col)
col
- Col index.Matrix setX(int row, int col, double val)
set(int, int, double)
sibling.row
- Row index.col
- Column index.val
- Value to set.Matrix times(double x)
x
- Value to multiply.Matrix times(Matrix mtx)
mtx
- Argument matrix.CardinalityException
- Thrown if cardinalities mismatch.Vector times(Vector vec)
vec
- Argument vector.CardinalityException
- Thrown if cardinalities mismatch.double sum()
Matrix transpose()
Vector viewRow(int row)
row
- Row index.IndexException
- Thrown in case of index is out of bound.Vector viewColumn(int col)
col
- Column index.IndexException
- Thrown in case of index is out of bound.Vector viewDiagonal()
default void destroy()
destroy
in interface Destroyable
void compute(int row, int col, IgniteTriFunction<Integer,Integer,Double,Double> f)
row
- Row.col
- Column.f
- Function used for replacing.double determinant()
CardinalityException
- Thrown if matrix is not square.Matrix inverse()
default boolean isNumeric()
isNumeric
in interface StorageOpsMetrics
GridGain In-Memory Computing Platform : ver. 8.9.14 Release Date : November 5 2024