|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.commons.math3.linear.RealLinearOperator
org.apache.commons.math3.linear.AbstractRealMatrix
org.apache.commons.math3.linear.SymmetricMatrix
public class SymmetricMatrix
Implementation of a symmetric matrix.
Operation are optimized to take advantage of symmetric properties of this kind of matrix.
| Nested Class Summary | |
|---|---|
static class |
SymmetricMatrix.SYMMETRIC
Enumerate to fill in a symmetric matrix only by its lower/upper part. |
| Constructor Summary | |
|---|---|
SymmetricMatrix(SymmetricMatrix.SYMMETRIC uplo,
int n,
int ld)
Creates a matrix with the supplied dimensions. |
|
SymmetricMatrix(SymmetricMatrix.SYMMETRIC uplo,
int n,
int ld,
double[] d)
Creates a matrix given the supplied dimensions and data array. |
|
SymmetricMatrix(SymmetricMatrix.SYMMETRIC uplo,
int n,
int ld,
double[][] d)
Creates a matrix given the supplied dimensions and data array 2D. |
|
SymmetricMatrix(SymmetricMatrix.SYMMETRIC uplo,
int n,
int ld,
double[] d,
boolean copyArray)
Creates a matrix given the supplied dimensions and data array. |
|
SymmetricMatrix(SymmetricMatrix.SYMMETRIC uplo,
int n,
int ld,
RealMatrix m)
Creates a symmetric matrix using a real matrix. |
|
| Method Summary | |
|---|---|
SymmetricMatrix |
add(DiagonalMatrix m)
Compute the sum of this and m. |
RealMatrix |
add(RealMatrix m)
Returns the sum of this and m. |
SymmetricMatrix |
add(SymmetricMatrix m)
Compute the sum of this and m. |
void |
addToEntry(int row,
int column,
double increment)
Adds (in place) the specified value to the specified entry of this matrix. |
SymmetricMatrix |
copy()
Returns a (deep) copy of this. |
static SymmetricMatrix |
createDiagonalMatrixWithArray(int dim,
int lda,
double[] coeff)
Creates an instance of SymmetricMatrix which is diagonal of input element. |
SymmetricMatrix |
createMatrix(int lda,
int dim)
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. |
double |
getEntry(int row,
int column)
Get the entry in the specified row and column. |
int |
getRowDimension()
Returns the number of rows of this matrix. |
boolean |
isSymmetric()
Checks if this is a symmetric matrix |
RealMatrix |
multiply(DiagonalMatrix m)
Returns the result of postmultiplying this by m. |
RealMatrix |
multiply(RealMatrix m)
Returns the result of postmultiplying this by m. |
RealMatrix |
multiply(SymmetricMatrix m)
Returns the result of postmultiplying this by m. |
void |
multiplyEntry(int row,
int column,
double factor)
Multiplies (in place) the specified entry of this matrix by the
specified value. |
static SymmetricMatrix |
newByCopy(SymmetricMatrix.SYMMETRIC uplo,
int n,
int ld,
SymmetricMatrix.SYMMETRIC uploMat,
RealMatrix mat)
Create a symmetric matrix by copy of a triangle of a matrix. |
static SymmetricMatrix |
newByCopyAndSymmetrize(SymmetricMatrix.SYMMETRIC uplo,
int n,
int ld,
RealMatrix mat)
Create a symmetric matrix by computation of the mean of the 2 triangles of a matrix. |
static SymmetricMatrix |
newByCopyOfPackedStorage(SymmetricMatrix.SYMMETRIC uplo,
int n,
int ld,
double[] d)
Creates a symmetric matrix using one of the triangles stored in 'packed' storage. |
SymmetricMatrix |
scalarMultiply(double d)
Returns the result of multiplying each entry of this by
d. |
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)
Replace the submatrix starting at row, column using data in the
input subMatrix array. |
void |
setSubMatrixWithMatrix(RealMatrix subMatrix,
int row,
int column)
Method setSubMatrix using a RealMatrix for subMatrix instead of an array |
SymmetricMatrix |
subtract(DiagonalMatrix m)
Compute this minus m. |
RealMatrix |
subtract(RealMatrix m)
Returns this minus m. |
SymmetricMatrix |
subtract(SymmetricMatrix m)
Compute this minus m. |
static void |
symmetricMatrixOperation(double alpha,
SymmetricMatrix symA,
RealMatrix matB,
double beta,
RealMatrix matC)
Performs the matrix-matrix operations C := alpha*A*B + beta*C where alpha and beta are scalars, A is a symmetric matrix and B and C are n by n matrices. |
RealMatrix |
transpose()
Returns the transpose of this matrix. |
| Methods inherited from class org.apache.commons.math3.linear.AbstractRealMatrix |
|---|
copySubMatrix, copySubMatrix, equals, getColumn, getColumnMatrix, getColumnVector, getData, getFrobeniusNorm, getNorm, getRow, getRowMatrix, getRowVector, getSubMatrix, getSubMatrix, getTrace, hashCode, isAntisymmetric, isDiagonal, isInvertible, isOrthogonal, isSquare, isSymmetric, operate, operate, power, preMultiply, preMultiply, preMultiply, scalarAdd, setColumn, setColumnMatrix, setColumnVector, setRow, setRowMatrix, setRowVector, toString, walkInColumnOrder, walkInColumnOrder, walkInColumnOrder, walkInColumnOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInOptimizedOrder, walkInRowOrder, walkInRowOrder, walkInRowOrder, walkInRowOrder |
| Methods inherited from class org.apache.commons.math3.linear.RealLinearOperator |
|---|
isTransposable, operateTranspose |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public SymmetricMatrix(SymmetricMatrix.SYMMETRIC uplo,
int n,
int ld)
uplo - the triangle that will be usedn - the dimension of the matrixld - the leading dimension of the matrix. ld is normaly equal to n. It can be set larger
in some case for performance improvements
public SymmetricMatrix(SymmetricMatrix.SYMMETRIC uplo,
int n,
int ld,
double[] d,
boolean copyArray)
uplo - the triangle that will be usedn - the dimension of the matrixld - the leading dimension of the matrix. ld is normaly equal to n. It can be set larger
in some case for performance improvementsd - the array to be viewed as a conventional full storage
symmetric matrixcopyArray - if the array must be copied
public SymmetricMatrix(SymmetricMatrix.SYMMETRIC uplo,
int n,
int ld,
double[] d)
throws NonSquareMatrixException
uplo - the triangle that will be usedn - the dimension of the matrixld - the leading dimension of the matrix. ld is normaly equal to n. It can be set larger
in some case for performance improvementsd - the array to be viewed as a conventional full storage
symmetric matrix
NonSquareMatrixException - if matrix is not square
public SymmetricMatrix(SymmetricMatrix.SYMMETRIC uplo,
int n,
int ld,
double[][] d)
throws NonSquareMatrixException
newByCopy(SYMMETRIC, int, int, SYMMETRIC, RealMatrix).
uplo - the triangle that will be usedn - the dimension of the matrixld - the leading dimension of the created matrix. ld is normaly equal to n. It can be set larger
in some case for performance improvementsd - data for the new matrix
NonSquareMatrixException - if matrix is not square
public SymmetricMatrix(SymmetricMatrix.SYMMETRIC uplo,
int n,
int ld,
RealMatrix m)
throws NonSquareMatrixException
uplo - the triangle that will be usedn - the dimension of the matrixld - the leading dimension of the created matrix. ld is normaly equal to n. It can be set larger
in some case for performance improvementsm - the real matrix to be used
NonSquareMatrixException - if matrix is not square| Method Detail |
|---|
public static SymmetricMatrix newByCopy(SymmetricMatrix.SYMMETRIC uplo,
int n,
int ld,
SymmetricMatrix.SYMMETRIC uploMat,
RealMatrix mat)
throws NonSquareMatrixException
uplo - the triangle to usen - the dimension of the created matrixld - the leading dimension of the created matrix. ld is normaly equal to n. It can be set larger
in some case for performance improvementsuploMat - the triangle to use from the input matrixmat - the matrix from which the data are extracted
NonSquareMatrixException - if matrix is not square
public static SymmetricMatrix newByCopyAndSymmetrize(SymmetricMatrix.SYMMETRIC uplo,
int n,
int ld,
RealMatrix mat)
uplo - the triangle to usen - the dimension of the created matrixld - the leading dimension of the created matrix. ld is normaly equal to n. It can be set larger
in some case for performance improvementsmat - the matrix from which the data are extracted
public static SymmetricMatrix newByCopyOfPackedStorage(SymmetricMatrix.SYMMETRIC uplo,
int n,
int ld,
double[] d)
throws NonSquareMatrixException
uplo - lower/upper known part of the matrixn - the dimension of the created matrixld - the leading dimension of the created matrix. ld is normaly equal to n. It can be set larger
in some case for performance improvementsd - data in 'packed storage'
NonSquareMatrixException - if matrix is not square
public SymmetricMatrix createMatrix(int lda,
int dim)
throws NotStrictlyPositiveException
createMatrix in interface RealMatrixcreateMatrix in class AbstractRealMatrixlda - the number of rows in the new matrixdim - the number of columns in the new matrix
NotStrictlyPositiveException - if row or column dimension is not
positive.
public static SymmetricMatrix createDiagonalMatrixWithArray(int dim,
int lda,
double[] coeff)
throws NotStrictlyPositiveException
dim - the dimension of the created matrixlda - the leading dimension of the created matrix. ld is normaly equal to n. It can be set larger
in some case for performance improvementscoeff - value of diagonals elements
NotStrictlyPositiveException - if n or ld are not positivepublic SymmetricMatrix copy()
copy in interface RealMatrixcopy in class AbstractRealMatrixpublic RealMatrix transpose()
transpose in interface RealMatrixtranspose in class AbstractRealMatrix
public static void symmetricMatrixOperation(double alpha,
SymmetricMatrix symA,
RealMatrix matB,
double beta,
RealMatrix matC)
alpha - the first value to use in above linear combinationsymA - the input symmetric matrixmatB - the input matrix, instance of RealMatrixbeta - the second value to use in above linear combinationmatC - the input/output matrix, instance of RealMatrix
public SymmetricMatrix add(SymmetricMatrix m)
throws DimensionMismatchException
m.
m - matrix to be added
DimensionMismatchException - if m is not the same size as this
public SymmetricMatrix add(DiagonalMatrix m)
throws IllegalArgumentException
m.
m - Diagonal matrix to be added
IllegalArgumentException - if m is not the same size as this
public RealMatrix add(RealMatrix m)
throws IllegalArgumentException
this and m.
add in interface RealMatrixadd in class AbstractRealMatrixm - matrix to be added
this + m
MatrixDimensionMismatchException - if m is not the same
size as this.
IllegalArgumentException
public SymmetricMatrix subtract(SymmetricMatrix m)
throws IllegalArgumentException
m.
m - matrix to be subtracted
IllegalArgumentException - if m is not the same size as this
public SymmetricMatrix subtract(DiagonalMatrix m)
throws IllegalArgumentException
m.
m - Diagonal matrix to be added
IllegalArgumentException - if m is not the same size as this
public RealMatrix subtract(RealMatrix m)
throws IllegalArgumentException
this minus m.
subtract in interface RealMatrixsubtract in class AbstractRealMatrixm - matrix to be subtracted
this - m
MatrixDimensionMismatchException - if m is not the same
size as this.
IllegalArgumentException
public RealMatrix multiply(SymmetricMatrix m)
throws IllegalArgumentException
m.
m - matrix to postmultiply by
IllegalArgumentException - if columnDimension(this) != rowDimension(m)
public RealMatrix multiply(DiagonalMatrix m)
throws IllegalArgumentException
m.
m - Diagonal matrix to postmultiply by
IllegalArgumentException - if columnDimension(this) != rowDimension(m)
public RealMatrix multiply(RealMatrix m)
throws IllegalArgumentException
this by m.
multiply in interface RealMatrixmultiply in class AbstractRealMatrixm - matrix to postmultiply by
this * m
DimensionMismatchException - if
columnDimension(this) != rowDimension(m)
IllegalArgumentExceptionpublic SymmetricMatrix scalarMultiply(double d)
this by
d.
scalarMultiply in interface RealMatrixscalarMultiply in class AbstractRealMatrixd - value to multiply all entries by
d * this
public void setSubMatrix(double[][] subMatrix,
int row,
int column)
throws NoDataException,
OutOfRangeException,
DimensionMismatchException,
NullArgumentException
row, column using data in the
input subMatrix array. Indexes are 0-based.
Example:
Starting with
1 2 3 4 5 6 7 8 9 0 1 2and
subMatrix = {{3, 4} {5,6}}, invoking
setSubMatrix(subMatrix,1,1)) will result in 1 2 3 4 5 3 4 8 9 5 6 2
setSubMatrix in interface RealMatrixsetSubMatrix in class AbstractRealMatrixsubMatrix - 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 replaced
NoDataException - if subMatrix is empty.
OutOfRangeException - if subMatrix does not fit into
this matrix from element in (row, column).
DimensionMismatchException - if subMatrix is not rectangular
(not all rows have the same length) or empty.
NullArgumentException - if subMatrix is null.
public void setSubMatrixWithMatrix(RealMatrix subMatrix,
int row,
int column)
throws NoDataException,
OutOfRangeException,
DimensionMismatchException,
NullArgumentException
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 replaced
NoDataException - if subMatrix is empty.
OutOfRangeException - if subMatrix does not fit into
this matrix from element in (row, column).
DimensionMismatchException - if subMatrix is not rectangular
(not all rows have the same length) or empty.
NullArgumentException - if subMatrix is null.
public double getEntry(int row,
int column)
throws OutOfRangeException
getEntry in interface RealMatrixgetEntry in class AbstractRealMatrixrow - Row index of entry to be fetched.column - Column index of entry to be fetched.
(row, column).
OutOfRangeException - if the row or column index is not valid.
public void setEntry(int row,
int column,
double value)
throws OutOfRangeException
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.
OutOfRangeException - if the row or column index is not valid
public void addToEntry(int row,
int column,
double increment)
throws OutOfRangeException
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.
OutOfRangeException - if the row or column index is not valid.
public void multiplyEntry(int row,
int column,
double factor)
throws OutOfRangeException
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.
OutOfRangeException - if the row or column index is not valid.public int getRowDimension()
getRowDimension in interface AnyMatrixgetRowDimension in class AbstractRealMatrixpublic int getColumnDimension()
getColumnDimension in interface AnyMatrixgetColumnDimension in class AbstractRealMatrixpublic boolean isSymmetric()
isSymmetric in interface RealMatrixisSymmetric in class AbstractRealMatrix
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||