public abstract class SimpleBase<T extends SimpleBase>
extends java.lang.Object
implements java.io.Serializable
SimpleMatrix implements all the standard matrix operations and uses
generics to allow the returned matrix type to be changed. This class should be extended
instead of SimpleMatrix.| Modifier and Type | Field and Description |
|---|---|
protected DenseMatrix64F |
mat
Internal matrix which this is a wrapper around.
|
| Modifier | Constructor and Description |
|---|---|
protected |
SimpleBase() |
|
SimpleBase(int numRows,
int numCols) |
| Modifier and Type | Method and Description |
|---|---|
T |
combine(int insertRow,
int insertCol,
T B)
Creates a new matrix that is a combination of this matrix and matrix B.
|
double |
conditionP2()
The condition p = 2 number of a matrix is used to measure the sensitivity of the linear
system Ax=b.
|
T |
copy()
Creates and returns a matrix which is idential to this one.
|
protected abstract T |
createMatrix(int numRows,
int numCols)
Used internally for creating new instances of SimpleMatrix.
|
double |
determinant()
Computes the determinant of the matrix.
|
T |
divide(double val)
Returns the result of dividing each element by 'val':
bi,j = ai,j/val
|
double |
dot(T v)
Computes the dot product (a.k.a.
|
SimpleEVD |
eig()
Returns the Eigen Value Decomposition (EVD) of this matrix.
|
T |
elementDiv(T b)
Returns a matrix which is the result of an element by element division of 'this' and 'b':
ci,j = ai,j/bi,j
|
T |
elementExp()
Returns a matrix which is the result of an element by element exp of 'this'
ci,j = Math.exp(ai,j)
|
T |
elementLog()
Returns a matrix which is the result of an element by element exp of 'this'
ci,j = Math.log(ai,j)
|
double |
elementMaxAbs()
Returns the maximum absolute value of all the elements in this matrix.
|
T |
elementMult(T b)
Returns a matrix which is the result of an element by element multiplication of 'this' and 'b':
ci,j = ai,j*bi,j
|
T |
elementPower(double b)
Returns a matrix which is the result of an element by element power of 'this' and 'b':
ci,j = ai,j ^ b
|
T |
elementPower(T b)
Returns a matrix which is the result of an element by element power of 'this' and 'b':
ci,j = ai,j ^ bi,j
|
double |
elementSum()
Computes the sum of all the elements in the matrix.
|
T |
extractDiag()
Extracts the diagonal from this matrix and returns them inside a column vector.
|
T |
extractMatrix(int y0,
int y1,
int x0,
int x1)
Creates a new SimpleMatrix which is a submatrix of this matrix.
|
T |
extractVector(boolean extractRow,
int element)
Extracts a row or column from this matrix.
|
double |
get(int index)
Returns the value of the matrix at the specified index of the 1D row major array.
|
double |
get(int row,
int col)
Returns the value of the specified matrix element.
|
int |
getIndex(int row,
int col)
Returns the index in the matrix's array.
|
DenseMatrix64F |
getMatrix()
Returns a reference to the matrix that it uses internally.
|
int |
getNumElements()
Returns the number of elements in this matrix, which is equal to
the number of rows times the number of columns.
|
boolean |
hasUncountable()
Checks to see if any of the elements in this matrix are either NaN or infinite.
|
void |
insertIntoThis(int insertRow,
int insertCol,
T B)
Copy matrix B into this matrix at location (insertRow, insertCol).
|
T |
invert()
Returns the inverse of this matrix.
b = a-1 |
boolean |
isIdentical(T a,
double tol)
Checks to see if matrix 'a' is the same as this matrix within the specified
tolerance.
|
boolean |
isInBounds(int row,
int col)
Returns true of the specified matrix element is valid element inside this matrix.
|
boolean |
isVector()
Returns true if this matrix is a vector.
|
MatrixIterator |
iterator(boolean rowMajor,
int minRow,
int minCol,
int maxRow,
int maxCol)
Creates a new iterator for traversing through a submatrix inside this matrix.
|
T |
kron(T B)
Computes the Kronecker product between this matrix and the provided B matrix:
C = kron(A,B) |
static SimpleMatrix |
loadBinary(java.lang.String fileName)
Loads a new matrix from a serialized binary file.
|
static SimpleMatrix |
loadCSV(java.lang.String fileName)
Loads a new matrix from a CSV file.
|
T |
minus(double b)
Returns the result of matrix-double subtraction:
c = a - b where c is the returned matrix, a is this matrix, and b is the passed in double. |
T |
minus(T b)
Returns the result of matrix subtraction:
c = a - b where c is the returned matrix, a is this matrix, and b is the passed in matrix. |
T |
mult(T b)
Returns a matrix which is the result of matrix multiplication:
c = a * b where c is the returned matrix, a is this matrix, and b is the passed in matrix. |
T |
negative()
Returns a new matrix whose elements are the negative of 'this' matrix's elements.
bij = -aij |
double |
normF()
Computes the Frobenius normal of the matrix:
normF = Sqrt{ ∑i=1:m ∑j=1:n { aij2} } |
int |
numCols()
Returns the number of columns in this matrix.
|
int |
numRows()
Returns the number of rows in this matrix.
|
T |
plus(double beta)
Performs a element-wise scale operation.
c = β*a where c is the returned matrix, a is this matrix. |
T |
plus(double beta,
T b)
Performs a matrix addition and scale operation.
c = a + β*b where c is the returned matrix, a is this matrix, and b is the passed in matrix. |
T |
plus(T b)
Returns the result of matrix addition:
c = a + b where c is the returned matrix, a is this matrix, and b is the passed in matrix. |
void |
print()
Prints the matrix to standard out.
|
void |
print(int numChar,
int precision)
Prints the matrix to standard out with the specified precision.
|
void |
print(java.lang.String format)
Prints the matrix to standard out given a {@link java.io.PrintStream#printf) style floating point format,
e.g.
|
void |
printDimensions()
Prints the number of rows and column in this matrix.
|
T |
pseudoInverse()
Computes the Moore-Penrose pseudo-inverse
|
void |
reshape(int numRows,
int numCols)
Reshapes the matrix to the specified number of rows and columns.
|
void |
saveToFileBinary(java.lang.String fileName)
Saves this matrix to a file as a serialized binary object.
|
void |
saveToFileCSV(java.lang.String fileName)
Saves this matrix to a file in a CSV format.
|
T |
scale(double val)
Returns the result of scaling each element by 'val':
bi,j = val*ai,j |
void |
set(double val)
Sets all the elements in this matrix equal to the specified value.
aij = val |
void |
set(int index,
double value)
Assigns an element a value based on its index in the internal array..
|
void |
set(int row,
int col,
double value)
Assigns the element in the Matrix to the specified value.
|
void |
set(T a)
Sets the elements in this matrix to be equal to the elements in the passed in matrix.
|
void |
setColumn(int column,
int offset,
double... values)
Assigns consecutive elements inside a column to the provided array.
A(offset:(offset + values.length),column) = values |
void |
setRow(int row,
int offset,
double... values)
Assigns consecutive elements inside a row to the provided array.
A(row,offset:(offset + values.length)) = values |
T |
solve(T b)
Solves for X in the following equation:
x = a-1b where 'a' is this matrix and 'b' is an n by p matrix. |
SimpleSVD |
svd()
Computes a full Singular Value Decomposition (SVD) of this matrix with the
eigenvalues ordered from largest to smallest.
|
SimpleSVD |
svd(boolean compact)
Computes the SVD in either compact format or full format.
|
java.lang.String |
toString()
Converts the array into a string format for display purposes.
|
double |
trace()
Computes the trace of the matrix.
|
T |
transpose()
Returns the transpose of this matrix.
aT |
void |
zero()
Sets all the elements in the matrix equal to zero.
|
protected DenseMatrix64F mat
public SimpleBase(int numRows,
int numCols)
protected SimpleBase()
protected abstract T createMatrix(int numRows, int numCols)
numRows - number of rows in the new matrix.numCols - number of columns in the new matrix.public DenseMatrix64F getMatrix()
Returns a reference to the matrix that it uses internally. This is useful when an operation is needed that is not provided by this class.
public T transpose()
Returns the transpose of this matrix.
aT
CommonOps.transpose(DenseMatrix64F,DenseMatrix64F)public T mult(T b)
Returns a matrix which is the result of matrix multiplication:
c = a * b
where c is the returned matrix, a is this matrix, and b is the passed in matrix.
b - A matrix that is n by bn. Not modified.CommonOps.mult(org.ejml.data.RowD1Matrix64F , org.ejml.data.RowD1Matrix64F , org.ejml.data.RowD1Matrix64F)public T kron(T B)
Computes the Kronecker product between this matrix and the provided B matrix:
C = kron(A,B)
B - The right matrix in the operation. Not modified.CommonOps.kron(DenseMatrix64F, DenseMatrix64F, DenseMatrix64F)public T plus(T b)
Returns the result of matrix addition:
c = a + b
where c is the returned matrix, a is this matrix, and b is the passed in matrix.
b - m by n matrix. Not modified.CommonOps.mult(org.ejml.data.RowD1Matrix64F , org.ejml.data.RowD1Matrix64F , org.ejml.data.RowD1Matrix64F)public T minus(T b)
Returns the result of matrix subtraction:
c = a - b
where c is the returned matrix, a is this matrix, and b is the passed in matrix.
b - m by n matrix. Not modified.CommonOps.subtract(org.ejml.data.D1Matrix64F , org.ejml.data.D1Matrix64F , org.ejml.data.D1Matrix64F)public T minus(double b)
Returns the result of matrix-double subtraction:
c = a - b
where c is the returned matrix, a is this matrix, and b is the passed in double.
b - Value subtracted from each elementCommonOps.subtract(org.ejml.data.D1Matrix64F , double , org.ejml.data.D1Matrix64F)public T plus(double beta)
Performs a element-wise scale operation.
c = β*a
where c is the returned matrix, a is this matrix.
beta - Double valueCommonOps.add( org.ejml.data.D1Matrix64F , double , org.ejml.data.D1Matrix64F)public T plus(double beta, T b)
Performs a matrix addition and scale operation.
c = a + β*b
where c is the returned matrix, a is this matrix, and b is the passed in matrix.
b - m by n matrix. Not modified.CommonOps.add( org.ejml.data.D1Matrix64F , double , org.ejml.data.D1Matrix64F , org.ejml.data.D1Matrix64F)public double dot(T v)
v - The second vector in the dot product. Not modified.public boolean isVector()
public T scale(double val)
Returns the result of scaling each element by 'val':
bi,j = val*ai,j
val - The multiplication factor.CommonOps.scale(double, org.ejml.data.D1Matrix64F)public T divide(double val)
Returns the result of dividing each element by 'val': bi,j = ai,j/val
val - Divisor.CommonOps.divide(org.ejml.data.D1Matrix64F,double)public T invert()
Returns the inverse of this matrix.
b = a-1
If the matrix could not be inverted then SingularMatrixException is thrown. Even if no exception is thrown the matrix could still be singular or nearly singular.
SingularMatrixExceptionCommonOps.invert(DenseMatrix64F, DenseMatrix64F)public T pseudoInverse()
Computes the Moore-Penrose pseudo-inverse
public T solve(T b)
Solves for X in the following equation:
x = a-1b
where 'a' is this matrix and 'b' is an n by p matrix.
If the system could not be solved then SingularMatrixException is thrown. Even if no exception is thrown 'a' could still be singular or nearly singular.
b - n by p matrix. Not modified.SingularMatrixExceptionCommonOps.solve(DenseMatrix64F, DenseMatrix64F, DenseMatrix64F)public void set(T a)
a - The matrix whose value this matrix is being set to.public void set(double val)
Sets all the elements in this matrix equal to the specified value.
aij = val
val - The value each element is set to.CommonOps.fill(org.ejml.data.D1Matrix64F , double)public void zero()
public double normF()
Computes the Frobenius normal of the matrix:
normF = Sqrt{ ∑i=1:m ∑j=1:n { aij2} }
NormOps.normF(org.ejml.data.D1Matrix64F)public double conditionP2()
The condition p = 2 number of a matrix is used to measure the sensitivity of the linear system Ax=b. A value near one indicates that it is a well conditioned matrix.
NormOps.conditionP2(DenseMatrix64F)public double determinant()
CommonOps.det(DenseMatrix64F)public double trace()
Computes the trace of the matrix.
CommonOps.trace(org.ejml.data.RowD1Matrix64F)public void reshape(int numRows,
int numCols)
Reshapes the matrix to the specified number of rows and columns. If the total number of elements is <= number of elements it had before the data is saved. Otherwise a new internal array is declared and the old data lost.
This is equivalent to calling A.getMatrix().reshape(numRows,numCols,false).
numRows - The new number of rows in the matrix.numCols - The new number of columns in the matrix.DenseMatrix64F.reshape(int,int,boolean)public void set(int row,
int col,
double value)
row - The row of the element.col - The column of the element.value - The element's new value.public void set(int index,
double value)
index - The matrix element that is being assigned a value.value - The element's new value.public void setRow(int row,
int offset,
double... values)
Assigns consecutive elements inside a row to the provided array.
A(row,offset:(offset + values.length)) = values
row - The row that the array is to be written to.offset - The initial column that the array is written to.values - Values which are to be written to the row in a matrix.public void setColumn(int column,
int offset,
double... values)
Assigns consecutive elements inside a column to the provided array.
A(offset:(offset + values.length),column) = values
column - The column that the array is to be written to.offset - The initial column that the array is written to.values - Values which are to be written to the row in a matrix.public double get(int row,
int col)
row - The row of the element.col - The column of the element.public double get(int index)
index - The element's index whose value is to be returnedD1Matrix64F.get(int)public int getIndex(int row,
int col)
row - The row number.col - The column number.DenseMatrix64F.getIndex(int, int)public MatrixIterator iterator(boolean rowMajor, int minRow, int minCol, int maxRow, int maxCol)
rowMajor - true means it will traverse through the submatrix by row first, false by columns.minRow - first row it will start at.minCol - first column it will start at.maxRow - last row it will stop at.maxCol - last column it will stop at.public T copy()
public int numRows()
public int numCols()
public int getNumElements()
public void print()
public void print(int numChar,
int precision)
public void print(java.lang.String format)
Prints the matrix to standard out given a {@link java.io.PrintStream#printf) style floating point format, e.g. print("%f").
public java.lang.String toString()
Converts the array into a string format for display purposes.
The conversion is done using MatrixIO.print(java.io.PrintStream, org.ejml.data.RealMatrix64F).
toString in class java.lang.Objectpublic T extractMatrix(int y0, int y1, int x0, int x1)
Creates a new SimpleMatrix which is a submatrix of this matrix.
si-y0 , j-x0 = oij for all y0 ≤ i < y1 and x0 ≤ j < x1
where 'sij' is an element in the submatrix and 'oij' is an element in the
original matrix.
If any of the inputs are set to T.END then it will be set to the last row or column in the matrix.
y0 - Start row.y1 - Stop row + 1.x0 - Start column.x1 - Stop column + 1.public T extractVector(boolean extractRow, int element)
Extracts a row or column from this matrix. The returned vector will either be a row or column vector depending on the input type.
extractRow - If true a row will be extracted.element - The row or column the vector is contained in.public T extractDiag()
Extracts the diagonal from this matrix and returns them inside a column vector.
CommonOps.extractDiag(DenseMatrix64F, DenseMatrix64F)public boolean isIdentical(T a, double tol)
a - The matrix it is being compared against.tol - How similar they must be to be equals.public boolean hasUncountable()
public SimpleSVD svd()
public SimpleSVD svd(boolean compact)
public SimpleEVD eig()
public void insertIntoThis(int insertRow,
int insertCol,
T B)
insertRow - First row the matrix is to be inserted into.insertCol - First column the matrix is to be inserted into.B - The matrix that is being inserted.public T combine(int insertRow, int insertCol, T B)
Creates a new matrix that is a combination of this matrix and matrix B. B is written into A at the specified location if needed the size of A is increased by growing it. A is grown by padding the new area with zeros.
While useful when adding data to a matrix which will be solved for it is also much less efficient than predeclaring a matrix and inserting data into it.
If insertRow or insertCol is set to SimpleMatrix.END then it will be combined at the last row or column respectively.
insertRow - Row where matrix B is written in to.insertCol - Column where matrix B is written in to.B - The matrix that is written into A.public double elementMaxAbs()
public double elementSum()
public T elementMult(T b)
Returns a matrix which is the result of an element by element multiplication of 'this' and 'b': ci,j = ai,j*bi,j
b - A simple matrix.public T elementDiv(T b)
Returns a matrix which is the result of an element by element division of 'this' and 'b': ci,j = ai,j/bi,j
b - A simple matrix.public T elementPower(T b)
Returns a matrix which is the result of an element by element power of 'this' and 'b': ci,j = ai,j ^ bi,j
b - A simple matrix.public T elementPower(double b)
Returns a matrix which is the result of an element by element power of 'this' and 'b': ci,j = ai,j ^ b
b - Scalarpublic T elementExp()
Returns a matrix which is the result of an element by element exp of 'this' ci,j = Math.exp(ai,j)
public T elementLog()
Returns a matrix which is the result of an element by element exp of 'this' ci,j = Math.log(ai,j)
public T negative()
Returns a new matrix whose elements are the negative of 'this' matrix's elements.
bij = -aij
public void saveToFileBinary(java.lang.String fileName)
throws java.io.IOException
Saves this matrix to a file as a serialized binary object.
fileName - java.io.IOExceptionMatrixIO.saveBin( org.ejml.data.RealMatrix64F, String)public static SimpleMatrix loadBinary(java.lang.String fileName) throws java.io.IOException
Loads a new matrix from a serialized binary file.
fileName - File which is to be loaded.java.io.IOExceptionMatrixIO.loadBin(String)public void saveToFileCSV(java.lang.String fileName)
throws java.io.IOException
Saves this matrix to a file in a CSV format. For the file format see MatrixIO.
fileName - java.io.IOExceptionMatrixIO.saveBin( org.ejml.data.RealMatrix64F, String)public static SimpleMatrix loadCSV(java.lang.String fileName) throws java.io.IOException
Loads a new matrix from a CSV file. For the file format see MatrixIO.
fileName - File which is to be loaded.java.io.IOExceptionMatrixIO.loadCSV(String)public boolean isInBounds(int row,
int col)
row - Row index.col - Column index.public void printDimensions()