public final class Matrix extends java.lang.Object implements java.io.Serializable, DeepCloneable
Modifier and Type | Field and Description |
---|---|
double[][] |
m_afData |
int |
m_iCols |
int |
m_iRows |
static int |
NB_ROWS_BEYOND_WHICH_MATRIX_INVERSION_TAKES_TOO_MUCH_TIME |
protected static int |
SizeBeforeSwitchingToLUDecompositionInDeterminantCalculation |
Constructor and Description |
---|
Matrix(double[] data)
Constructor 2.
|
Matrix(double[][] data)
Constructor 1.
|
Matrix(int iRows,
int iCols)
Constructor 4.
|
Matrix(int iRows,
int iCols,
double from,
double iIncrement)
Constructor 5.
|
Matrix(java.util.List<? extends java.lang.Number> list)
Constructor 3.
|
Modifier and Type | Method and Description |
---|---|
Matrix |
add(Matrix m)
This method add matrix m to the current matrix.
|
void |
addElementsAt(java.util.List<java.lang.Integer> indices,
Matrix m)
This method add the elements of the parameter matrix to those designated through the indices.
|
boolean |
anyElementDifferentFrom(double d)
This method tests whether if any element of the Matrix object is
different from parameter d.
|
boolean |
anyElementLargerThan(double d)
This method tests whether if any element of the Matrix object is
larger than parameter d.
|
boolean |
anyElementSmallerOrEqualTo(double d)
This method tests whether if any element of the Matrix object is
smaller than or equal to parameter d.
|
Matrix |
diagonalVector()
This method return a vector that contains the diagonal element of this.
|
boolean |
doesContainAnyNaN()
This method returns true if the matrix contains at least one value NaN.
|
Matrix |
elementWiseDivide(Matrix m)
This method compute the elementwise division of this / m
|
Matrix |
elementWiseMultiply(Matrix m)
This method compute the elementwise product of this x m
|
Matrix |
elementWisePower(double power)
This method computes the elements of the matrix at a given power.
|
boolean |
equals(java.lang.Object obj) |
Matrix |
expMatrix()
Compute the exponential of the elements of this matrix.
|
Matrix |
getAbsoluteValue()
This method returns a Matrix object that contains the absolute values
of the original matrix.
|
Matrix |
getAdjugateMatrix()
This method returns the adjugate matrix of this matrix.
|
protected java.util.List<java.util.List<java.lang.Integer>> |
getBlockConfiguration()
This method returns a list of indices that defines the blocks in the matrix.
|
double |
getCofactor(int i,
int j)
This method returns the cofactor of this matrix with respect to the element i,j.
|
Matrix |
getDeepClone()
This method returns a deep clone of the object.
|
double |
getDeterminant()
This method returns the determinant of this matrix using Laplace's method for small matrices and LU decomposition
for larger matrices.
|
Matrix |
getElements(java.util.List<java.lang.Integer> indices)
This method returns the elements defined by the List indices in a row vector.
|
static Matrix |
getIdentityMatrix(int i) |
protected Matrix |
getInternalInverseMatrix() |
Matrix |
getInverseMatrix()
This method returns the inverse matrix of this matrix.
|
Matrix |
getIsserlisMatrix()
This method returns a Matrix that corresponds to the Isserlis theorem given that matrix this is
a variance-covariance matrix.
|
Matrix |
getKroneckerProduct(Matrix m)
This method calculates the Kronecker product of this by the m Matrix object.
|
java.util.List<java.lang.Integer> |
getLocationIndex(double d)
This method returns a List of integers, which represent the index of the elements
that are equal to parameter d.
|
Matrix |
getLowerCholTriangle()
This method compute the lower triangle of the Cholesky decomposition.
|
Matrix[] |
getLUDecomposition()
This method returns the LU decomposition of this Matrix instance.
|
double |
getMinor(int i,
int j)
This method returns the minor of this matrix, ie the determinant of the Matrix that
contains all the elements of the original matrix except those in row i and column j.
|
int |
getNumberOfElements()
This method returns the number of elements in a Matrix object.
|
Matrix |
getSubMatrix(int startRow,
int endRow,
int startColumn,
int endColumn)
This method returns a submatrix of this matrix.
|
Matrix |
getSubMatrix(java.util.List<java.lang.Integer> rowIndex,
java.util.List<java.lang.Integer> columnIndex)
This method returns a sub matrix whose elements correspond to the indices listed in
the row index list and the column index list.
|
double |
getSumOfElements()
This method returns the sum of all the elements in the Matrix instance.
|
double |
getSumOfElements(int startRow,
int endRow,
int startColumn,
int endColumn)
This method returns the sum of the elements of a submatrix.
|
double |
getTrace()
This method computes the trace of the matrix, i.e.
|
boolean |
isColumnVector()
This method checks if this is a column vector
|
boolean |
isDiagonalMatrix()
This method checks whether this matrix is a diagonal matrix, i.e.
|
boolean |
isPositiveDefinite()
This method checks if the matrix is positive definite.
|
boolean |
isRowVector()
This method checks if this is a row vector
|
boolean |
isSquare()
This method checks if this is a square matrix
|
boolean |
isSymmetric()
This method tests whether the matrix is symmetric.
|
boolean |
isTheSameDimension(Matrix m)
This method checks whether or not this and m have the same dimensions
|
Matrix |
logMatrix()
Compute the logarithm of the elements of this matrix
|
Matrix |
matrixDiagBlock(Matrix m)
This method creates a new matrix in which the current matrix represents the first diagonal block and matrix m represents the second
diagonal block.
|
Matrix |
matrixDiagonal()
This method compute a diagonal matrix from a row or a column vector.
|
Matrix |
matrixStack(Matrix m,
boolean stackOver)
This method creates a new matrix that is the stack of this and matrix m.
|
Matrix |
multiply(Matrix m)
This method compute the matrix multiplication product of this x m
|
Matrix |
powMatrix(double seed)
This method computes the power of the seed by the elements of the matrix.
|
Matrix |
removeElements(java.util.List<java.lang.Integer> index)
This method makes it possible to remove some elements in a
particular matrix
|
Matrix |
repeat(int nrow,
int ncol)
This method repeats this matrix a given number of times in each dimension.
|
void |
resetMatrix()
This method reset all the elements of this Matrix instance to 0.
|
Matrix |
scalarAdd(double d)
This method adds the scalar d to all the elements of the current matrix.
|
Matrix |
scalarMultiply(double d)
This method multiplies the elements of the current matrix by the scalar d.
|
void |
setElements(java.util.List<java.lang.Integer> indices,
Matrix m)
This method replaces the elements of the matrix designated through the indices by the values
in the row vector m.
|
void |
setSubMatrix(double[][] array,
int i,
int j)
This method replaces some elements of the matrix by those that are contained in an array of Double.
|
void |
setSubMatrix(Matrix m,
int i,
int j)
This method replaces some elements of the matrix by those that are contained in matrix m.
|
Matrix |
squareSym()
This method makes a square symmetric matrix from a vector.
|
Matrix |
subtract(Matrix m)
This method subtracts matrix m from the current matrix.
|
protected void |
swapAlongTheDiagonal(int i,
int j) |
Matrix |
symSquare()
This method returns a vector of the values corresponding to a symmetric matrix.
|
java.lang.String |
toString()
Returns a representation of the m_afData array.
|
Matrix |
transpose()
Creates a transposed matrix.
|
protected static int SizeBeforeSwitchingToLUDecompositionInDeterminantCalculation
public static int NB_ROWS_BEYOND_WHICH_MATRIX_INVERSION_TAKES_TOO_MUCH_TIME
public final double[][] m_afData
public int m_iRows
public int m_iCols
public Matrix(double[][] data)
public Matrix(double[] data)
data
- an array of double instances.public Matrix(java.util.List<? extends java.lang.Number> list)
list
- a List of Number-derived instancespublic Matrix(int iRows, int iCols)
iRows
- number of rowsiCols
- number of columnspublic Matrix(int iRows, int iCols, double from, double iIncrement)
iRows
- number of rowsiCols
- number of columnsfrom
- first element of the matrixiIncrement
- increment for the next elementspublic Matrix add(Matrix m)
m
- the matrix to be addedpublic boolean anyElementDifferentFrom(double d)
d
- the value to be checkedpublic boolean anyElementLargerThan(double d)
d
- the value to be checkedpublic boolean anyElementSmallerOrEqualTo(double d)
d
- the value to be checkedpublic Matrix diagonalVector()
java.lang.UnsupportedOperationException
- if the matrix is not squarepublic boolean doesContainAnyNaN()
public Matrix elementWiseDivide(Matrix m)
m
- public Matrix elementWiseMultiply(Matrix m)
m
- the matrix that contains the elements to be multiplied with.public Matrix expMatrix()
public Matrix getLowerCholTriangle()
java.lang.UnsupportedOperationException
- if the Cholesky factorisation cannot be completedpublic Matrix getSubMatrix(int startRow, int endRow, int startColumn, int endColumn)
startRow
- the index of the first row (included)endRow
- the index of the last row (included)startColumn
- the index of the first column (included)endColumn
- the index of the last column (included)public Matrix getSubMatrix(java.util.List<java.lang.Integer> rowIndex, java.util.List<java.lang.Integer> columnIndex)
rowIndex
- a List of integers (if null all the rows are selected)columnIndex
- a List of integers (if null all the columns are selected)public boolean isColumnVector()
public boolean isDiagonalMatrix()
public boolean isRowVector()
public boolean isSquare()
public boolean isSymmetric()
public boolean isTheSameDimension(Matrix m)
m
- a Matrix instancepublic Matrix logMatrix()
java.lang.UnsupportedOperationException
- if one element of the matrix is smaller than or equal to 0public Matrix matrixDiagBlock(Matrix m)
m
- the matrix to be diagonally blockedpublic Matrix matrixDiagonal()
java.lang.UnsupportedOperationException
- if this matrix is not a vectorpublic Matrix matrixStack(Matrix m, boolean stackOver)
m
- the matrix to stack.stackOver
- true if the stack is vertically or false if horizontallypublic Matrix multiply(Matrix m)
m
- a Matrix type objectpublic void resetMatrix()
public Matrix scalarAdd(double d)
d
- the scalar to be addedpublic Matrix scalarMultiply(double d)
d
- the multiplierpublic void setSubMatrix(double[][] array, int i, int j)
array
- a two-dimension array of Doublei
- the row index of the first element to be changedj
- the column index of the first element to be changedpublic void setSubMatrix(Matrix m, int i, int j)
m
- a Matrix instancei
- the row index of the first element to be changedj
- the column index of the first element to be changedpublic Matrix squareSym()
public Matrix symSquare()
public Matrix subtract(Matrix m)
m
- the matrix to be subtractedpublic double getTrace()
public Matrix transpose()
public Matrix powMatrix(double seed)
seed
- a doublepublic Matrix elementWisePower(double power)
power
- a doublepublic Matrix repeat(int nrow, int ncol)
nrow
- the number of times to repeat in row-wise directionncol
- the number of times to repeat in column-wise directionpublic Matrix removeElements(java.util.List<java.lang.Integer> index)
index
- is the index of the elements to be removedpublic Matrix getElements(java.util.List<java.lang.Integer> indices)
indices
- a List of indicespublic void setElements(java.util.List<java.lang.Integer> indices, Matrix m)
indices
- a List of Integer representing the indicesm
- a Matrix instancepublic void addElementsAt(java.util.List<java.lang.Integer> indices, Matrix m)
indices
- a List of Integer representing the indicesm
- a Matrix instancepublic java.util.List<java.lang.Integer> getLocationIndex(double d)
d
- the value that is checked forpublic double getSumOfElements()
public double getSumOfElements(int startRow, int endRow, int startColumn, int endColumn)
startRow
- the index of the starting rowendRow
- the index of the ending rowstartColumn
- the index of the starting columnendColumn
- the index of the ending columnpublic Matrix getAbsoluteValue()
public int getNumberOfElements()
public Matrix getKroneckerProduct(Matrix m)
m
- a Matrix instancepublic Matrix getIsserlisMatrix()
public boolean isPositiveDefinite()
public Matrix getDeepClone()
DeepCloneable
getDeepClone
in interface DeepCloneable
public java.lang.String toString()
toString
in class java.lang.Object
public Matrix[] getLUDecomposition()
java.lang.UnsupportedOperationException
- if the matrix is not squareprotected void swapAlongTheDiagonal(int i, int j)
protected java.util.List<java.util.List<java.lang.Integer>> getBlockConfiguration()
public double getMinor(int i, int j)
i
- the index of the row to be omittedj
- the index of the column to be omittedpublic double getCofactor(int i, int j)
i
- the row index of the elementj
- the column index of the elementpublic double getDeterminant()
java.lang.UnsupportedOperationException
- if the matrix is not squarepublic Matrix getAdjugateMatrix()
protected Matrix getInternalInverseMatrix()
public Matrix getInverseMatrix()
public static Matrix getIdentityMatrix(int i)
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object