public class ArrayRowSymmetricMatrix extends AbstractRealMatrix implements SymmetricMatrix, Serializable
This implementation stores the elements of the lower triangular part of a symmetric matrix. These elements are stored
in a 1D array, row after row. For example, for a 3 by 3 matrix we have:
(1) = s1,1;
(2) = s2,1; (3) = s2,2;
(4) = s3,1; (5) = s3,2; (6) = s3,3;
The elements actually stored depends on the type of symmetry specified at construction: LOWER or UPPER implies the symmetry is enforced by keeping only the lower or upper
triangular part of the matrix, while MEAN enforces the symmetry by computing the mean of
the lower and upper elements. The symmetry the provided matrix is not checked by default, meaning that the symmetry
is enforced regardless of the inputs. However, such a check can be triggered by setting the default absolute and
relative symmetry thresholds to a non-null value or by providing these thresholds at construction.
Important:
Because only half the elements of the matrix are actually stored, setting an off-diagonal element to a new value will
automatically modify the symmetric element. As a result, the symmetry of the matrix will automatically be preserved.
However, note that the method setSubMatrix is not supported and will
systematically throw a MathUnsupportedOperationException.
| Modifier and Type | Class and Description |
|---|---|
static class |
ArrayRowSymmetricMatrix.SymmetryType
Enumerate to fill in a symmetric matrix only by its lower/upper part.
|
| Modifier | Constructor and Description |
|---|---|
|
ArrayRowSymmetricMatrix(ArrayRowSymmetricMatrix.SymmetryType symmetryType,
double[][] dataIn)
Builds a new
ArrayRowSymmetricMatrix from the provided data, using the default
symmetry thresholds. |
|
ArrayRowSymmetricMatrix(ArrayRowSymmetricMatrix.SymmetryType symmetryType,
double[][] dataIn,
Double absoluteSymmetryThreshold,
Double relativeSymmetryThreshold)
Builds a new
ArrayRowSymmetricMatrix from the provided data, using the specified
symmetry thresholds. |
|
ArrayRowSymmetricMatrix(ArrayRowSymmetricMatrix.SymmetryType symmetryType,
RealMatrix matrix)
Builds a new
ArrayRowSymmetricMatrix from the provided matrix, using the default
symmetry thresholds. |
|
ArrayRowSymmetricMatrix(ArrayRowSymmetricMatrix.SymmetryType symmetryType,
RealMatrix matrix,
Double absoluteSymmetryThreshold,
Double relativeSymmetryThreshold)
Builds a new
ArrayRowSymmetricMatrix from the provided matrix, using the specified
symmetry thresholds. |
protected |
ArrayRowSymmetricMatrix(double[] dataIn,
boolean copyArray)
Builds a new
ArrayRowSymmetricMatrix by specifying the lower triangular part of the
matrix directly. |
|
ArrayRowSymmetricMatrix(int n)
Builds a new
ArrayRowSymmetricMatrix of dimension n (filled with zero). |
| Modifier and Type | Method and Description |
|---|---|
ArrayRowSymmetricMatrix |
add(DiagonalMatrix m)
Compute the sum of this and
m. |
RealMatrix |
add(RealMatrix m)
Returns the sum of
this and m. |
ArrayRowSymmetricMatrix |
add(SymmetricMatrix m)
Adds a
SymmetricMatrix to this matrix. |
void |
addToEntry(int row,
int column,
double increment)
Adds (in place) the specified value to the specified entry of
this matrix. |
ArrayRowSymmetricMatrix |
copy()
Returns a (deep) copy of this.
|
ArrayRowSymmetricMatrix |
createMatrix(int rowDimension,
int columnDimension)
Create a new RealMatrix of the same type as the instance with the
supplied
row and column dimensions.
|
ArrayRowSymmetricMatrix |
extractSubSymmetricMatrix(int[] index)
Extract a sub-part of the matrix providing a subset of indices.
|
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.
|
protected double[] |
getDataRef()
Gets the internal array storing the lower part of the symmetric matrix.
|
static Double |
getDefaultAbsoluteSymmetryThreshold()
Gets the default absolute threshold above which off-diagonal elements are considered
different.
|
static Double |
getDefaultRelativeSymmetryThreshold()
Gets the default relative threshold above which off-diagonal elements are considered
different.
|
double |
getEntry(int row,
int column)
Get the entry in the specified row and column.
|
ArrayRowSymmetricMatrix |
getInverse()
Get the inverse (or pseudo-inverse) of the decomposed matrix using the default decomposition.
|
ArrayRowSymmetricMatrix |
getInverse(Function<RealMatrix,Decomposition> decompositionBuilder)
Get the inverse (or pseudo-inverse) matrix computed with the given decomposition algorithm.
|
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.
|
boolean |
isSquare()
Is this a square matrix?
|
boolean |
isSymmetric()
Checks if this is a symmetric matrix
|
void |
multiplyEntry(int row,
int column,
double factor)
Multiplies (in place) the specified entry of
this matrix by the
specified value. |
ArrayRowSymmetricMatrix |
power(int p)
Returns the result of multiplying
this with itself p times. |
ArrayRowSymmetricMatrix |
quadraticMultiplication(RealMatrix m)
Gets the result of the quadratic multiplication M×S×MT, where S is
this matrix and M is the provided matrix.
|
ArrayRowSymmetricMatrix |
quadraticMultiplication(RealMatrix m,
boolean toTranspose)
Gets the result of the quadratic multiplication M×S×MT, where S is
this matrix and M or MT is the provided matrix.
|
ArrayRowSymmetricMatrix |
scalarAdd(double d)
Returns the result of adding
d to each entry of this. |
ArrayRowSymmetricMatrix |
scalarMultiply(double d)
Returns the result of multiplying each entry of
this by d. |
static void |
setDefaultAbsoluteSymmetryThreshold(Double threshold)
Sets the default absolute threshold above which off-diagonal elements are considered
different.
|
static void |
setDefaultRelativeSymmetryThreshold(Double threshold)
Sets the default relative threshold above which off-diagonal elements are considered
different.
|
void |
setEntry(int row,
int column,
double value)
Set the entry in the specified row and column.
|
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 SymmetricMatrix. |
void |
setSubMatrix(RealMatrix subMatrix,
int row,
int column)
Method setSubMatrix using a RealMatrix for subMatrix instead of an array
|
ArrayRowSymmetricMatrix |
subtract(DiagonalMatrix m)
Compute this minus
m. |
RealMatrix |
subtract(RealMatrix m)
Returns
this minus m. |
ArrayRowSymmetricMatrix |
subtract(SymmetricMatrix m)
Subtracts a
SymmetricMatrix from this matrix. |
ArrayRowSymmetricMatrix |
transpose()
Returns the transpose of this matrix.
|
ArrayRowSymmetricMatrix |
transpose(boolean forceCopy)
Returns the transpose of this matrix.
|
concatenateDiagonally, concatenateHorizontally, concatenateHorizontally, concatenateVertically, concatenateVertically, copySubMatrix, copySubMatrix, copySubMatrix, copySubMatrix, equals, equals, getColumn, getColumnVector, getData, getData, getDefaultDecomposition, getFrobeniusNorm, getMax, getMin, getNorm, getRow, getRowVector, getTrace, hashCode, isAntisymmetric, isDiagonal, isInvertible, isOrthogonal, isPositiveDefinite, isSymmetric, isSymmetric, multiply, multiply, multiply, multiply, 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, walkInRowOrderisTransposable, operateTransposeclone, finalize, getClass, notify, notifyAll, wait, wait, waitconcatenateDiagonally, concatenateHorizontally, concatenateHorizontally, concatenateVertically, concatenateVertically, copySubMatrix, copySubMatrix, copySubMatrix, copySubMatrix, equals, getColumn, getColumnVector, getData, getData, getDefaultDecomposition, getFrobeniusNorm, getMax, getMin, getNorm, getRow, getRowVector, getTrace, isAntisymmetric, isDiagonal, isInvertible, isOrthogonal, isPositiveDefinite, isSymmetric, isSymmetric, multiply, multiply, multiply, operate, operate, preMultiply, preMultiply, preMultiply, setColumn, setColumnMatrix, setColumnVector, setDefaultDecomposition, setRow, setRowMatrix, setRowVector, toString, walkInColumnOrder, walkInColumnOrder, walkInColumnOrder, walkInColumnOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInRowOrder, walkInRowOrder, walkInRowOrder, walkInRowOrderpublic ArrayRowSymmetricMatrix(int n)
ArrayRowSymmetricMatrix of dimension n (filled with zero).n - the dimension of the matrixpublic ArrayRowSymmetricMatrix(ArrayRowSymmetricMatrix.SymmetryType symmetryType, double[][] dataIn)
ArrayRowSymmetricMatrix from the provided data, using the default
symmetry thresholds.symmetryType - the type of symmetry enforced at constructiondataIn - the data of the matrix (must be a NxN array)NonSquareMatrixException - if the provided matrix is not square (unchecked)NonSymmetricMatrixException - if the provided matrix is not symmetric (unchecked)getDefaultRelativeSymmetryThreshold()public ArrayRowSymmetricMatrix(ArrayRowSymmetricMatrix.SymmetryType symmetryType, double[][] dataIn, Double absoluteSymmetryThreshold, Double relativeSymmetryThreshold)
ArrayRowSymmetricMatrix from the provided data, using the specified
symmetry thresholds.symmetryType - the type of symmetry enforced at constructiondataIn - the data of the matrix (must be a NxN array)absoluteSymmetryThreshold - the absolute threshold above which off-diagonal elements are considered differentrelativeSymmetryThreshold - the relative threshold above which off-diagonal elements are considered differentIllegalArgumentException - if the provided thresholds are strictly negative (unchecked)NonSquareMatrixException - if the provided matrix is not square (unchecked)NonSymmetricMatrixException - if the provided matrix is not symmetric (unchecked)public ArrayRowSymmetricMatrix(ArrayRowSymmetricMatrix.SymmetryType symmetryType, RealMatrix matrix)
ArrayRowSymmetricMatrix from the provided matrix, using the default
symmetry thresholds.symmetryType - the type of symmetry enforced at constructionmatrix - the matrix (must NxN)NonSquareMatrixException - if the provided matrix is not square (unchecked)NonSymmetricMatrixException - if the provided matrix is not symmetric (unchecked)getDefaultRelativeSymmetryThreshold()public ArrayRowSymmetricMatrix(ArrayRowSymmetricMatrix.SymmetryType symmetryType, RealMatrix matrix, Double absoluteSymmetryThreshold, Double relativeSymmetryThreshold)
ArrayRowSymmetricMatrix from the provided matrix, using the specified
symmetry thresholds.symmetryType - the type of symmetry enforced at constructionmatrix - the matrix (must NxN)absoluteSymmetryThreshold - the absolute threshold above which off-diagonal elements are considered differentrelativeSymmetryThreshold - the relative threshold above which off-diagonal elements are considered differentIllegalArgumentException - if the provided thresholds are strictly negative (unchecked)NonSquareMatrixException - if the provided matrix is not square (unchecked)NonSymmetricMatrixException - if the provided matrix is not symmetric (unchecked)protected ArrayRowSymmetricMatrix(double[] dataIn,
boolean copyArray)
ArrayRowSymmetricMatrix by specifying the lower triangular part of the
matrix directly.dataIn - the array storing the lower triangular part of the matrixcopyArray - if true, copy the provided array insteadpublic int getRowDimension()
getRowDimension in interface AnyMatrixgetRowDimension in class AbstractRealMatrixpublic int getColumnDimension()
getColumnDimension in interface AnyMatrixgetColumnDimension in class AbstractRealMatrixprotected double[] getDataRef()
public double getEntry(int row,
int column)
getEntry in interface RealMatrixgetEntry in class AbstractRealMatrixrow - 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)
This method automatically modify the symmetric element to ensure the symmetry of the matrix is preserved.
setEntry in interface RealMatrixsetEntry in class AbstractRealMatrixrow - Row index of entry to be set.column - Column index of entry to be set.value - the new value of the entry.public ArrayRowSymmetricMatrix scalarAdd(double d)
d to each entry of this.scalarAdd in interface RealMatrixscalarAdd in interface SymmetricMatrixscalarAdd in class AbstractRealMatrixd - value to be added to each entryd + thispublic ArrayRowSymmetricMatrix scalarMultiply(double d)
this by d.scalarMultiply in interface RealMatrixscalarMultiply in interface SymmetricMatrixscalarMultiply in class AbstractRealMatrixd - value to multiply all entries byd * thispublic RealMatrix add(RealMatrix m)
this and m.add in interface RealMatrixadd in class AbstractRealMatrixm - matrix to be addedthis + mpublic ArrayRowSymmetricMatrix add(SymmetricMatrix m)
SymmetricMatrix to this matrix.add in interface SymmetricMatrixm - the matrix to addpublic ArrayRowSymmetricMatrix add(DiagonalMatrix m)
m.
DiagonalMatrix method optimization
m - Diagonal matrix to be addedIllegalArgumentException - if m is not the same size as thispublic RealMatrix subtract(RealMatrix m)
this minus m.subtract in interface RealMatrixsubtract in class AbstractRealMatrixm - matrix to be subtractedthis - mpublic ArrayRowSymmetricMatrix subtract(SymmetricMatrix m)
SymmetricMatrix from this matrix.subtract in interface SymmetricMatrixm - the matrix to subtractpublic ArrayRowSymmetricMatrix subtract(DiagonalMatrix m)
m.
DiagonalMatrix method optimization
m - Diagonal matrix to be addedIllegalArgumentException - if m is not the same size as thispublic ArrayRowSymmetricMatrix quadraticMultiplication(RealMatrix m)
quadraticMultiplication in interface SymmetricMatrixm - the matrix Mpublic ArrayRowSymmetricMatrix quadraticMultiplication(RealMatrix m, boolean toTranspose)
quadraticMultiplication in interface SymmetricMatrixm - the matrix M or the matrix MTtoTranspose - if true, assume the provided matrix is MT, otherwise assumes it is Mpublic ArrayRowSymmetricMatrix createMatrix(int rowDimension, int columnDimension)
createMatrix in interface RealMatrixcreateMatrix in class AbstractRealMatrixrowDimension - 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 RealMatrix getSubMatrix(int startRow, int endRow, int startColumn, int endColumn)
getSubMatrix in interface RealMatrixgetSubMatrix in class AbstractRealMatrixstartRow - Initial row indexendRow - Final row index (inclusive)startColumn - Initial column indexendColumn - Final column index (inclusive)public RealMatrix getSubMatrix(int[] selectedRows, int[] selectedColumns)
getSubMatrix in interface RealMatrixgetSubMatrix in class AbstractRealMatrixselectedRows - Array of row indices.selectedColumns - Array of column indices.public ArrayRowSymmetricMatrix extractSubSymmetricMatrix(int[] index)
Usage example (with permutation):
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]
Usage example :
1 2 3 2 3
1 [lambda1, mu, gamma] 2 [lambda2, beta]
2 [ mu, lambda2, beta] --> {2,3} --> 3 [ beta, lambda3]
3 [ gamma, beta, lambda3]
extractSubSymmetricMatrix in interface SymmetricMatrixindex - Index listpublic ArrayRowSymmetricMatrix copy()
copy in interface RealMatrixcopy in interface SymmetricMatrixcopy in class AbstractRealMatrixpublic ArrayRowSymmetricMatrix transpose()
transpose in interface RealMatrixtranspose in interface SymmetricMatrixtranspose in class AbstractRealMatrixpublic ArrayRowSymmetricMatrix transpose(boolean forceCopy)
transpose in interface RealMatrixtranspose in class AbstractRealMatrixforceCopy - true if we want to return a copy of the matrix, false otherwisepublic static Double getDefaultAbsoluteSymmetryThreshold()
A null value means the symmetry is enforced without any check on the absolute difference between symmetric elements.
getDefaultRelativeSymmetryThreshold(),
setDefaultAbsoluteSymmetryThreshold(Double),
setDefaultRelativeSymmetryThreshold(Double)public static void setDefaultAbsoluteSymmetryThreshold(Double threshold)
A null value means the symmetry is enforced without any check on the absolute difference between symmetric elements.
threshold - the new default relative symmetry threshold (≥0 or null)IllegalArgumentException - if provided thresholds are strictly negative or NaNgetDefaultAbsoluteSymmetryThreshold(),
getDefaultRelativeSymmetryThreshold(),
setDefaultRelativeSymmetryThreshold(Double)public static Double getDefaultRelativeSymmetryThreshold()
A null value means the symmetry is enforced without any check on the relative difference between symmetric elements.
getDefaultAbsoluteSymmetryThreshold(),
setDefaultAbsoluteSymmetryThreshold(Double),
setDefaultRelativeSymmetryThreshold(Double)public static void setDefaultRelativeSymmetryThreshold(Double threshold)
A null value means the symmetry is enforced without any check on the relative difference between symmetric elements.
threshold - the new default relative symmetry threshold (≥0 or null)IllegalArgumentException - if provided thresholds are strictly negative or NaNgetDefaultAbsoluteSymmetryThreshold(),
getDefaultRelativeSymmetryThreshold(),
setDefaultAbsoluteSymmetryThreshold(Double)public void setSubMatrix(double[][] subMatrix,
int row,
int column)
MathUnsupportedOperationException as this operation is not safe when
we deal with a SymmetricMatrix.setSubMatrix in interface RealMatrixsetSubMatrix in class AbstractRealMatrixsubMatrix - matrix 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 void setSubMatrix(RealMatrix subMatrix, int row, int column)
subMatrix - matrix 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 void addToEntry(int row,
int column,
double increment)
this matrix. Row and column indices start
at 0.addToEntry in interface RealMatrixaddToEntry in class AbstractRealMatrixrow - Row index of the entry to be modified.column - Column index of the entry to be modified.increment - value to add to the matrix entry.public void multiplyEntry(int row,
int column,
double factor)
this matrix by the
specified value. Row and column indices start at 0.multiplyEntry in interface RealMatrixmultiplyEntry in class AbstractRealMatrixrow - Row index of the entry to be modified.column - Column index of the entry to be modified.factor - Multiplication factor for the matrix entry.public RealMatrix getRowMatrix(int row)
getRowMatrix in interface RealMatrixgetRowMatrix in class AbstractRealMatrixrow - Row to be fetched.public RealMatrix getColumnMatrix(int column)
getColumnMatrix in interface RealMatrixgetColumnMatrix in class AbstractRealMatrixcolumn - Column to be fetched.public ArrayRowSymmetricMatrix getInverse()
setDefaultDecomposition(Function) method.
Default decomposition is used.
Default decomposition builder is set to LUDecomposition.decompositionBuilder(1e-11).getInverse in interface RealMatrixgetInverse in interface SymmetricMatrixgetInverse in class AbstractRealMatrixpublic ArrayRowSymmetricMatrix getInverse(Function<RealMatrix,Decomposition> decompositionBuilder)
getInverse in interface RealMatrixgetInverse in interface SymmetricMatrixgetInverse in class AbstractRealMatrixdecompositionBuilder - function to construct the decomposition available in the Decomposition
classes, for instance QRDecomposition.decompositionBuilder(double)public ArrayRowSymmetricMatrix power(int p)
this with itself p times. Depending on the underlying storage,
instability for high powers
might occur.power in interface RealMatrixpower in interface SymmetricMatrixpower in class AbstractRealMatrixp - raise this to power pthis^ppublic boolean isSquare()
isSquare in interface AnyMatrixisSquare in class AbstractRealMatrixpublic boolean isSymmetric()
Matrix is considered symmetric if no cross-term violates default absolute and relative thresholds (
both Precision.DOUBLE_COMPARISON_EPSILON).
isSymmetric in interface RealMatrixisSymmetric in class AbstractRealMatrixCopyright © 2021 CNES. All rights reserved.