public class Matrix
extends java.lang.Object
implements java.lang.Cloneable
Modifier and Type | Class and Description |
---|---|
static class |
Matrix.Function
A transformation function that can be used to map input to a different
output.
|
Constructor and Description |
---|
Matrix(double[][] values)
A mathematical matrix containing an array of values.
|
Matrix(int rows,
int cols)
A mathematical matrix containing an array of values.
|
Matrix(int rows,
int cols,
double defaultValue)
A mathematical matrix containing an array of values.
|
Modifier and Type | Method and Description |
---|---|
Matrix |
add(double value)
Add a value to every item in the matrix.
|
Matrix |
add(Matrix mat)
Add two matrices together.
|
java.lang.Object |
clone() |
Matrix |
convertToOneColumn()
Convert the entire matrix to one column.
|
Matrix |
convertToOneRow()
Convert the entire matrix to one row.
|
Matrix |
dot(Matrix mat)
Apply the dot product to two matrices.
|
int[] |
find(double value)
Find a value in the matrix.
|
double |
get(int row,
int col)
Get a value in the matrix.
|
double[] |
getColumn(int col)
Get a column of the matrix.
|
int |
getNumCols()
Get the number of columns in the matrix.
|
int |
getNumRows()
Get the number of rows in the matrix.
|
double[] |
getRow(int row)
Get a row of the matrix.
|
double[][] |
getValues()
Get the values of the matrix.
|
Matrix |
map(Matrix.Function fn)
Map each item in the matrix to a different value using a transformation
function.
|
double |
max()
Get the max value of the matrix.
|
double |
min()
Get the min value of the matrix.
|
Matrix |
multiply(double value)
Multiply each item in the matrix by a value.
|
Matrix |
multiply(Matrix mat)
Multiply two matrices together using element wise multiplication.
|
Matrix |
normalize()
Normalize a matrix (All values will be scaled from 0..1 in proportion to
the max value)
|
Matrix |
oneHot()
Make the max value in the matrix 1 and all others 0.
|
Matrix |
power(double power)
Raise every item in the matrix to a power.
|
void |
set(int row,
int col,
double value)
Set a value in the matrix.
|
void |
setValues(double[][] values)
Set the values of the matrix.
|
Matrix |
subtract(double value)
Subtract a value from every item in the matrix.
|
Matrix |
subtract(Matrix mat)
Subtract two matrices.
|
double |
sum()
Get the sum of all of the elements of the matrix.
|
java.lang.String |
toString() |
Matrix |
transpose()
Transpose a matrix.
|
public Matrix(double[][] values)
values
- The values of the Matrix formated as double[rows][columns]public Matrix(int rows, int cols)
rows
- The number of rows in the matrix.cols
- The number of columns in the matrix.public Matrix(int rows, int cols, double defaultValue)
rows
- The number of rows in the matrix.cols
- The number of columns in the matrix.defaultValue
- The default value of each item in the matrix.public Matrix map(Matrix.Function fn)
fn
- The function to apply to each item in the matrix.public Matrix dot(Matrix mat)
mat
- The matrix to multiply by.public Matrix power(double power)
power
- The power to raise each item to.public Matrix multiply(Matrix mat)
mat
- The matrix to multiply by.public Matrix multiply(double value)
value
- The value to multiply each item by.public Matrix transpose()
public Matrix add(Matrix mat)
mat
- The matrix to add to this matrix.public Matrix add(double value)
value
- The amount to add to each item.public Matrix subtract(Matrix mat)
mat
- The matrix to subtract from this matrix.public Matrix subtract(double value)
value
- The amount to subtract from each item.public Matrix normalize()
public Matrix oneHot()
public Matrix convertToOneRow()
public Matrix convertToOneColumn()
public double max()
public double min()
public int[] find(double value)
value
- The target value.public double sum()
public double[][] getValues()
public void setValues(double[][] values)
values
- The new values of the matrix as a double[][].public int getNumRows()
public int getNumCols()
public double get(int row, int col)
row
- The row of the value.col
- The column of the value.public void set(int row, int col, double value)
row
- The row of the value.col
- The column of the valuevalue
- The new value for [row, col]public double[] getRow(int row)
row
- The row number of the matrix.public double[] getColumn(int col)
col
- The column number of the matrix.public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.Object clone()
clone
in class java.lang.Object