public class ArrayRowSymmetricMatrix extends AbstractRealMatrix implements SymmetricMatrix
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 of 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 or relative symmetry threshold to a non-null value, or by specifying any of 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)
Returns the result of adding the diagonal matrix
m to this matrix. |
RealMatrix |
add(RealMatrix m)
Returns the result of adding the matrix
m to this matrix. |
ArrayRowSymmetricMatrix |
add(SymmetricMatrix m)
Returns the result of adding the symmetric 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.
|
protected static void |
checkAbsoluteThreshold(Double threshold)
Ensures the provided absolute threshold is either
null or a positive number (zero
included). |
protected static void |
checkDataArray(double[] data)
Checks the validity of the provided data array.
|
protected static void |
checkMatrix(RealMatrix matrix)
Ensures the provided matrix is not
null and is a square matrix. |
protected static void |
checkRelativeThreshold(Double threshold)
Ensures the provided relative threshold is either
null or a positive number (zero
included). |
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. |
ArrayRowSymmetricMatrix |
copy()
Returns a deep copy of this matrix.
|
static ArrayRowSymmetricMatrix |
createIdentityMatrix(int dim)
Creates an identity matrix of the specified dimension.
|
ArrayRowSymmetricMatrix |
createMatrix(int rowDimension,
int columnDimension)
Creates a new matrix of the same type as this matrix.
|
boolean |
equals(Object object)
Returns
true if the provided object is a RealMatrix instance with the
same dimensions as this matrix, whose entries are strictly equal to the entries of this
matrix (no absolute or relative tolerance is taken into account when comparing the entries). |
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.
|
protected double[] |
getDataRef()
Gets a reference to the internal data 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)
Gets the entry at the specified row and column.
|
ArrayRowSymmetricMatrix |
getInverse()
Gets the inverse (or pseudo-inverse) of this matrix using the default decomposition.
|
ArrayRowSymmetricMatrix |
getInverse(Function<RealMatrix,Decomposition> decompositionBuilder)
Gets the inverse (or pseudo-inverse) of this matrix using the given decomposition algorithm.
|
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.
|
ArrayRowSymmetricMatrix |
getSubMatrix(int[] indices)
Extracts the submatrix corresponding to the specified indices.
|
RealMatrix |
getSubMatrix(int[] selectedRows,
int[] selectedColumns)
Gets a submatrix.
|
ArrayRowSymmetricMatrix |
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 |
hashCode()
Computes a hash code for the matrix.
|
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
m T, 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. |
ArrayRowSymmetricMatrix |
power(int p)
Returns the the result of multiplying this matrix with itself
p times. |
ArrayRowSymmetricMatrix |
quadraticMultiplication(RealMatrix m)
Returns the result of the quadratic multiplication M×
this ×MT,
where M is the provided matrix. |
ArrayRowSymmetricMatrix |
quadraticMultiplication(RealMatrix m,
boolean isTranspose)
Returns the result of the quadratic multiplication M×
this ×MT,
where M or MT is the provided matrix. |
ArrayRowSymmetricMatrix |
scalarAdd(double d)
Returns the result of adding a scalar
d to the entries of this matrix. |
ArrayRowSymmetricMatrix |
scalarMultiply(double d)
Returns the result of multiplying the entries of this matrix by the scalar
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)
Sets the entry at the specified row and column to a new value.
|
void |
setSubMatrix(double[][] subMatrix,
int row,
int column)
Replaces part of the matrix with a given submatrix, starting at the specified row and column.
|
ArrayRowSymmetricMatrix |
subtract(DiagonalMatrix m)
Returns the result of subtracting the diagonal matrix
m from this matrix. |
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 |
transpose()
Returns the transpose of this matrix.
|
ArrayRowSymmetricMatrix |
transpose(boolean forceCopy)
Returns the transpose of this matrix.
|
checkDestinationArray, checkSquare, concatenateDiagonally, concatenateDiagonally, concatenateHorizontally, concatenateVertically, copySubMatrix, copySubMatrix, copySubMatrix, copySubMatrix, equals, getColumn, getColumnVector, getData, getData, getDefaultDecomposition, getDiagonal, getFrobeniusNorm, getMax, getMin, getNorm, getRow, getRowVector, getTrace, isAntisymmetric, isDiagonal, isInvertible, isOrthogonal, 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
getDiagonal
concatenateDiagonally, concatenateDiagonally, concatenateHorizontally, concatenateVertically, copySubMatrix, copySubMatrix, copySubMatrix, copySubMatrix, equals, getColumn, getColumnVector, getData, getData, getDefaultDecomposition, getFrobeniusNorm, getMax, getMin, getNorm, getRow, getRowVector, getTrace, isAntisymmetric, isDiagonal, isInvertible, isOrthogonal, 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)
n
- the dimension of the matrixpublic ArrayRowSymmetricMatrix(ArrayRowSymmetricMatrix.SymmetryType symmetryType, double[][] dataIn)
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)
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 one of the provided thresholds is NaN
or is 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)
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)
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 one of the provided thresholds is NaN
or is 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)
dataIn
- the array storing the lower triangular part of the matrixcopyArray
- if true, copy the provided array insteadprotected static void checkMatrix(RealMatrix matrix)
null
and is a square matrix.matrix
- the matrix to be checkedNullArgumentException
- if the provided matrix is null
NonSquareMatrixException
- if the provided matrix is not squareprotected static void checkDataArray(double[] data)
To be valid, the array must not be null
or empty.
data
- the data array to be checkedNullArgumentException
- if the data array is null
NoDataException
- if the data array is emptyprotected static void checkAbsoluteThreshold(Double threshold)
null
or a positive number (zero
included).threshold
- the absolute threshold to checkIllegalArgumentException
- if the provided threshold is NaN
or is strictly negativeprotected static void checkRelativeThreshold(Double threshold)
null
or a positive number (zero
included).threshold
- the relative threshold to checkIllegalArgumentException
- if the provided threshold is NaN
or is strictly negativeprotected double[] getDataRef()
This method is only provided for optimization purposes.
Any modification made on the returned array will change the values of this matrix.
public int getRowDimension()
getRowDimension
in interface AnyMatrix
getRowDimension
in class AbstractRealMatrix
public int getColumnDimension()
getColumnDimension
in interface AnyMatrix
getColumnDimension
in class AbstractRealMatrix
public double getEntry(int row, int column)
Row and column indices start at 0.
getEntry
in interface RealMatrix
getEntry
in class AbstractRealMatrix
row
- the row index of entry to be fetchedcolumn
- the column index of entry to be fetchedpublic void setEntry(int row, int column, double value)
Row and column indices start at 0.
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
- the row index of entry to be setcolumn
- the column index of entry to be setvalue
- the new value of the entrypublic void addToEntry(int row, int column, double increment)
Row and column indices start at 0.
addToEntry
in interface RealMatrix
addToEntry
in class AbstractRealMatrix
row
- 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 entrypublic void multiplyEntry(int row, int column, double factor)
this
matrix by a given value.
Row and column indices start at 0.
multiplyEntry
in interface RealMatrix
multiplyEntry
in class AbstractRealMatrix
row
- 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 getRowMatrix(int row)
Row indices start at 0.
getRowMatrix
in interface RealMatrix
getRowMatrix
in class AbstractRealMatrix
row
- the index of the row to be fetchedpublic RealMatrix getColumnMatrix(int column)
Column indices start at 0.
getColumnMatrix
in interface RealMatrix
getColumnMatrix
in class AbstractRealMatrix
column
- the index of the column to be fetchedpublic 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 ArrayRowSymmetricMatrix if the selected indices are the same for the rows and the columns, and an Array2DRowRealMatrix or a BlockRealMatrix otherwise.
getSubMatrix
in interface RealMatrix
getSubMatrix
in class AbstractRealMatrix
startRow
- 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 an ArrayRowSymmetricMatrix 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 RealMatrix
getSubMatrix
in class AbstractRealMatrix
selectedRows
- the selected row indicesselectedColumns
- the selected column indicespublic ArrayRowSymmetricMatrix 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 SymmetricMatrix
startIndex
- the initial row/column indexendIndex
- the final row/column index (inclusive)public ArrayRowSymmetricMatrix 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 SymmetricMatrix
indices
- the selected indicespublic void setSubMatrix(double[][] subMatrix, int row, int column)
setSubMatrix
in interface RealMatrix
setSubMatrix
in class AbstractRealMatrix
subMatrix
- the array containing the submatrix replacement datarow
- 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 ArrayRowSymmetricMatrix scalarAdd(double d)
d
to the entries of this matrix.scalarAdd
in interface RealMatrix
scalarAdd
in interface SymmetricMatrix
scalarAdd
in class AbstractRealMatrix
d
- the scalar value to be added to the entries of this matrixthis
+d
public ArrayRowSymmetricMatrix scalarMultiply(double d)
d
.scalarMultiply
in interface RealMatrix
scalarMultiply
in interface SymmetricMatrix
scalarMultiply
in class AbstractRealMatrix
d
- the scalar value by which to multiply the entries of this matrix bythis
×d
public RealMatrix add(RealMatrix m)
m
to this matrix.
The returned matrix is, in order of priority:
add
in interface RealMatrix
add
in class AbstractRealMatrix
m
- the matrix to be addedthis
+m
public ArrayRowSymmetricMatrix add(SymmetricMatrix m)
m
to this matrix.add
in interface SymmetricMatrix
m
- the matrix to be addedthis
+m
public ArrayRowSymmetricMatrix add(DiagonalMatrix m)
m
to this matrix.m
- the matrix to be addedthis
+ m
MatrixDimensionMismatchException
- if the matrix m
is not the same size as this matrixpublic RealMatrix subtract(RealMatrix m)
m
from this matrix.
The returned matrix is, in order of priority:
subtract
in interface RealMatrix
subtract
in class AbstractRealMatrix
m
- the matrix to be subtractedthis
-m
public ArrayRowSymmetricMatrix subtract(SymmetricMatrix m)
m
from this matrix.subtract
in interface SymmetricMatrix
m
- the matrix to be subtractedthis
-m
public ArrayRowSymmetricMatrix subtract(DiagonalMatrix m)
m
from this matrix.m
- the matrix to be subtractedthis
- m
MatrixDimensionMismatchException
- if the matrix m
is not the same size as this matrixpublic RealMatrix multiply(RealMatrix m, boolean toTranspose, double d)
m
or its transpose
m
T, then by the scalar d
.multiply
in interface RealMatrix
multiply
in class AbstractRealMatrix
m
- 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
×m
T×d
public RealMatrix multiply(DiagonalMatrix m, double d)
m
, then by
the scalar d
.multiply
in class AbstractRealMatrix
m
- the diagonal matrix by which to multiply this matrix byd
- the scalar by which to multiply the resulting matrix bythis
×m
×d
or
this
×m
T×d
public ArrayRowSymmetricMatrix quadraticMultiplication(RealMatrix m)
this
×MT,
where M is the provided matrix.quadraticMultiplication
in interface SymmetricMatrix
m
- the matrix Mthis
×MTpublic ArrayRowSymmetricMatrix quadraticMultiplication(RealMatrix m, boolean isTranspose)
this
×MT,
where M or MT is the provided matrix.quadraticMultiplication
in interface SymmetricMatrix
m
- the matrix M or the matrix MTisTranspose
- if true
, assumes the provided matrix is MT, otherwise assumes it is
Mthis
×MTpublic ArrayRowSymmetricMatrix 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 RealMatrix
power
in interface SymmetricMatrix
power
in class AbstractRealMatrix
p
- the exponent p
to which this matrix is to be raisedp
public ArrayRowSymmetricMatrix 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 RealMatrix
createMatrix
in interface SymmetricMatrix
createMatrix
in class AbstractRealMatrix
rowDimension
- the number of rows in the new matrixcolumnDimension
- the number of columns in the new matrixpublic static ArrayRowSymmetricMatrix createIdentityMatrix(int dim)
dim
- the dimension of the identity matrixpublic 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 ArrayRowSymmetricMatrix 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 RealMatrix
transpose
in interface SymmetricMatrix
transpose
in class AbstractRealMatrix
forceCopy
- 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 RealMatrix
concatenateHorizontally
in class AbstractRealMatrix
m
- 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 RealMatrix
concatenateVertically
in class AbstractRealMatrix
m
- 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 RealMatrix
concatenateDiagonally
in class AbstractRealMatrix
m
- 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 ArrayRowSymmetricMatrix getInverse()
The default decomposition builder can be changed using the
setDefaultDecomposition
method.
getInverse
in interface RealMatrix
getInverse
in interface SymmetricMatrix
getInverse
in class AbstractRealMatrix
RealMatrix.getDefaultDecomposition()
,
RealMatrix.setDefaultDecomposition(Function)
public ArrayRowSymmetricMatrix getInverse(Function<RealMatrix,Decomposition> decompositionBuilder)
The decomposition builder is a function capable of generating new instances of the decomposition algorithm to be used for the computation of the inverse matrix (like the QRDecomposition or the EigenDecomposition, for instance).
getInverse
in interface RealMatrix
getInverse
in interface SymmetricMatrix
getInverse
in class AbstractRealMatrix
decompositionBuilder
- the decomposition builder to usepublic boolean isSquare()
isSquare
in interface AnyMatrix
isSquare
in class AbstractRealMatrix
public 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 RealMatrix
isSymmetric
in class AbstractRealMatrix
true
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 RealMatrix
isSymmetric
in class AbstractRealMatrix
relativeTolerance
- 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 RealMatrix
isSymmetric
in class AbstractRealMatrix
relativeTolerance
- 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 boolean equals(Object object)
true
if the provided object is a RealMatrix instance with the
same dimensions as this matrix, whose entries are strictly equal to the entries of this
matrix (no absolute or relative tolerance is taken into account when comparing the entries).equals
in class AbstractRealMatrix
object
- the object to be tested for equalitytrue
if the provided object is equal to this matrixpublic int hashCode()
hashCode
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.
null
)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 absolute symmetry threshold (≥0 or null
)IllegalArgumentException
- if the provided threshold is NaN
or is strictly negativepublic static Double getDefaultRelativeSymmetryThreshold()
A null
value means the symmetry is enforced without any check on the relative
difference between symmetric elements.
null
)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 the provided threshold is NaN
or is strictly negativeCopyright © 2023 CNES. All rights reserved.