|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.numericalmethod.suanshu.matrix.doubles.matrixtype.MatrixMathImpl<T>
com.numericalmethod.suanshu.matrix.doubles.matrixtype.MatrixStorageImpl<SymmetricMatrix>
com.numericalmethod.suanshu.matrix.doubles.matrixtype.dense.triangle.SymmetricMatrix
public class SymmetricMatrix
A symmetric matrix is a square matrix such that its transpose equals to itself, i.e.,
A[i][j] = A[j][i]
We implement this class by storing the data using an lower triangular matrix, e.g., LowerTriangularMatrix.
This will reduce the storage cost by almost half compared to DenseMatrix.
We choose to use lower triangular matrix instead of upper triangular matrix for visual reason. A double[] data arrangement resembles a lower triangular matrix.
For example,
new double[][]{
{1},
{2, 3},
{4, 5, 6},
{7, 8, 9, 10},
{11, 12, 13, 14, 15}});
| Field Summary | |
|---|---|
int |
dim
dimension; SymmetricMatrix is always square |
| Constructor Summary | |
|---|---|
SymmetricMatrix(double[][] data)
Construct a symmetric matrix from a 2D double[][] array. |
|
SymmetricMatrix(int dim)
Construct a symmetric matrix of dimension dim * dim. |
|
SymmetricMatrix(SymmetricMatrix S)
Copy constructor performing a deep copy. |
|
| Method Summary | |
|---|---|
SymmetricMatrix |
add(SymmetricMatrix that)
|
SymmetricMatrix |
deepCopy()
The implementation can return an instance created from this by the copy
constructor of the class, or just this if the instance itself is
immutable. |
boolean |
equals(java.lang.Object obj)
Check if two matrices (of different implementations) are equal. |
double |
get(int row,
int col)
Get the matrix entry at [row, col]. |
DenseVector |
getColumn(int col)
Get a specified column as a vector. |
DenseVector |
getRow(int row)
Get a specified row as a vector. |
int |
hashCode()
|
SymmetricMatrix |
minus(SymmetricMatrix that)
|
SymmetricMatrix |
ONE()
Get an identity matrix that has the same dimension as this matrix. |
SymmetricMatrix |
scaled(double scalar)
scalar * this |
void |
set(int row,
int col,
double value)
Set the matrix entry at [row, col] to value. |
SymmetricMatrix |
t()
t(A) = A. |
DenseMatrix |
toDense()
Densify a matrix, i.e., convert a matrix implementation to a standard dense matrix, DenseMatrix. |
java.lang.String |
toString()
|
SymmetricMatrix |
ZERO()
The additive element 0 in the group, such that for all elements a in the group,
the equation 0 + a = a + 0 = a holds. |
| Methods inherited from class com.numericalmethod.suanshu.matrix.doubles.matrixtype.MatrixStorageImpl |
|---|
getMatrixData, setMatrixData |
| Methods inherited from class com.numericalmethod.suanshu.matrix.doubles.matrixtype.MatrixMathImpl |
|---|
add, call, getSample, minus, multiply, multiply, nCols, nRows, opposite, setColumn, setColumn, setRow, setRow |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public final int dim
| Constructor Detail |
|---|
public SymmetricMatrix(int dim)
dim * dim.
Space for the matrix data is not yet allocated.
dim - symmetric matrix dimension, i.e., the number of rows or number of columnspublic SymmetricMatrix(double[][] data)
data - the 2D double[][] arraypublic SymmetricMatrix(SymmetricMatrix S)
S - the matrix to be copied| Method Detail |
|---|
public SymmetricMatrix deepCopy()
Matrixthis by the copy
constructor of the class, or just this if the instance itself is
immutable.
Override the return type.
deepCopy in interface DeepCopyabledeepCopy in interface MatrixMatrix instancepublic DenseMatrix toDense()
DensifiableDenseMatrix.
This is equivalent to
new DenseMatrix(Matrix A)
Individual matrix implementation may optimize the conversion
by taking advantage of having access to the class' private members.
In other words, toDense() is in general more efficient than explicit copy construction.
As an example, for some long matrix computations, we may not be sure about the return type. We can always cast it to the standard matrix. That is,
DenseMatrix A = B.multiply(C).add(D).minus(E).toDense();
This statement always works regardless of the types of B, C, D, and E.
toDense in interface DensifiableDenseMatrix
public void set(int row,
int col,
double value)
throws MatrixAccessException
MatrixAccessor[row, col] to value.
This is the only method that may change the entries of a matrix.
set in interface MatrixAccessorset in class MatrixStorageImpl<SymmetricMatrix>row - the row indexcol - the column indexvalue - the value to set A[row, col] to
MatrixAccessException - if row or col is out of range
public double get(int row,
int col)
throws MatrixAccessException
MatrixAccessor[row, col].
get in interface MatrixAccessorget in class MatrixStorageImpl<SymmetricMatrix>row - the row indexcol - the column index
A[row, col]
MatrixAccessException - if row or col is out of range
public DenseVector getRow(int row)
throws MatrixAccessException
MatrixAccessor
getRow in interface MatrixAccessorgetRow in class MatrixMathImpl<SymmetricMatrix>row - the row index
A[row, ]
MatrixAccessException - when row < 1, or when row > number of rows
public DenseVector getColumn(int col)
throws MatrixAccessException
MatrixAccessor
getColumn in interface MatrixAccessorgetColumn in class MatrixMathImpl<SymmetricMatrix>col - the column index
A[, col]
MatrixAccessException - when col < 1, or when col > number of columnspublic SymmetricMatrix add(SymmetricMatrix that)
public SymmetricMatrix minus(SymmetricMatrix that)
public SymmetricMatrix ZERO()
AbelianGroupa in the group,
the equation 0 + a = a + 0 = a holds.
ZERO in interface AbelianGroup<Matrix>ZERO in interface MatrixRing0public SymmetricMatrix ONE()
MatrixRingFor a non-square matrix, it zeros out the rows (columns) with index > nCols (nRows).
ONE in interface Monoid<Matrix>ONE in interface MatrixRingpublic SymmetricMatrix t()
t(A) = A.
t in interface MatrixRingt in class MatrixMathImpl<SymmetricMatrix>public SymmetricMatrix scaled(double scalar)
Matrixscalar * this
scaled in interface Matrixscaled in class MatrixMathImpl<SymmetricMatrix>scalar - a double
scalar * thispublic java.lang.String toString()
toString in class MatrixMathImpl<SymmetricMatrix>public boolean equals(java.lang.Object obj)
MatrixStorageImpl
equals in class MatrixStorageImpl<SymmetricMatrix>true iff two matrices have the same values, entry-by-entrypublic int hashCode()
hashCode in class MatrixStorageImpl<SymmetricMatrix>
|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||