public class DecomposedSymmetricPositiveMatrix extends AbstractRealMatrix implements SymmetricPositiveMatrix
The matrix A is symmetric positive semi-definite by definition for any matrix B. Although the matrix A is always a NxN matrix, this is not necessarily the case for the matrix B: any NxM matrix multiplied by its transpose will yield a NxN matrix.
The decomposition matrix B is not unique and building it is left to the user. Typically, this
matrix is computed through a Cholesky decomposition A = L×LT, where L
is a lower-triangular matrix. The matrix yielded by this decomposition is unique for positive
definite matrices, but is not for positive semi-definite matrices (the implementation
CholeskyDecomposition does not even support the latter). It can also be obtained through
a LDL decomposition (A = L×D×LT), or through an eigen
decomposition (A = V×D×VT).
| Constructor and Description |
|---|
DecomposedSymmetricPositiveMatrix(double[][] dataBT)
Builds a new
DecomposedSymmetricPositiveMatrix by specifying the data of a matrix
BT which satisfies A = B×BT. |
DecomposedSymmetricPositiveMatrix(double[][] dataBT,
boolean copyArray)
Builds a new
DecomposedSymmetricPositiveMatrix by specifying the data of a matrix
BT which satisfies A = B×BT. |
DecomposedSymmetricPositiveMatrix(int n)
Builds a new DecomposedSymmetricPositiveMatrix of dimension n (filled with
zero).
|
DecomposedSymmetricPositiveMatrix(RealMatrix matrixBTranspose)
Builds a new
SymmetricPositiveMatrix by specifying a matrix BT which
satisfies A = B×BT. |
DecomposedSymmetricPositiveMatrix(RealMatrix matrixBTranspose,
boolean copyMatrix)
Builds a new
SymmetricPositiveMatrix by specifying a matrix BT which
satisfies A = B×BT. |
| Modifier and Type | Method and Description |
|---|---|
DecomposedSymmetricPositiveMatrix |
add(DecomposedSymmetricPositiveMatrix m)
Adds another
DecomposedSymmetricPositiveMatrix to this matrix. |
DecomposedSymmetricPositiveMatrix |
add(DecomposedSymmetricPositiveMatrix m,
boolean resize)
Adds another
DecomposedSymmetricPositiveMatrix to this matrix. |
RealMatrix |
add(RealMatrix m)
Returns the result of adding the matrix
m to this matrix. |
SymmetricMatrix |
add(SymmetricMatrix m)
Returns the result of adding the symmetric matrix
m to this matrix. |
SymmetricPositiveMatrix |
add(SymmetricPositiveMatrix m)
Returns the result of adding the symmetric positive semi-definite matrix
m to this
matrix. |
void |
addToEntry(int row,
int column,
double increment)
Adds (in place) a given value to the specified entry of this matrix.
|
static DecomposedSymmetricPositiveMatrix |
castOrTransform(SymmetricPositiveMatrix matrix)
Cast or transform the provided matrix into a
DecomposedSymmetricPositiveMatrix. |
RealMatrix |
concatenateDiagonally(RealMatrix m,
boolean rightConcatenation,
boolean lowerConcatenation)
Diagonally or anti-diagonally concatenates this matrix and another matrix
m. |
RealMatrix |
concatenateHorizontally(RealMatrix m,
boolean rightConcatenation)
Horizontally concatenates this matrix and another matrix
m, , placing it in the left
or right part of the concatenated matrix. |
RealMatrix |
concatenateVertically(RealMatrix m,
boolean lowerConcatenation)
Vertically concatenates this matrix and another matrix
m, placing it in the lower or
upper part of the concatenated matrix. |
DecomposedSymmetricPositiveMatrix |
copy()
Returns a deep copy of this matrix.
|
static DecomposedSymmetricPositiveMatrix |
createIdentityMatrix(int dim)
Creates an identity matrix of the specified dimension.
|
DecomposedSymmetricPositiveMatrix |
createMatrix(int rowDimension,
int columnDimension)
Creates a new matrix of the same type as this matrix.
|
RealMatrix |
getB()
Gets the matrix B of the decomposition A = B×BT of this matrix.
|
RealMatrix |
getBT()
Gets the matrix BT of the decomposition A = B×BT of this matrix.
|
RealMatrix |
getBT(boolean copyMatrix)
Gets the matrix BT of the decomposition A = B×BT of this matrix.
|
int |
getColumnDimension()
Returns the dimension of the domain of this operator.
|
RealMatrix |
getColumnMatrix(int column)
Gets the entries of a given column as a column matrix.
|
double |
getEntry(int row,
int column)
Gets the entry at the specified row and column.
|
DecomposedSymmetricPositiveMatrix |
getInverse()
Gets the inverse of the matrix.
|
DecomposedSymmetricPositiveMatrix |
getInverse(Function<RealMatrix,Decomposition> decompositionBuilder)
Gets the inverse of the matrix.
|
RealMatrix |
getResizedB()
Gets the matrix B after reducing or extending it to match this matrix's dimensions.
|
RealMatrix |
getResizedBT()
Gets the matrix BT after reducing or extending it to match this matrix's
dimensions.
|
int |
getRowDimension()
Returns the dimension of the codomain of this operator.
|
RealMatrix |
getRowMatrix(int row)
Gets the entries of a given row as a row matrix.
|
DecomposedSymmetricPositiveMatrix |
getSubMatrix(int[] indices)
Extracts the submatrix corresponding to the specified indices.
|
RealMatrix |
getSubMatrix(int[] selectedRows,
int[] selectedColumns)
Gets a submatrix.
|
DecomposedSymmetricPositiveMatrix |
getSubMatrix(int startIndex,
int endIndex)
Extracts the submatrix corresponding to the specified indices.
|
RealMatrix |
getSubMatrix(int startRow,
int endRow,
int startColumn,
int endColumn)
Gets a submatrix.
|
int |
getTransparentDimension()
Gets this matrix's transparent dimension (i.e. the number of columns of the matrix B).
|
boolean |
isSquare()
Is this a square matrix?
|
boolean |
isSymmetric()
Is this a symmetric matrix?
|
boolean |
isSymmetric(double relativeTolerance)
Is this a symmetric matrix?
|
boolean |
isSymmetric(double relativeTolerance,
double absoluteTolerance)
Is this a symmetric matrix?
|
RealMatrix |
multiply(DiagonalMatrix m,
double d)
Returns the result of postmultiplying this matrix by the diagonal matrix
m, then by
the scalar d. |
RealMatrix |
multiply(RealMatrix m,
boolean toTranspose,
double d)
Returns the result of postmultiplying this matrix by the matrix
m or its transpose
mT, then by the scalar d. |
void |
multiplyEntry(int row,
int column,
double factor)
Multiplies (in place) the specified entry of
this matrix by a given value. |
DecomposedSymmetricPositiveMatrix |
positiveScalarAdd(double d)
Returns the result of adding a positive scalar
d to the entries of this matrix. |
DecomposedSymmetricPositiveMatrix |
positiveScalarMultiply(double d)
Returns the result of multiplying the entries of this matrix by a positive scalar
d. |
DecomposedSymmetricPositiveMatrix |
power(int p)
Returns the the result of multiplying this matrix with itself
p times. |
DecomposedSymmetricPositiveMatrix |
quadraticMultiplication(RealMatrix m)
Returns the result of the quadratic multiplication M×
this×MT,
where M is the provided matrix. |
DecomposedSymmetricPositiveMatrix |
quadraticMultiplication(RealMatrix m,
boolean isTranspose)
Returns the result of the quadratic multiplication M×
this×MT,
where M or MT is the provided matrix. |
DecomposedSymmetricPositiveMatrix |
resizeB()
Reduces or extends the matrix B to ensure it is a NxN matrix.
|
SymmetricMatrix |
scalarAdd(double d)
Returns the result of adding a scalar
d to the entries of this matrix. |
SymmetricMatrix |
scalarMultiply(double d)
Returns the result of multiplying the entries of this matrix by the scalar
d. |
void |
setColumn(int column,
double[] array)
Replaces the entries of a given column with the entries of the specified data array.
|
void |
setColumnMatrix(int column,
RealMatrix matrix)
Replaces the entries of a given column with the entries of the specified column matrix.
|
void |
setColumnVector(int column,
RealVector vector)
Replaces the entries of a given column with the entries of the specified vector.
|
void |
setEntry(int row,
int column,
double value)
Sets the entry for the specified row and column.
|
void |
setRow(int row,
double[] array)
Replaces the entries of a given row with the entries of the specified data array.
|
void |
setRowMatrix(int row,
RealMatrix matrix)
Replaces the entries of a given row with the entries of the specified row matrix.
|
void |
setRowVector(int row,
RealVector vector)
Replaces the entries of a given row with the entries of the specified vector.
|
void |
setSubMatrix(double[][] subMatrix,
int row,
int column)
Replaces part of the matrix with a given submatrix, starting at the specified row and column.
|
RealMatrix |
subtract(RealMatrix m)
Returns the result of subtracting the matrix
m from this matrix. |
ArrayRowSymmetricMatrix |
subtract(SymmetricMatrix m)
Returns the result of subtracting the symmetric matrix
m from this matrix. |
ArrayRowSymmetricMatrix |
toArrayRowSymmetricMatrix()
Gets the matrix A = B×BT represented by this instance, stored in a new
ArrayRowSymmetricMatrix.
|
ArrayRowSymmetricPositiveMatrix |
toArrayRowSymmetricPositiveMatrix()
Gets the matrix A = B×BT represented by this instance, stored in a new
ArrayRowSymmetricPositiveMatrix.
|
DecomposedSymmetricPositiveMatrix |
transpose()
Returns the transpose of this matrix.
|
DecomposedSymmetricPositiveMatrix |
transpose(boolean forceCopy)
Returns the transpose of this matrix.
|
double |
walkInColumnOrder(RealMatrixChangingVisitor visitor)
Visits (and possibly change) all matrix entries in column order.
|
double |
walkInColumnOrder(RealMatrixChangingVisitor visitor,
int startRow,
int endRow,
int startColumn,
int endColumn)
Visits (and possibly change) some matrix entries in column order.
|
double |
walkInOptimizedOrder(RealMatrixChangingVisitor visitor)
Visits (and possibly change) all matrix entries using the fastest possible order.
|
double |
walkInOptimizedOrder(RealMatrixChangingVisitor visitor,
int startRow,
int endRow,
int startColumn,
int endColumn)
Visits (and possibly change) some matrix entries using the fastest possible order.
|
double |
walkInRowOrder(RealMatrixChangingVisitor visitor)
Visits (and possibly change) all matrix entries in row order.
|
double |
walkInRowOrder(RealMatrixChangingVisitor visitor,
int startRow,
int endRow,
int startColumn,
int endColumn)
Visits (and possibly change) some matrix entries in row order.
|
checkDestinationArray, checkSquare, concatenateDiagonally, concatenateDiagonally, concatenateHorizontally, concatenateVertically, copySubMatrix, copySubMatrix, copySubMatrix, copySubMatrix, equals, equals, getAbs, getColumn, getColumnVector, getData, getData, getDefaultDecomposition, getDiagonal, getFrobeniusNorm, getMax, getMin, getNorm, getRow, getRowVector, getTrace, hashCode, isAntisymmetric, isDiagonal, isInvertible, isOrthogonal, multiply, multiply, operate, operate, preMultiply, preMultiply, preMultiply, setDefaultDecomposition, toString, toString, walkInColumnOrder, walkInColumnOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInRowOrder, walkInRowOrderisTransposable, operateTransposeclone, finalize, getClass, notify, notifyAll, wait, wait, waitgetDiagonalconcatenateDiagonally, concatenateDiagonally, concatenateHorizontally, concatenateVertically, copySubMatrix, copySubMatrix, copySubMatrix, copySubMatrix, equals, getAbs, getColumn, getColumnVector, getData, getData, getDefaultDecomposition, getFrobeniusNorm, getMax, getMax, getMin, getMin, getNorm, getRow, getRowVector, getTrace, isAntisymmetric, isDiagonal, isInvertible, isOrthogonal, multiply, multiply, operate, operate, preMultiply, preMultiply, preMultiply, setDefaultDecomposition, toString, walkInColumnOrder, walkInColumnOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInRowOrder, walkInRowOrderpublic DecomposedSymmetricPositiveMatrix(int n)
n - the dimension of the matrixpublic DecomposedSymmetricPositiveMatrix(double[][] dataBT)
DecomposedSymmetricPositiveMatrix by specifying the data of a matrix
BT which satisfies A = B×BT.
The provided array is copied, not referenced.
dataBT - the data of the matrix BTpublic DecomposedSymmetricPositiveMatrix(double[][] dataBT,
boolean copyArray)
DecomposedSymmetricPositiveMatrix by specifying the data of a matrix
BT which satisfies A = B×BT.dataBT - the data of the matrix BTcopyArray - if false, the provided array will be referenced instead of being copiedpublic DecomposedSymmetricPositiveMatrix(RealMatrix matrixBTranspose)
SymmetricPositiveMatrix by specifying a matrix BT which
satisfies A = B×BT.matrixBTranspose - the matrix BTpublic DecomposedSymmetricPositiveMatrix(RealMatrix matrixBTranspose, boolean copyMatrix)
SymmetricPositiveMatrix by specifying a matrix BT which
satisfies A = B×BT.matrixBTranspose - the matrix BTcopyMatrix - if false, the provided matrix will be referenced instead of being copiedpublic RealMatrix getB()
This method returns a copy of the BT matrix stored internally.
public RealMatrix getBT()
public RealMatrix getBT(boolean copyMatrix)
This method returns a copy of the matrix BT if copyMatrix is set to
true. Otherwise, it returns a direct reference to the matrix stored internally.
Access to the internal matrix is provided for optimization purposes only. Modifying the
returned matrix is strongly discouraged, as any change made on it will also apply to this
matrix.
copyMatrix - whether to return a copy of the BT matrix (true) or its reference (
false)public int getRowDimension()
getRowDimension in interface AnyMatrixgetRowDimension in class AbstractRealMatrixpublic int getColumnDimension()
getColumnDimension in interface AnyMatrixgetColumnDimension in class AbstractRealMatrixpublic int getTransparentDimension()
public ArrayRowSymmetricMatrix toArrayRowSymmetricMatrix()
public ArrayRowSymmetricPositiveMatrix toArrayRowSymmetricPositiveMatrix()
public double getEntry(int row,
int column)
Row and column indices start at 0.
getEntry in interface RealMatrixgetEntry in class AbstractRealMatrixrow - the row index of entry to be fetchedcolumn - the column index of entry to be fetchedpublic void setEntry(int row,
int column,
double value)
Important:
This method systematically throws a MathUnsupportedOperationException since this
operation is not safe when dealing with symmetric positive definite matrices (the properties
of the matrix are not guaranteed to be preserved).
setEntry in interface RealMatrixsetEntry in class AbstractRealMatrixrow - the row index of entry to be set.column - the column index of entry to be set.value - the new value of the entry.MathUnsupportedOperationException - systematically, since this operation is not supportedpublic void addToEntry(int row,
int column,
double increment)
Row and column indices start at 0.
Important:
This method systematically throws a MathUnsupportedOperationException since this
operation is not safe when dealing with symmetric positive definite matrices (the properties
of the matrix are not guaranteed to be preserved).
addToEntry in interface RealMatrixaddToEntry in class AbstractRealMatrixrow - the row index of the entry to be modifiedcolumn - the column index of the entry to be modifiedincrement - the value to add to the matrix entryMathUnsupportedOperationException - systematically (this operation is forbidden)public void multiplyEntry(int row,
int column,
double factor)
this matrix by a given value.
Row and column indices start at 0.
Important:
This method systematically throws a MathUnsupportedOperationException since this
operation is not safe when dealing with symmetric positive definite matrices (the properties
of the matrix are not guaranteed to be preserved).
multiplyEntry in interface RealMatrixmultiplyEntry in class AbstractRealMatrixrow - the row index of the entry to be modifiedcolumn - the column index of the entry to be modifiedfactor - the multiplication factor for the matrix entrypublic RealMatrix getSubMatrix(int startRow, int endRow, int startColumn, int endColumn)
Rows and columns are indicated counting from 0 to n-1.
The returned matrix is an DecomposedSymmetricPositiveMatrix if the selected indices are the same for the rows and the columns, and an Array2DRowRealMatrix or a BlockRealMatrix otherwise.
getSubMatrix in interface RealMatrixgetSubMatrix in class AbstractRealMatrixstartRow - the initial row indexendRow - the final row index (inclusive)startColumn - the initial column indexendColumn - the final column index (inclusive)public RealMatrix getSubMatrix(int[] selectedRows, int[] selectedColumns)
Rows and columns are indicated counting from 0 to n-1.
The returned matrix is a DecomposedSymmetricPositiveMatrix if the selected indices are the same for the rows and the columns (same indices, same order), and an Array2DRowRealMatrix or a BlockRealMatrix otherwise.
getSubMatrix in interface RealMatrixgetSubMatrix in class AbstractRealMatrixselectedRows - the selected row indicesselectedColumns - the selected column indicespublic DecomposedSymmetricPositiveMatrix getSubMatrix(int startIndex, int endIndex)
This method uses the same start/end indices to select the rows and columns to be extracted. These indices must be valid indices with respect to the dimensions of the matrix (valid indices range from 0 to n-1, with n the row/column dimension of the matrix). Calling this method is equivalent to calling RealMatrix.getSubMatrix(int, int, int, int) using the same start/end indices for the rows and columns. The extracted submatrix is guaranteed to be symmetric. It will also remain positive semi-definite if the initial matrix originally is.
Usage examples:
// Initial matrix
matrix = [a00, a10, a20]
[a10, a11, a21]
[a20, a21, a22]
// Submatrix extraction
matrix.getSubMatrix(1, 2) => [a11, a21]
[a21, a22]
getSubMatrix in interface SymmetricMatrixgetSubMatrix in interface SymmetricPositiveMatrixstartIndex - the initial row/column indexendIndex - the final row/column index (inclusive)public DecomposedSymmetricPositiveMatrix getSubMatrix(int[] indices)
This method uses a single index array to select the rows and columns to be extracted. All indices must be valid indices with respect to the dimensions of the matrix (valid indices range from 0 to n-1, with n the row/column dimension of the matrix). The provided index array is allowed to contain duplicates. Calling this method is equivalent to calling RealMatrix.getSubMatrix(int[], int[]) using the provided index array for the selected rows and columns. This method can be used to extract any submatrix and perform a symmetric reordering of its rows/columns. The extracted submatrix is guaranteed to be symmetric. It will also remain positive semi-definite if the initial matrix originally is.
Usage examples:
// Initial matrix
matrix = [a00, a10, a20]
[a10, a11, a21]
[a20, a21, a22]
// Submatrix extraction
matrix.getSubMatrix([1, 2]) => [a11, a21]
[a21, a22]
// Rows/Columns permutation
matrix.getSubMatrix([1, 2, 0]) => [a11, a21, a10]
[a21, a22, a20]
[a10, a20, a00]
// Submatrix extraction (with duplicated indices)
matrix.getSubMatrix([1, 2, 0, 1, 0])
=> [a11, a21, a10, a11, a10]
[a21, a22, a20, a21, a20]
[a10, a20, a00, a10, a00]
[a11, a21, a10, a11, a10]
[a10, a20, a00, a10, a00]
getSubMatrix in interface SymmetricMatrixgetSubMatrix in interface SymmetricPositiveMatrixindices - the selected indicespublic void setSubMatrix(double[][] subMatrix,
int row,
int column)
Important:
This method systematically throws a MathUnsupportedOperationException since this
operation is not safe when dealing with symmetric positive definite matrices (the properties
of the matrix are not guaranteed to be preserved).
setSubMatrix in interface RealMatrixsetSubMatrix in class AbstractRealMatrixsubMatrix - the array containing the replacement data of the targeted submatrixrow - the row coordinate of the top, left element to be replacedcolumn - the column coordinate of the top, left element to be replacedMathUnsupportedOperationException - systematically, since this operation is not supportedpublic RealMatrix getRowMatrix(int row)
Row indices start at 0.
getRowMatrix in interface RealMatrixgetRowMatrix in class AbstractRealMatrixrow - the index of the row to be fetchedpublic RealMatrix getColumnMatrix(int column)
Column indices start at 0.
getColumnMatrix in interface RealMatrixgetColumnMatrix in class AbstractRealMatrixcolumn - the index of the column to be fetchedpublic void setRow(int row,
double[] array)
Row indices start at 0.
The size of the provided data array must match the column dimension of this matrix.
Important:
This method systematically throws a MathUnsupportedOperationException since this operation is not safe
when dealing with symmetric positive definite matrices (the properties of the matrix are not guaranteed to be
preserved).
setRow in interface RealMatrixsetRow in class AbstractRealMatrixrow - the index of the row to be replacedarray - the row data array to be copiedMathUnsupportedOperationException - systematically, since this operation is not supportedpublic void setRowVector(int row,
RealVector vector)
Row indices start at 0.
The size of the provided vector must match the column dimension of this matrix.
Important:
This method systematically throws a MathUnsupportedOperationException since this
operation is not safe when dealing with symmetric positive definite matrices (the properties
of the matrix are not guaranteed to be preserved).
setRowVector in interface RealMatrixsetRowVector in class AbstractRealMatrixrow - the index of the row to be replacedvector - the row vector to be copiedMathUnsupportedOperationException - systematically, since this operation is not supportedpublic void setRowMatrix(int row,
RealMatrix matrix)
Row indices start at 0.
The provided matrix must have one row and the same number of columns as this matrix.
Important:
This method systematically throws a MathUnsupportedOperationException since this
operation is not safe when dealing with symmetric positive definite matrices (the properties
of the matrix are not guaranteed to be preserved).
setRowMatrix in interface RealMatrixsetRowMatrix in class AbstractRealMatrixrow - the index of the row to be replacedmatrix - the row matrix to be copiedMathUnsupportedOperationException - systematically, since this operation is not supportedpublic void setColumn(int column,
double[] array)
Column indices start at 0.
The size of the provided data array must match the row dimension of this matrix.
Important:
This method systematically throws a MathUnsupportedOperationException since this
operation is not safe when dealing with symmetric positive definite matrices (the properties
of the matrix are not guaranteed to be preserved).
setColumn in interface RealMatrixsetColumn in class AbstractRealMatrixcolumn - the index of the column to be replacedarray - the column data array to be copiedMathUnsupportedOperationException - systematically, since this operation is not supportedpublic void setColumnVector(int column,
RealVector vector)
Column indices start at 0.
The size of the provided vector must match the row dimension of this matrix.
Important:
This method systematically throws a MathUnsupportedOperationException since this
operation is not safe when dealing with symmetric positive definite matrices (the properties
of the matrix are not guaranteed to be preserved).
setColumnVector in interface RealMatrixsetColumnVector in class AbstractRealMatrixcolumn - the index of the column to be replacedvector - the column vector to be copiedMathUnsupportedOperationException - systematically, since this operation is not supportedpublic void setColumnMatrix(int column,
RealMatrix matrix)
Column indices start at 0.
The provided matrix must have one column and the same number of rows as this matrix.
Important:
This method systematically throws a MathUnsupportedOperationException since this
operation is not safe when dealing with symmetric positive definite matrices (the properties
of the matrix are not guaranteed to be preserved).
setColumnMatrix in interface RealMatrixsetColumnMatrix in class AbstractRealMatrixcolumn - the index of the column to be replacedmatrix - the column matrix to be copiedMathUnsupportedOperationException - systematically, since this operation is not supportedpublic SymmetricMatrix scalarAdd(double d)
d to the entries of this matrix.scalarAdd in interface RealMatrixscalarAdd in interface SymmetricMatrixscalarAdd in class AbstractRealMatrixd - the scalar value to be added to the entries of this matrixthis+dpublic DecomposedSymmetricPositiveMatrix positiveScalarAdd(double d)
d to the entries of this matrix.
The scalar addition is computed by doing a vertical concatenation between the BT matrix and a row matrix storing the square root of the scalar to add.
positiveScalarAdd in interface SymmetricPositiveMatrixd - the positive scalar value to be added to the entries of this matrixthis+
dpublic SymmetricMatrix scalarMultiply(double d)
d.scalarMultiply in interface RealMatrixscalarMultiply in interface SymmetricMatrixscalarMultiply in class AbstractRealMatrixd - the scalar value by which to multiply the entries of this matrix bythis×dpublic DecomposedSymmetricPositiveMatrix positiveScalarMultiply(double d)
d.positiveScalarMultiply in interface SymmetricPositiveMatrixd - the positive scalar value by which to multiply the entries of this matrix byd
×thispublic RealMatrix add(RealMatrix m)
m to this matrix.
The returned matrix is, in order of priority:
add in interface RealMatrixadd in class AbstractRealMatrixm - the matrix to be addedthis+mpublic SymmetricMatrix add(SymmetricMatrix m)
m to this matrix.
The returned matrix is, in order of priority:
add in interface SymmetricMatrixm - the matrix to be addedthis+mpublic SymmetricPositiveMatrix add(SymmetricPositiveMatrix m)
m to this
matrix.
The returned matrix is, in order of priority:
add in interface SymmetricPositiveMatrixm - the symmetric positive semi-definite matrix to be addedthis+
mpublic DecomposedSymmetricPositiveMatrix add(DecomposedSymmetricPositiveMatrix m)
DecomposedSymmetricPositiveMatrix to this matrix.
Adding another DecomposedSymmetricPositiveMatrix amounts to concatenating their B
matrices horizontally. As a result, the number of column of the matrix B increases with each
addition. The concatenated matrix B is automatically resized afterward to ensure it is a NxN
matrix.
m - the matrix to addadd(DecomposedSymmetricPositiveMatrix, boolean),
resizeB()public DecomposedSymmetricPositiveMatrix add(DecomposedSymmetricPositiveMatrix m, boolean resize)
DecomposedSymmetricPositiveMatrix to this matrix.
Adding another DecomposedSymmetricPositiveMatrix amounts to concatenating their B
matrices horizontally. As a result, the number of column of the matrix B increases with each
addition. Setting resize to true triggers a reduction or an extension of the
matrix B afterward to ensure it is a NxN matrix.
m - the matrix to addresize - if true, the matrix B is resized afterward to ensure it is NxNresizeB()public RealMatrix subtract(RealMatrix m)
m from this matrix.
The returned matrix is, in order of priority:
subtract in interface RealMatrixsubtract in class AbstractRealMatrixm - the matrix to be subtractedthis-mpublic ArrayRowSymmetricMatrix subtract(SymmetricMatrix m)
m from this matrix.subtract in interface SymmetricMatrixm - the matrix to be subtractedthis-mpublic RealMatrix multiply(RealMatrix m, boolean toTranspose, double d)
m or its transpose
mT, then by the scalar d.multiply in interface RealMatrixmultiply in class AbstractRealMatrixm - the matrix by which to multiply this matrix bytoTranspose - whether to compute the product this×m×d (
toTranspose=false), or the product this×m
T×d (toTranspose=true)d - the scalar by which to multiply the resulting matrix bythis×m×d or
this×mT×dpublic RealMatrix multiply(DiagonalMatrix m, double d)
m, then by
the scalar d.multiply in class AbstractRealMatrixm - the diagonal matrix by which to multiply this matrix byd - the scalar by which to multiply the resulting matrix bythis×m×d or
this×mT×dpublic DecomposedSymmetricPositiveMatrix quadraticMultiplication(RealMatrix m)
this×MT,
where M is the provided matrix..quadraticMultiplication in interface SymmetricMatrixquadraticMultiplication in interface SymmetricPositiveMatrixm - the matrix Mthis
×MTpublic DecomposedSymmetricPositiveMatrix quadraticMultiplication(RealMatrix m, boolean isTranspose)
this×MT,
where M or MT is the provided matrix..quadraticMultiplication in interface SymmetricMatrixquadraticMultiplication in interface SymmetricPositiveMatrixm - the matrix M or the matrix MTisTranspose - if true, assumes the provided matrix is MT, otherwise assumes it is
Mthis
×MTpublic DecomposedSymmetricPositiveMatrix power(int p)
p times.
The exponent p must be positive or equal to zero.
This operation is only supported for square matrices.
Depending on the underlying storage, numerical instabilities might occur for high powers.
power in interface RealMatrixpower in interface SymmetricMatrixpower in interface SymmetricPositiveMatrixpower in class AbstractRealMatrixp - the exponent p to which this matrix is to be raisedppublic DecomposedSymmetricPositiveMatrix resizeB()
If the matrix B has more columns than rows, this method replaces the current matrix B by the matrix R resulting from the QR decomposition of BT, after truncating it to its first N rows (where N is the dimension of this matrix). If it has less columns than rows, it simply adds new columns filled with zero.
public RealMatrix getResizedB()
If the matrix B has more columns than rows, this method returns the transpose of the matrix R resulting from the QR decomposition of BT, after truncating it to its first N rows (where N is the dimension of this matrix). If the matrix B has less columns than rows, this methods simply adds columns filled with zero to match its row dimensions.
public RealMatrix getResizedBT()
If the matrix B has more columns than rows, this method returns the matrix R resulting from the QR decomposition of BT, after truncating it to its first N rows (where N is the dimension of this matrix). If the matrix B has less columns than rows, this methods simply adds columns filled with zero to match its row dimensions.
public DecomposedSymmetricPositiveMatrix createMatrix(int rowDimension, int columnDimension)
The returned matrix is filled with zeros. Its size is determined by the specified row and column dimensions, which must both be strictly positive. Additional constraints on the dimensions may apply depending on the implementation (for example, symmetric matrices must be square, which implies that the row and column dimensions must be equal).
createMatrix in interface RealMatrixcreateMatrix in interface SymmetricMatrixcreateMatrix in interface SymmetricPositiveMatrixcreateMatrix in class AbstractRealMatrixrowDimension - the number of rows in the new matrixcolumnDimension - the number of columns in the new matrixpublic static DecomposedSymmetricPositiveMatrix createIdentityMatrix(int dim)
dim - the dimension of the identity matrixpublic DecomposedSymmetricPositiveMatrix copy()
copy in interface RealMatrixcopy in interface SymmetricMatrixcopy in interface SymmetricPositiveMatrixcopy in class AbstractRealMatrixpublic DecomposedSymmetricPositiveMatrix transpose()
transpose in interface RealMatrixtranspose in interface SymmetricMatrixtranspose in interface SymmetricPositiveMatrixtranspose in class AbstractRealMatrixpublic DecomposedSymmetricPositiveMatrix transpose(boolean forceCopy)
If forceCopy is true, the returned matrix is guaranteed to be a new instance,
which can be modified without any risk of impacting the current instance. Otherwise, this
method may simply return the current instance when the matrix is its own transpose (symmetric
matrix).
transpose in interface RealMatrixtranspose in interface SymmetricMatrixtranspose in interface SymmetricPositiveMatrixtranspose in class AbstractRealMatrixforceCopy - if true, the transpose of the matrix is systematically stored in a new matrix;
otherwise the method may return the current instance when the matrix is its own
transposepublic RealMatrix concatenateHorizontally(RealMatrix m, boolean rightConcatenation)
m, , placing it in the left
or right part of the concatenated matrix.
The way the two matrices are concatenated depends on the provided argument:
The matrix m is placed in the right part of the concatenated matrix if
rightConcatenation is set to true, and in its left part if it is set to
false.
Usage examples:
this.concatenateHorizontally(m, true) => [this, m] this.concatenateHorizontally(m, false) => [m, this]
concatenateHorizontally in interface RealMatrixconcatenateHorizontally in class AbstractRealMatrixm - the matrix to be concatenated with this matrixrightConcatenation - whether the matrix m is to be placed in the right (true) or left (
false) part of the concatenated matrixpublic RealMatrix concatenateVertically(RealMatrix m, boolean lowerConcatenation)
m, placing it in the lower or
upper part of the concatenated matrix.
The way the two matrices are concatenated depends on the provided argument:
The matrix m is placed in the lower part of the concatenated matrix if
lowerConcatenation is set to true, and in its upper part if it is set to
false.
Usage examples:
this.concatenateVertically(m, true) => [this]
[ m]
this.concatenateVertically(m, false) => [ m]
[this]
concatenateVertically in interface RealMatrixconcatenateVertically in class AbstractRealMatrixm - the matrix to be concatenated with this matrixlowerConcatenation - whether the matrix m is to be placed in the lower (true) or upper (
false) part of the concatenated matrixpublic RealMatrix concatenateDiagonally(RealMatrix m, boolean rightConcatenation, boolean lowerConcatenation)
m.
The way the two matrices are concatenated depends on the provided arguments:
The matrix m is placed in the right part of the concatenated matrix if
rightConcatenation is set to true, and in its left part if it is set to
false. Similarly, the matrix m is placed in the lower part of the
concatenated matrix if lowerConcatenation is set to true, and in its upper
part if it is set to false. This matrix is then placed in the opposite part of the
concatenated matrix (as an example, if the provided matrix is placed in the upper left part,
this matrix will be placed in the lower right part, the remaining parts being filled with
zeros).
Usage examples:
// Diagonal concatenation
this.concatenateDiagonally(m, true, true) => [this, 0]
[ 0, m]
this.concatenateDiagonally(m, false, false) => [m, 0]
[0, this]
// Anti-diagonal concatenation
this.concatenateDiagonally(m, false, true) => [0, this]
[m, 0]
this.concatenateDiagonally(m, true, false) => [ 0, m]
[this, 0]
concatenateDiagonally in interface RealMatrixconcatenateDiagonally in class AbstractRealMatrixm - the matrix to be concatenated with this matrixrightConcatenation - whether the matrix m is to be placed in the right (true) or left (
false) part of the concatenated matrixlowerConcatenation - whether the matrix m is to be placed in the lower (true) or upper (
false) part of the concatenated matrixpublic DecomposedSymmetricPositiveMatrix getInverse()
The inverse matrix is calculated using the default decomposition as follows:
If A1 = B1 × B1T and
A2 = B2 × B2T
= A1-1, then we have
B2T = B1-1.
getInverse in interface RealMatrixgetInverse in interface SymmetricMatrixgetInverse in interface SymmetricPositiveMatrixgetInverse in class AbstractRealMatrixRealMatrix.getDefaultDecomposition(),
RealMatrix.setDefaultDecomposition(Function)public DecomposedSymmetricPositiveMatrix getInverse(Function<RealMatrix,Decomposition> decompositionBuilder)
The inverse of B1 is computed using the provided decomposition as follows:
If A1 = B1 × B1T and
A2 = B2 × B2T
= A1-1, then we have
B2T = B1-1.
getInverse in interface RealMatrixgetInverse in interface SymmetricMatrixgetInverse in interface SymmetricPositiveMatrixgetInverse in class AbstractRealMatrixdecompositionBuilder - the decomposition algorithm to usepublic boolean isSquare()
isSquare in interface AnyMatrixisSquare in class AbstractRealMatrixpublic boolean isSymmetric()
This method indicates if the matrix is symmetric.
To do so, the method checks that symmetric off-diagonal elements are numerically equal. Two
elements are considered to have different values if their absolute and relative differences
are both above the default tolerances.
This method systematically returns false for non-square matrices.
The absolute and relative tolerances both default to Precision.DOUBLE_COMPARISON_EPSILON.
isSymmetric in interface RealMatrixisSymmetric in class AbstractRealMatrixtrue if this is a symmetric matrix, false otherwisepublic boolean isSymmetric(double relativeTolerance)
This method indicates if the matrix is symmetric.
To do so, the method checks that symmetric off-diagonal elements are numerically equal. Two
elements are considered to have different values if their relative difference is above the
specified tolerance.
This method systematically returns false for non-square matrices.
isSymmetric in interface RealMatrixisSymmetric in class AbstractRealMatrixrelativeTolerance - the relative tolerance to take into account when comparing off-diagonal elementstrue if this is a symmetric matrix, false otherwisepublic boolean isSymmetric(double relativeTolerance,
double absoluteTolerance)
This method indicates if the matrix is symmetric.
To do so, the method checks that symmetric off-diagonal elements are numerically equal. Two
elements are considered to have different values if their absolute and relative differences
are both above the specified tolerances.
This method systematically returns false for non-square matrices.
isSymmetric in interface RealMatrixisSymmetric in class AbstractRealMatrixrelativeTolerance - the relative tolerance to take into account when comparing off-diagonal elementsabsoluteTolerance - the absolute tolerance to take into account when comparing off-diagonal elementstrue if this is a symmetric matrix, false otherwisepublic double walkInRowOrder(RealMatrixChangingVisitor visitor)
Row order starts at upper left element, iterating through all elements of a row from left to right before going to the leftmost element of the next row.
Important:
This method systematically throws a MathUnsupportedOperationException since this
operation is not safe when dealing with symmetric positive definite matrices (the properties
of the matrix are not guaranteed to be preserved).
walkInRowOrder in interface RealMatrixwalkInRowOrder in class AbstractRealMatrixvisitor - the visitor used to process all matrix entriesRealMatrixChangingVisitor.end() at the end of the walkMathUnsupportedOperationException - systematically (this operation is forbidden)RealMatrix.walkInRowOrder(RealMatrixPreservingVisitor),
RealMatrix.walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int),
RealMatrix.walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int),
RealMatrix.walkInColumnOrder(RealMatrixChangingVisitor),
RealMatrix.walkInColumnOrder(RealMatrixPreservingVisitor),
RealMatrix.walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int),
RealMatrix.walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int),
RealMatrix.walkInOptimizedOrder(RealMatrixChangingVisitor),
RealMatrix.walkInOptimizedOrder(RealMatrixPreservingVisitor),
RealMatrix.walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int),
RealMatrix.walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)public double walkInRowOrder(RealMatrixChangingVisitor visitor, int startRow, int endRow, int startColumn, int endColumn)
Row order starts at upper left element, iterating through all elements of a row from left to right before going to the leftmost element of the next row.
Important:
This method systematically throws a MathUnsupportedOperationException since this
operation is not safe when dealing with symmetric positive definite matrices (the properties
of the matrix are not guaranteed to be preserved).
walkInRowOrder in interface RealMatrixwalkInRowOrder in class AbstractRealMatrixvisitor - the visitor used to process all matrix entriesstartRow - the initial row indexendRow - the final row index (inclusive)startColumn - the initial column indexendColumn - the final column indexRealMatrixChangingVisitor.end() at the end of the walkMathUnsupportedOperationException - systematically (this operation is forbidden)RealMatrix.walkInRowOrder(RealMatrixChangingVisitor),
RealMatrix.walkInRowOrder(RealMatrixPreservingVisitor),
RealMatrix.walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int),
RealMatrix.walkInColumnOrder(RealMatrixChangingVisitor),
RealMatrix.walkInColumnOrder(RealMatrixPreservingVisitor),
RealMatrix.walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int),
RealMatrix.walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int),
RealMatrix.walkInOptimizedOrder(RealMatrixChangingVisitor),
RealMatrix.walkInOptimizedOrder(RealMatrixPreservingVisitor),
RealMatrix.walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int),
RealMatrix.walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)public double walkInColumnOrder(RealMatrixChangingVisitor visitor)
Column order starts at upper left element, iterating through all elements of a column from top to bottom before going to the topmost element of the next column.
Important:
This method systematically throws a MathUnsupportedOperationException since this
operation is not safe when dealing with symmetric positive definite matrices (the properties
of the matrix are not guaranteed to be preserved).
walkInColumnOrder in interface RealMatrixwalkInColumnOrder in class AbstractRealMatrixvisitor - the visitor used to process all matrix entriesRealMatrixChangingVisitor.end() at the end of the walkMathUnsupportedOperationException - systematically (this operation is forbidden)RealMatrix.walkInRowOrder(RealMatrixChangingVisitor),
RealMatrix.walkInRowOrder(RealMatrixPreservingVisitor),
RealMatrix.walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int),
RealMatrix.walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int),
RealMatrix.walkInColumnOrder(RealMatrixPreservingVisitor),
RealMatrix.walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int),
RealMatrix.walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int),
RealMatrix.walkInOptimizedOrder(RealMatrixChangingVisitor),
RealMatrix.walkInOptimizedOrder(RealMatrixPreservingVisitor),
RealMatrix.walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int),
RealMatrix.walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)public double walkInColumnOrder(RealMatrixChangingVisitor visitor, int startRow, int endRow, int startColumn, int endColumn)
Column order starts at upper left element, iterating through all elements of a column from top to bottom before going to the topmost element of the next column.
Important:
This method systematically throws a MathUnsupportedOperationException since this
operation is not safe when dealing with symmetric positive definite matrices (the properties
of the matrix are not guaranteed to be preserved).
walkInColumnOrder in interface RealMatrixwalkInColumnOrder in class AbstractRealMatrixvisitor - the visitor used to process all matrix entriesstartRow - the initial row indexendRow - the final row index (inclusive)startColumn - the initial column indexendColumn - the final column indexRealMatrixChangingVisitor.end() at the end of the walkMathUnsupportedOperationException - systematically (this operation is forbidden)RealMatrix.walkInRowOrder(RealMatrixChangingVisitor),
RealMatrix.walkInRowOrder(RealMatrixPreservingVisitor),
RealMatrix.walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int),
RealMatrix.walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int),
RealMatrix.walkInColumnOrder(RealMatrixChangingVisitor),
RealMatrix.walkInColumnOrder(RealMatrixPreservingVisitor),
RealMatrix.walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int),
RealMatrix.walkInOptimizedOrder(RealMatrixChangingVisitor),
RealMatrix.walkInOptimizedOrder(RealMatrixPreservingVisitor),
RealMatrix.walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int),
RealMatrix.walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)public double walkInOptimizedOrder(RealMatrixChangingVisitor visitor)
The fastest walking order depends on the exact matrix class. It may be different from traditional row or column orders.
Important:
This method systematically throws a MathUnsupportedOperationException since this
operation is not safe when dealing with symmetric positive definite matrices (the properties
of the matrix are not guaranteed to be preserved).
walkInOptimizedOrder in interface RealMatrixwalkInOptimizedOrder in class AbstractRealMatrixvisitor - the visitor used to process all matrix entriesRealMatrixChangingVisitor.end() at the end of the walkMathUnsupportedOperationException - systematically (this operation is forbidden)RealMatrix.walkInRowOrder(RealMatrixChangingVisitor),
RealMatrix.walkInRowOrder(RealMatrixPreservingVisitor),
RealMatrix.walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int),
RealMatrix.walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int),
RealMatrix.walkInColumnOrder(RealMatrixChangingVisitor),
RealMatrix.walkInColumnOrder(RealMatrixPreservingVisitor),
RealMatrix.walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int),
RealMatrix.walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int),
RealMatrix.walkInOptimizedOrder(RealMatrixPreservingVisitor),
RealMatrix.walkInOptimizedOrder(RealMatrixChangingVisitor, int, int, int, int),
RealMatrix.walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)public double walkInOptimizedOrder(RealMatrixChangingVisitor visitor, int startRow, int endRow, int startColumn, int endColumn)
The fastest walking order depends on the exact matrix class. It may be different from traditional row or column orders.
Important:
This method systematically throws a MathUnsupportedOperationException since this
operation is not safe when dealing with symmetric positive definite matrices (the properties
of the matrix are not guaranteed to be preserved).
walkInOptimizedOrder in interface RealMatrixwalkInOptimizedOrder in class AbstractRealMatrixvisitor - the visitor used to process all matrix entriesstartRow - the initial row indexendRow - the final row index (inclusive)startColumn - the initial column indexendColumn - the final column index (inclusive)RealMatrixChangingVisitor.end() at the end of the walkMathUnsupportedOperationException - systematically (this operation is forbidden)RealMatrix.walkInRowOrder(RealMatrixChangingVisitor),
RealMatrix.walkInRowOrder(RealMatrixPreservingVisitor),
RealMatrix.walkInRowOrder(RealMatrixChangingVisitor, int, int, int, int),
RealMatrix.walkInRowOrder(RealMatrixPreservingVisitor, int, int, int, int),
RealMatrix.walkInColumnOrder(RealMatrixChangingVisitor),
RealMatrix.walkInColumnOrder(RealMatrixPreservingVisitor),
RealMatrix.walkInColumnOrder(RealMatrixChangingVisitor, int, int, int, int),
RealMatrix.walkInColumnOrder(RealMatrixPreservingVisitor, int, int, int, int),
RealMatrix.walkInOptimizedOrder(RealMatrixChangingVisitor),
RealMatrix.walkInOptimizedOrder(RealMatrixPreservingVisitor),
RealMatrix.walkInOptimizedOrder(RealMatrixPreservingVisitor, int, int, int, int)public static final DecomposedSymmetricPositiveMatrix castOrTransform(SymmetricPositiveMatrix matrix)
DecomposedSymmetricPositiveMatrix.
The transformation is performed thanks to a CholeskyDecomposition. In this case, the input matrix must be
positive definite otherwise an exception is thrown).
matrix - The symmetric positive matrix to cast or transformNonPositiveDefiniteMatrixException - if a transformation is necessary and the matrix is not positive definiteCopyright © 2024 CNES. All rights reserved.