Package org.tribuo.math.la
Interface Matrix
- All Superinterfaces:
Iterable<MatrixTuple>
,ProtoSerializable<org.tribuo.math.protos.TensorProto>
,Serializable
,Tensor
- All Known Implementing Classes:
DenseMatrix
,DenseSparseMatrix
,ShrinkingMatrix
Interface for 2 dimensional
Tensor
s.
Matrices have immutable sizes and immutable indices (so DenseSparseMatrix
can't grow).
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Interface for matrix factorizations. -
Field Summary
Fields inherited from interface org.tribuo.protos.ProtoSerializable
DESERIALIZATION_METHOD_NAME, PROVENANCE_SERIALIZER
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(int i, int j, double value) Adds the argument value to the value at the supplied index.copy()
Copies the matrix.double
get
(int i, int j) Gets an element from thisMatrix
.getColumn
(int index) Returns a copy of the specified column.int
The size of the first dimension.int
The size of the second dimension.getRow
(int i) AnSGDVector
view of the row.leftMultiply
(SGDVector input) Multiplies this Matrix by aSGDVector
returning a vector of the appropriate size.matrixMultiply
(Matrix input) Multiplies this Matrix by anotherMatrix
returning a matrix of the appropriate size.matrixMultiply
(Matrix input, boolean transposeThis, boolean transposeOther) Multiplies this Matrix by anotherMatrix
returning a matrix of the appropriate size.int
numActiveElements
(int row) The number of non-zero elements in that row.rightMultiply
(SGDVector input) Multiplies this Matrix by aSGDVector
returning a vector of the appropriate size.void
rowScaleInPlace
(DenseVector scalingCoefficients) Scales each row by the appropriate value in theDenseVector
.rowSum()
Generates aDenseVector
representing the sum of each row.void
set
(int i, int j, double value) Sets an element at the supplied location.Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
Methods inherited from interface org.tribuo.protos.ProtoSerializable
serialize
Methods inherited from interface org.tribuo.math.la.Tensor
foreachInPlace, getShape, hadamardProductInPlace, hadamardProductInPlace, intersectAndAddInPlace, intersectAndAddInPlace, reshape, scalarAddInPlace, scaleInPlace, twoNorm
-
Method Details
-
copy
Matrix copy()Copies the matrix. -
get
double get(int i, int j) Gets an element from thisMatrix
.- Parameters:
i
- The index for the first dimension.j
- The index for the second dimension.- Returns:
- The value at matrix[i][j].
-
set
void set(int i, int j, double value) Sets an element at the supplied location.- Parameters:
i
- The index for the first dimension.j
- The index for the second dimension.value
- The value to be stored at matrix[i][j].
-
add
void add(int i, int j, double value) Adds the argument value to the value at the supplied index.- Parameters:
i
- The index for the first dimension.j
- The index for the second dimension.value
- The value to add.
-
getDimension1Size
int getDimension1Size()The size of the first dimension.- Returns:
- The size of the first dimension.
-
getDimension2Size
int getDimension2Size()The size of the second dimension.- Returns:
- The size of the second dimension.
-
numActiveElements
int numActiveElements(int row) The number of non-zero elements in that row.An element could be active and zero, if it was active on construction.
- Parameters:
row
- The index of the row.- Returns:
- The number of non-zero elements.
-
leftMultiply
Multiplies this Matrix by aSGDVector
returning a vector of the appropriate size.The input must have dimension equal to
getDimension2Size()
.- Parameters:
input
- The input vector.- Returns:
- A new
SGDVector
of sizegetDimension1Size()
.
-
rightMultiply
Multiplies this Matrix by aSGDVector
returning a vector of the appropriate size.The input must have dimension equal to
getDimension1Size()
.- Parameters:
input
- The input vector.- Returns:
- A new
SGDVector
of sizegetDimension2Size()
.
-
matrixMultiply
Multiplies this Matrix by anotherMatrix
returning a matrix of the appropriate size.The input must have dimension 1 equal to
getDimension2Size()
.- Parameters:
input
- The input matrix.- Returns:
- A new
Matrix
of sizegetDimension1Size()
,input.getDimension2Size()
.
-
matrixMultiply
Multiplies this Matrix by anotherMatrix
returning a matrix of the appropriate size.Must obey the rules of matrix multiplication after the transposes are applied.
- Parameters:
input
- The input matrix.transposeThis
- Implicitly transposes this matrix just for the multiplication.transposeOther
- Implicitly transposes other just for the multiplication.- Returns:
- A new
Matrix
.
-
rowSum
DenseVector rowSum()Generates aDenseVector
representing the sum of each row.- Returns:
- A new
DenseVector
of sizegetDimension1Size()
.
-
rowScaleInPlace
Scales each row by the appropriate value in theDenseVector
.- Parameters:
scalingCoefficients
- ADenseVector
with sizegetDimension1Size()
.
-
getRow
AnSGDVector
view of the row.This refers to the same values as the matrix, so updating this vector will update the matrix.
- Parameters:
i
- The index of the row to extract.- Returns:
- An
SGDVector
.
-
getColumn
Returns a copy of the specified column.- Parameters:
index
- The column index.- Returns:
- A copy of the column.
-