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.
|
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.
|
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.
|
protected double[] |
getInternalData()
Gets the internal array storing the lower part of the symmetric matrix.
|
ArrayRowSymmetricMatrix |
getInverse()
Get the inverse (or pseudo-inverse) of the decomposed matrix.
|
ArrayRowSymmetricMatrix |
getInverse(Decomposition decomposition)
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.
|
void |
multiplyEntry(int row,
int column,
double factor)
Multiplies (in place) the specified entry of
this matrix by the
specified value. |
ArrayRowSymmetricMatrix |
permutation(int[] index)
Permute the rows/columns of this matrix according to a new specified index order list.
|
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 isTranspose)
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.
|
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, 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, walkInRowOrder
isTransposable, operateTranspose
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
concatenateDiagonally, concatenateHorizontally, concatenateVertically, copySubMatrix, copySubMatrix, equals, getColumn, getColumnVector, getData, getDefaultDecomposition, getFrobeniusNorm, getNorm, getRow, getRowVector, getTrace, isAntisymmetric, isDiagonal, isInvertible, isOrthogonal, isSymmetric, 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, walkInRowOrder
public 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 differentNonSquareMatrixException
- 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 differentNonSquareMatrixException
- 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 AnyMatrix
getRowDimension
in class AbstractRealMatrix
public int getColumnDimension()
getColumnDimension
in interface AnyMatrix
getColumnDimension
in class AbstractRealMatrix
protected double[] getInternalData()
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)
This method automatically modify the symmetric element to ensure the symmetry of the matrix is preserved.
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.public ArrayRowSymmetricMatrix 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 ArrayRowSymmetricMatrix 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 RealMatrix add(RealMatrix m)
this
and m
.add
in interface RealMatrix
add
in class AbstractRealMatrix
m
- matrix to be addedthis + m
public ArrayRowSymmetricMatrix add(SymmetricMatrix m)
SymmetricMatrix
to this matrix.add
in interface SymmetricMatrix
m
- 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 RealMatrix
subtract
in class AbstractRealMatrix
m
- matrix to be subtractedthis - m
public ArrayRowSymmetricMatrix subtract(SymmetricMatrix m)
SymmetricMatrix
from this matrix.subtract
in interface SymmetricMatrix
m
- 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 SymmetricMatrix
m
- the matrix Mpublic ArrayRowSymmetricMatrix quadraticMultiplication(RealMatrix m, boolean isTranspose)
quadraticMultiplication
in interface SymmetricMatrix
m
- the matrix M or the matrix MTisTranspose
- if true, assume the provided matrix is MT, otherwise assumes it is Mpublic ArrayRowSymmetricMatrix 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 RealMatrix getSubMatrix(int startRow, int endRow, int startColumn, int endColumn)
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)
getSubMatrix
in interface RealMatrix
getSubMatrix
in class AbstractRealMatrix
selectedRows
- Array of row indices.selectedColumns
- Array of column indices.public ArrayRowSymmetricMatrix 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 ArrayRowSymmetricMatrix copy()
copy
in interface RealMatrix
copy
in interface SymmetricMatrix
copy
in class AbstractRealMatrix
public ArrayRowSymmetricMatrix transpose()
transpose
in interface RealMatrix
transpose
in interface SymmetricMatrix
transpose
in class AbstractRealMatrix
public 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)getDefaultAbsoluteSymmetryThreshold()
,
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)getDefaultAbsoluteSymmetryThreshold()
,
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 RealMatrix
setSubMatrix
in class AbstractRealMatrix
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 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 RealMatrix
addToEntry
in class AbstractRealMatrix
row
- 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 RealMatrix
multiplyEntry
in class AbstractRealMatrix
row
- 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 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.public ArrayRowSymmetricMatrix getInverse()
setDefaultDecomposition(Decomposition)
method.
Default decomposition is used. Default decomposition is set to LUDecomposition
.getInverse
in interface RealMatrix
getInverse
in interface SymmetricMatrix
getInverse
in class AbstractRealMatrix
public ArrayRowSymmetricMatrix getInverse(Decomposition decomposition)
Warning: If a matrix has already been given to the decomposition, it won't be taken into account, as a
new computation will be run on this
matrix and will erase the old decomposition data.
getInverse
in interface RealMatrix
getInverse
in interface SymmetricMatrix
getInverse
in class AbstractRealMatrix
decomposition
- decomposed matrixpublic ArrayRowSymmetricMatrix 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 class AbstractRealMatrix
p
- raise this
to power p
this^p
Copyright © 2020 CNES. All rights reserved.