public class SymmetricMatrix extends Object implements Matrix, Densifiable
A[i][j] = A[j][i]
Constructor and Description |
---|
SymmetricMatrix(double[][] data)
Construct a symmetric matrix from a 2D
double[][] array. |
SymmetricMatrix(int dim)
Construct a symmetric matrix of dimension dim * dim.
|
SymmetricMatrix(Matrix A)
Cast an (almost) symmetric matrix into SymmetricMatrix by averaging A(i,j) and
A(j,i).
|
SymmetricMatrix(Matrix A,
boolean copyLower)
Cast an (almost) symmetric matrix into SymmetricMatrix.
|
SymmetricMatrix(SymmetricMatrix S)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
Matrix |
add(Matrix that)
this + that
|
SymmetricMatrix |
deepCopy()
The implementation returns an instance created from
this by the copy
constructor of the class, or just this if the instance itself is
immutable. |
boolean |
equals(Object obj) |
double |
get(int i,
int j)
Get the matrix entry at [i,j].
|
Vector |
getColumn(int j)
Get the specified column in the matrix as a vector.
|
Vector |
getRow(int i)
Get the specified row in the matrix as a vector.
|
int |
hashCode() |
Matrix |
minus(Matrix that)
this - that
|
Matrix |
multiply(Matrix that)
this * that
|
Vector |
multiply(Vector v)
Right multiply this matrix, A, by a vector.
|
int |
nCols()
Gets the number of columns.
|
int |
nRows()
Gets the number of rows.
|
SymmetricMatrix |
ONE()
Get an identity matrix that has the same dimension as this matrix.
|
SymmetricMatrix |
opposite()
Get the opposite of this matrix.
|
SymmetricMatrix |
scaled(double scalar)
Scale this matrix, A, by a constant.
|
void |
set(int row,
int col,
double value)
Set the matrix entry at [i,j] to a value.
|
SymmetricMatrix |
t()
The transpose of a symmetric matrix is the same as itself.
|
DenseMatrix |
toDense()
Densify a matrix, i.e., convert a matrix implementation to the standard dense matrix,
DenseMatrix . |
String |
toString() |
SymmetricMatrix |
ZERO()
Get a zero matrix that has the same dimension as this matrix.
|
public SymmetricMatrix(int dim)
dim
- the matrix dimensionpublic SymmetricMatrix(double[][] data)
double[][]
array.
The array specifies only the lower triangular part (main diagonal inclusive) of the whole
matrix.
For example,
new double[][]{
{1},
{2, 3},
{4, 5, 6},
{7, 8, 9, 10},
{11, 12, 13, 14, 15}});
gives
\[
\begin{bmatrix}
1 & 2 & 4 & 7 & 11\\
2 & 3 & 5 & 8 & 12\\
4 & 5 & 6 & 9 & 13\\
7 & 8 & 9 & 10 & 14\\
11 & 12 & 13 & 14 & 15
\end{bmatrix}
\]
This constructor uses lower instead of upper triangular representation for visual reason.data
- the lower triangular specificationpublic SymmetricMatrix(Matrix A)
A
- an (almost) symmetric matrixpublic SymmetricMatrix(Matrix A, boolean copyLower)
A
- an (almost) symmetric matrixcopyLower
- true
if the lower triangular portion of A is used; otherwise, the
average values of A(i,j) and A(j,i) are usedpublic SymmetricMatrix(SymmetricMatrix S)
S
- a symmetric matrixpublic int nRows()
Table
public int nCols()
Table
public SymmetricMatrix deepCopy()
DeepCopyable
this
by the copy
constructor of the class, or just this
if the instance itself is
immutable.deepCopy
in interface Matrix
deepCopy
in interface DeepCopyable
public DenseMatrix toDense()
Densifiable
DenseMatrix
.toDense
in interface Densifiable
DenseMatrix
public void set(int row, int col, double value) throws MatrixAccessException
MatrixAccess
set
in interface MatrixAccess
row
- the row indexcol
- the column indexvalue
- the value to set A[i,j] toMatrixAccessException
- if i or j is out of rangepublic double get(int i, int j) throws MatrixAccessException
MatrixAccess
get
in interface MatrixAccess
i
- the row indexj
- the column indexMatrixAccessException
- if i or j is out of rangepublic Vector getRow(int i) throws MatrixAccessException
Matrix
getRow
in interface Matrix
i
- the row indexMatrixAccessException
- when i < 1, or when i > the number of rowspublic Vector getColumn(int j) throws MatrixAccessException
Matrix
getColumn
in interface Matrix
j
- the column indexMatrixAccessException
- when j < 1, or when j > the number of columnspublic Matrix add(Matrix that)
MatrixRing
add
in interface MatrixRing
add
in interface AbelianGroup<Matrix>
that
- a matrixthis
and that
public Matrix minus(Matrix that)
MatrixRing
minus
in interface MatrixRing
minus
in interface AbelianGroup<Matrix>
that
- a matrixthis
and that
public Matrix multiply(Matrix that)
MatrixRing
multiply
in interface MatrixRing
multiply
in interface Monoid<Matrix>
that
- a matrixthis
and that
public SymmetricMatrix t()
t
in interface MatrixRing
public SymmetricMatrix scaled(double scalar)
Matrix
public SymmetricMatrix opposite()
MatrixRing
opposite
in interface MatrixRing
opposite
in interface AbelianGroup<Matrix>
public SymmetricMatrix ZERO()
MatrixRing
ZERO
in interface MatrixRing
ZERO
in interface AbelianGroup<Matrix>
public SymmetricMatrix ONE()
MatrixRing
ONE
in interface MatrixRing
ONE
in interface Monoid<Matrix>
public Vector multiply(Vector v)
Matrix
Copyright © 2010-2020 NM FinTech Ltd.. All Rights Reserved.