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[][] dataB,
boolean isTranspose)
Builds a new
DecomposedSymmetricPositiveMatrix by specifying the data of a matrix B (triangular inferior)
or BT (triangular superior) which satisfies A = B×BT. |
DecomposedSymmetricPositiveMatrix(int dimension)
Builds a new NxN
SymmetricPositiveMatrix (filled with zero). |
DecomposedSymmetricPositiveMatrix(RealMatrix matrixB,
boolean isTranspose)
Builds a new
SymmetricPositiveMatrix by specifying a matrix B, or a matrix
BT which satisfies A = B×BT. |
Modifier and Type | Method and Description |
---|---|
DecomposedSymmetricPositiveMatrix |
add(DecomposedSymmetricPositiveMatrix m)
Adds another
SymmetricPositiveMatrix to this matrix. |
DecomposedSymmetricPositiveMatrix |
add(DecomposedSymmetricPositiveMatrix m,
boolean resize)
Adds another
SymmetricPositiveMatrix to this matrix. |
RealMatrix |
add(RealMatrix m)
Returns the sum of
this and m . |
SymmetricMatrix |
add(SymmetricMatrix m)
Adds a
SymmetricMatrix to this matrix. |
SymmetricPositiveMatrix |
add(SymmetricPositiveMatrix m)
Adds a
SymmetricPositiveMatrix to this matrix. |
DecomposedSymmetricPositiveMatrix |
copy()
Returns a (deep) copy of this.
|
DecomposedSymmetricPositiveMatrix |
createMatrix(int rowDimension,
int columnDimension)
Create a new RealMatrix of the same type as the instance with the
supplied
row and column dimensions.
|
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.
|
int |
getColumnDimension()
Returns the number of columns of this matrix.
|
RealMatrix |
getColumnMatrix(int column)
Get the entries at the given column index as a column matrix.
|
double |
getEntry(int row,
int column)
Get the entry in the specified row and column.
|
DecomposedSymmetricPositiveMatrix |
getInverse()
Get the inverse of the decomposed matrix given as input.
|
DecomposedSymmetricPositiveMatrix |
getInverse(Decomposition decomposition)
Get the inverse of the decomposed matrix given as input.
|
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 number of rows of this matrix.
|
RealMatrix |
getRowMatrix(int row)
Get the entries at the given row index as a row matrix.
|
RealMatrix |
getSubMatrix(int[] selectedRows,
int[] selectedColumns)
Gets a submatrix.
|
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).
|
RealMatrix |
multiply(RealMatrix m)
Returns the result of postmultiplying
this by m . |
RealMatrix |
multiply(RealMatrix m,
boolean toTranspose)
Returns the result of postmultiplying this × m (if
isTranspose = false )
or this × mT (if isTranspose = true ) |
RealMatrix |
multiply(RealMatrix m,
boolean toTranspose,
double d)
Returns the result of postmultiplying d × this × m (if
toTranspose = false
) or d × this × mT (if toTranspose = true ) |
RealMatrix |
multiply(SymmetricMatrix m,
boolean toTranspose,
double d)
Returns the result of postmultiplying d × this × m (independently from the
toTranspose parameter value as we use diagonal matrix). |
DecomposedSymmetricPositiveMatrix |
permutation(int[] index)
Permute the rows/columns of this matrix according to a new specified index order list.
|
DecomposedSymmetricPositiveMatrix |
positiveScalarAdd(double d)
Adds a positive scalar to each entry of this matrix.
|
DecomposedSymmetricPositiveMatrix |
positiveScalarMultiply(double d)
Multiplies each entry of this matrix by a positive scalar.
|
DecomposedSymmetricPositiveMatrix |
power(int p)
Returns the result of multiplying
this with itself p times. |
DecomposedSymmetricPositiveMatrix |
quadraticMultiplication(RealMatrix m)
Gets the result of the quadratic multiplication M×S×MT, where S is
this matrix and M is the provided matrix.
|
DecomposedSymmetricPositiveMatrix |
quadraticMultiplication(RealMatrix m,
boolean isTranspose)
Gets the result of the quadratic multiplication M×S×MT, where S is
this matrix and 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
d to each entry of this . |
SymmetricMatrix |
scalarMultiply(double d)
Returns the result of multiplying each entry of
this by d . |
void |
setEntry(int row,
int column,
double value)
The method systematically throws a
MathUnsupportedOperationException as this operation is not safe when
we deal with a SymmetricPositiveMatrix . |
void |
setSubMatrix(double[][] subMatrix,
int row,
int column)
The method systematically throws a
MathUnsupportedOperationException as this operation is not safe when
we deal with a SymmetricPositiveMatrix . |
RealMatrix |
subtract(RealMatrix m)
Returns
this minus m . |
SymmetricMatrix |
subtract(SymmetricMatrix m)
Subtracts a
SymmetricMatrix from this matrix. |
SymmetricMatrix |
toSymmetricMatrix()
Gets the matrix A resulting of the decomposition A = B×BT of this matrix.
|
DecomposedSymmetricPositiveMatrix |
transpose()
Returns the transpose of this matrix.
|
addToEntry, concatenateDiagonally, concatenateHorizontally, concatenateVertically, copySubMatrix, copySubMatrix, equals, equals, getColumn, getColumnVector, getData, getDefaultDecomposition, getFrobeniusNorm, getNorm, getRow, getRowVector, getTrace, hashCode, isAntisymmetric, isDiagonal, isInvertible, isOrthogonal, isSquare, isSymmetric, isSymmetric, isSymmetric, multiply, multiplyEntry, operate, operate, preMultiply, preMultiply, preMultiply, setColumn, setColumnMatrix, setColumnVector, setDefaultDecomposition, setRow, setRowMatrix, setRowVector, toString, toString, walkInColumnOrder, walkInColumnOrder, walkInColumnOrder, walkInColumnOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInRowOrder, walkInRowOrder, walkInRowOrder, walkInRowOrder
isTransposable, operateTranspose
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
addToEntry, concatenateDiagonally, concatenateHorizontally, concatenateVertically, copySubMatrix, copySubMatrix, equals, getColumn, getColumnVector, getData, getDefaultDecomposition, getFrobeniusNorm, getNorm, getRow, getRowVector, getTrace, isAntisymmetric, isDiagonal, isInvertible, isOrthogonal, isSymmetric, isSymmetric, isSymmetric, multiplyEntry, operate, operate, preMultiply, preMultiply, preMultiply, setColumn, setColumnMatrix, setColumnVector, setDefaultDecomposition, setRow, setRowMatrix, setRowVector, toString, walkInColumnOrder, walkInColumnOrder, walkInColumnOrder, walkInColumnOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInRowOrder, walkInRowOrder, walkInRowOrder, walkInRowOrder
public DecomposedSymmetricPositiveMatrix(int dimension)
SymmetricPositiveMatrix
(filled with zero).dimension
- the dimension N of the matrixpublic DecomposedSymmetricPositiveMatrix(double[][] dataB, boolean isTranspose)
DecomposedSymmetricPositiveMatrix
by specifying the data of a matrix B (triangular inferior)
or BT (triangular superior) which satisfies A = B×BT.dataB
- the data of the matrix B or BTisTranspose
- if true, assumes the provided matrix is BT, otherwise assumes it is Bpublic DecomposedSymmetricPositiveMatrix(RealMatrix matrixB, boolean isTranspose)
SymmetricPositiveMatrix
by specifying a matrix B, or a matrix
BT which satisfies A = B×BT.matrixB
- the matrix B or BTisTranspose
- if true, assumes the provided matrix is BT, otherwise assumes it is Bpublic RealMatrix getB()
public RealMatrix getBT()
public int getRowDimension()
getRowDimension
in interface AnyMatrix
getRowDimension
in class AbstractRealMatrix
public int getColumnDimension()
getColumnDimension
in interface AnyMatrix
getColumnDimension
in class AbstractRealMatrix
public int getTransparentDimension()
public SymmetricMatrix toSymmetricMatrix()
public double getEntry(int row, int column)
getEntry
in interface RealMatrix
getEntry
in class AbstractRealMatrix
row
- Row index of entry to be fetched.column
- Column index of entry to be fetched.(row, column)
.public void setEntry(int row, int column, double value)
MathUnsupportedOperationException
as this operation is not safe when
we deal with a SymmetricPositiveMatrix
.setEntry
in interface RealMatrix
setEntry
in class AbstractRealMatrix
row
- Row index of entry to be set.column
- Column index of entry to be set.value
- the new value of the entry.MathUnsupportedOperationException
- systematically, since this operation is not supportedpublic void setSubMatrix(double[][] subMatrix, int row, int column)
MathUnsupportedOperationException
as this operation is not safe when
we deal with a SymmetricPositiveMatrix
.setSubMatrix
in interface RealMatrix
setSubMatrix
in class AbstractRealMatrix
subMatrix
- array containing the submatrix replacement datarow
- row coordinate of the top, left element to be replacedcolumn
- column coordinate of the top, left element to be replacedMathUnsupportedOperationException
- systematically, since this operation is not supportedpublic RealMatrix add(RealMatrix m)
this
and m
.add
in interface RealMatrix
add
in class AbstractRealMatrix
m
- matrix to be addedthis + m
public SymmetricMatrix add(SymmetricMatrix m)
SymmetricMatrix
to this matrix.add
in interface SymmetricMatrix
m
- the matrix to addpublic SymmetricPositiveMatrix add(SymmetricPositiveMatrix m)
SymmetricPositiveMatrix
to this matrix.add
in interface SymmetricPositiveMatrix
m
- the matrix to addpublic DecomposedSymmetricPositiveMatrix add(DecomposedSymmetricPositiveMatrix m)
SymmetricPositiveMatrix
to this matrix.
Adding another SymmetricPositiveMatrix
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)
SymmetricPositiveMatrix
to this matrix.
Adding another SymmetricPositiveMatrix
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 SymmetricMatrix scalarAdd(double d)
d
to each entry of this
.scalarAdd
in interface RealMatrix
scalarAdd
in interface SymmetricMatrix
scalarAdd
in class AbstractRealMatrix
d
- value to be added to each entryd + this
public DecomposedSymmetricPositiveMatrix positiveScalarAdd(double d)
The scalar addition is computed by doing a vertical concatenation between the matrix B^T and a row matrix composed by the square root of the scalar.
positiveScalarAdd
in interface SymmetricPositiveMatrix
d
- the scalar to add to each entrypublic RealMatrix subtract(RealMatrix m)
this
minus m
.subtract
in interface RealMatrix
subtract
in class AbstractRealMatrix
m
- matrix to be subtractedthis - m
public SymmetricMatrix subtract(SymmetricMatrix m)
SymmetricMatrix
from this matrix.subtract
in interface SymmetricMatrix
m
- the matrix to subtractpublic RealMatrix multiply(RealMatrix m)
this
by m
.multiply
in interface RealMatrix
multiply
in class AbstractRealMatrix
m
- matrix to postmultiply bythis * m
public RealMatrix multiply(RealMatrix m, boolean toTranspose)
isTranspose = false
)
or this × mT (if isTranspose = true
)multiply
in interface RealMatrix
multiply
in class AbstractRealMatrix
m
- matrix to postmultiply bytoTranspose
- if true, assumes the provided matrix is MT, otherwise assumes it is Mpublic RealMatrix multiply(RealMatrix m, boolean toTranspose, double d)
toTranspose = false
) or d × this × mT (if toTranspose = true
)multiply
in interface RealMatrix
multiply
in class AbstractRealMatrix
m
- matrix to postmultiply bytoTranspose
- indication value, true if we expect the m
matrix to be transposedd
- value to multiply all entries bypublic RealMatrix multiply(SymmetricMatrix m, boolean toTranspose, double d)
toTranspose
parameter value as we use diagonal matrix).
Optimized method for symmetric matrix.m
- matrix to postmultiply bytoTranspose
- no used value for diagonal matrixd
- value to multiply all entries byDimensionMismatchException
- if matrices are not multiplication compatiblepublic SymmetricMatrix scalarMultiply(double d)
this
by d
.scalarMultiply
in interface RealMatrix
scalarMultiply
in interface SymmetricMatrix
scalarMultiply
in class AbstractRealMatrix
d
- value to multiply all entries byd * this
public DecomposedSymmetricPositiveMatrix positiveScalarMultiply(double d)
positiveScalarMultiply
in interface SymmetricPositiveMatrix
d
- the scalar by which each entry is multipliedNotPositiveException
- if the d is negative (unchecked)public DecomposedSymmetricPositiveMatrix quadraticMultiplication(RealMatrix m)
quadraticMultiplication
in interface SymmetricMatrix
quadraticMultiplication
in interface SymmetricPositiveMatrix
m
- the matrix Mpublic DecomposedSymmetricPositiveMatrix quadraticMultiplication(RealMatrix m, boolean isTranspose)
quadraticMultiplication
in interface SymmetricMatrix
quadraticMultiplication
in interface SymmetricPositiveMatrix
m
- the matrix M or the matrix MTisTranspose
- if true, assume the matrix provided is MT, otherwise assume it is Mpublic DecomposedSymmetricPositiveMatrix power(int p)
this
with itself p
times. Depending on the underlying storage,
instability for high powers
might occur.power
in interface RealMatrix
power
in interface SymmetricMatrix
power
in interface SymmetricPositiveMatrix
power
in class AbstractRealMatrix
p
- raise this
to power p
this^p
NotPositiveException
- if p is negativepublic 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)
createMatrix
in interface RealMatrix
createMatrix
in class AbstractRealMatrix
rowDimension
- the number of rows in the new matrixcolumnDimension
- the number of columns in the new matrixDimensionMismatchException
- if the row and column dimensions are not the same (unchecked)public DecomposedSymmetricPositiveMatrix copy()
copy
in interface RealMatrix
copy
in interface SymmetricMatrix
copy
in interface SymmetricPositiveMatrix
copy
in class AbstractRealMatrix
public DecomposedSymmetricPositiveMatrix transpose()
transpose
in interface RealMatrix
transpose
in interface SymmetricMatrix
transpose
in interface SymmetricPositiveMatrix
transpose
in class AbstractRealMatrix
public DecomposedSymmetricPositiveMatrix permutation(int[] index)
The index list must be the same dimension as the matrix and each index must be represented.
Usage example : 1 2 3 2 3 1 1 [lambda1, mu, gamma] 2 [lambda2, beta, mu] 2 [ mu, lambda2, beta] --> {2,3,1} --> 3 [ beta, lambda3, gamma] 3 [ gamma, beta, lambda3] 1 [ mu, gamma, lambda1]
permutation
in interface SymmetricMatrix
index
- Index list of the expected permutationpublic DecomposedSymmetricPositiveMatrix getInverse()
The default decomposition is used.
The inverseDecomposedSymmetricPositiveMatrix
matrix is calculated like :
If A1 = B1 × B1T and
A2 = B2 × B2T
= A1-1, then we have
B2T = B1-1.
getInverse
in interface RealMatrix
getInverse
in interface SymmetricMatrix
getInverse
in interface SymmetricPositiveMatrix
getInverse
in class AbstractRealMatrix
SingularMatrixException
- if the decomposed matrix is singular.public DecomposedSymmetricPositiveMatrix getInverse(Decomposition decomposition)
Warning: The decomposition should be instantiated without providing any matrix (avoids useless operations).
The inverse DecomposedSymmetricPositiveMatrix
matrix is calculated like : If
A1 = B1 × B1T and
A2 = B2 × B2T
= A1-1, then we have B2T = B1-1.
The inverse of B1 is computed using the provided decomposition.
getInverse
in interface RealMatrix
getInverse
in interface SymmetricMatrix
getInverse
in interface SymmetricPositiveMatrix
getInverse
in class AbstractRealMatrix
decomposition
- The decomposition algorithmSingularMatrixException
- if the decomposed matrix is singular.public RealMatrix getSubMatrix(int startRow, int endRow, int startColumn, int endColumn)
Note that the returned matrix is a regular matrix.
getSubMatrix
in interface RealMatrix
getSubMatrix
in class AbstractRealMatrix
startRow
- Initial row indexendRow
- Final row index (inclusive)startColumn
- Initial column indexendColumn
- Final column index (inclusive)public RealMatrix getSubMatrix(int[] selectedRows, int[] selectedColumns)
Note that if the returned matrix is a regular matrix.
getSubMatrix
in interface RealMatrix
getSubMatrix
in class AbstractRealMatrix
selectedRows
- Array of row indices.selectedColumns
- Array of column indices.public RealMatrix getRowMatrix(int row)
getRowMatrix
in interface RealMatrix
getRowMatrix
in class AbstractRealMatrix
row
- Row to be fetched.public RealMatrix getColumnMatrix(int column)
getColumnMatrix
in interface RealMatrix
getColumnMatrix
in class AbstractRealMatrix
column
- Column to be fetched.Copyright © 2020 CNES. All rights reserved.