public abstract class Matrix
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
protected static interface |
Matrix.ElementVisitorFunction
Functional interface that visits every non-zero element in this matrix.
|
static interface |
Matrix.ReadOnlyElementVisitorFunction
Functional interface that visits every non-zero element in this matrix.
|
| Modifier | Constructor and Description |
|---|---|
protected |
Matrix(int numRows,
int numCols)
Creates a new matrix.
|
| Modifier and Type | Method and Description |
|---|---|
Matrix |
abs()
Creates a new matrix by taking the absolute value of this matrix.
|
double |
absSum()
Gets the sum of the absolute value of all the matrix's elements.
|
Matrix |
add(double scalar)
Creates a new matrix by adding each value in this matrix by a scalar.
|
Matrix |
addElementWise(Matrix matrix)
Creates a new Matrix by adding this matrix element-wise with another matrix.
|
protected abstract Matrix |
create(int numRows,
int numCols)
Creates a new matrix.
|
boolean |
equals(java.lang.Object obj) |
protected abstract void |
forEach(Matrix.ElementVisitorFunction func)
Calls the specified function for every non-zero element.
|
void |
forEach(Matrix.ReadOnlyElementVisitorFunction func)
Calls the specified function for every non-zero element.
|
double |
getAt(int row,
int col)
Gets the value at the specified row and column.
|
protected abstract double |
getAtUnchecked(int row,
int col)
Gets the value at the specified row and column.
|
int |
getColumnCount()
Gets the number of columns.
|
ColumnVector |
getColumnSumVector()
Gets a vector containing the sums of each matrix column.
|
int |
getElementCount()
Gets the number of elements.
|
abstract MatrixNonZeroElementRowIterator |
getNonZeroElementRowIterator(int row)
Gets the non-zero matrix row element iterator for a given row index.
|
int |
getRowCount()
Gets the number of rows.
|
ColumnVector |
getRowSumVector()
Gets a vector containing the sums of each matrix row.
|
int |
hashCode() |
void |
incrementAt(int row,
int col,
double val)
Increments a value at the specified row and column by the given val.
|
boolean |
isSameSize(Matrix matrix)
Determines if two this matrix and another matrix have the same dimensions.
|
boolean |
isZeroMatrix()
Determines if this matrix is a zero matrix.
|
ColumnVector |
multiply(ColumnVector vector)
Multiplies this matrix by a vector.
|
Matrix |
multiply(double scalar)
Creates a new matrix by multiplying this matrix by a scalar.
|
Matrix |
multiplyElementWise(Matrix matrix)
Creates a new Matrix by multiplying this matrix element-wise with another matrix.
|
java.util.Collection<java.lang.Integer> |
normalizeColumns()
Normalizes each column of the matrix.
|
void |
removeLessThan(double minValue)
Sets all values less than the specified value to zero.
|
void |
removeNegatives()
Sets all negative values to zero.
|
Matrix |
roundTo(int numPlaces)
Creates a new matrix by rounding all elements in this matrix to the specified number of decimal
places.
|
void |
scale(double scale)
Scales this matrix by dividing all of its elements by the specified factor.
|
void |
setAt(int row,
int col,
double val)
Sets a value at the specified row and column.
|
protected abstract void |
setAtUnchecked(int row,
int col,
double val)
Sets a value at the specified row and column.
|
Matrix |
sqrt()
Creates a new matrix by taking the square root of this matrix.
|
double |
sum()
Gets the sum of all the matrix's elements.
|
Matrix |
transpose()
Transposes this matrix.
|
protected Matrix(int numRows,
int numCols)
numRows - The number of rows.numCols - The number of columns.public final int getElementCount()
public final int getRowCount()
public final int getColumnCount()
public final double getAt(int row,
int col)
row - The row.col - The column.public final void setAt(int row,
int col,
double val)
row - The row.col - The column.val - The value.public final void incrementAt(int row,
int col,
double val)
row - The row.col - The column.val - The value to increment by.public final ColumnVector getRowSumVector()
public final ColumnVector getColumnSumVector()
public java.util.Collection<java.lang.Integer> normalizeColumns()
public void removeNegatives()
public void removeLessThan(double minValue)
minValue - The minimum value that should not be set to zero.public final void scale(double scale)
scale - The scale factor.public Matrix multiplyElementWise(Matrix matrix)
matrix - The other matrix.public Matrix addElementWise(Matrix matrix)
matrix - The other matrix.public final double absSum()
public final double sum()
public ColumnVector multiply(ColumnVector vector)
vector - The vector.public final Matrix transpose()
public Matrix roundTo(int numPlaces)
numPlaces - The number of decimal places.public Matrix multiply(double scalar)
scalar - The scalar.public Matrix add(double scalar)
scalar - The scalar.public Matrix abs()
public Matrix sqrt()
public final boolean isSameSize(Matrix matrix)
matrix - The other matrix.public final boolean isZeroMatrix()
public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic void forEach(Matrix.ReadOnlyElementVisitorFunction func)
func - The function.protected abstract Matrix create(int numRows, int numCols)
numRows - The number of rows.numCols - The number of columns.protected abstract double getAtUnchecked(int row,
int col)
row - The row.col - The column.protected abstract void setAtUnchecked(int row,
int col,
double val)
row - The row.col - The column.val - The value.protected abstract void forEach(Matrix.ElementVisitorFunction func)
func - The function.public abstract MatrixNonZeroElementRowIterator getNonZeroElementRowIterator(int row)
row - The row index.