|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectprea.data.structure.SparseMatrix
public class SparseMatrix
This class implements sparse matrix, containing empty values for most space.
Field Summary | |
---|---|
private SparseVector[] |
cols
The array of column references. |
private int |
M
The number of rows. |
private int |
N
The number of columns. |
private SparseVector[] |
rows
The array of row references. |
Constructor Summary | |
---|---|
SparseMatrix(int m,
int n)
Construct an empty sparse matrix, with a given size. |
|
SparseMatrix(SparseMatrix sm)
Construct an empty sparse matrix, with data copied from another sparse matrix. |
Method Summary | |
---|---|
SparseMatrix |
add(double alpha)
Scalar addition. |
double |
average()
Average of every element. |
SparseMatrix |
cholesky()
Calculate Cholesky decomposition of the matrix. |
SparseMatrix |
covariance()
Generate a covariance matrix of the current matrix. |
SparseVector |
diagonal()
Return items in the diagonal in vector form. |
SparseMatrix |
exp(double alpha)
Exponential of a given constant. |
SparseVector |
getCol(int index)
Return a copy of a given column. |
SparseVector |
getColRef(int index)
Return a reference of a given column. |
SparseVector |
getRow(int index)
Return a copy of a given row. |
SparseVector |
getRowRef(int index)
Return a reference of a given row. |
double |
getValue(int i,
int j)
Retrieve a stored value from the given index. |
SparseMatrix |
inverse()
Calculate inverse matrix. |
int |
itemCount()
Actual number of items in the matrix. |
int[] |
length()
Capacity of this matrix. |
static SparseMatrix |
makeIdentity(int n)
Generate an identity matrix with the given size. |
double |
max()
The value of maximum element in the matrix. |
double |
min()
The value of minimum element in the matrix. |
SparseMatrix |
partInverse(int[] indexList)
Inverse of matrix only with indices in indexList. |
SparseMatrix |
partMinus(SparseMatrix B,
int[] indexList)
Matrix subtraction (A = A - B) only with indices in indexList. |
SparseMatrix |
partPlus(SparseMatrix B,
int[] indexList)
Matrix summation (A = A + B) only with indices in indexList. |
SparseMatrix |
partScale(double alpha,
int[] indexList)
Scalar Multiplication only with indices in indexList. |
SparseVector |
partTimes(SparseVector x,
int[] indexList)
Matrix-vector product (b = Ax) only with indices in indexList. |
SparseMatrix |
plus(SparseMatrix B)
Matrix-matrix sum (C = A + B) |
SparseMatrix |
scale(double alpha)
Scalar subtraction (aX). |
void |
selfAdd(double alpha)
Scalar addition on the matrix itself. |
void |
selfScale(double alpha)
Scalar subtraction (aX) on the matrix itself. |
void |
selfTimes(SparseMatrix B)
Matrix-matrix product (A = AB), without using extra memory. |
void |
setSize(int m,
int n)
Set a new size of the matrix. |
void |
setValue(int i,
int j,
double value)
Set a new value at the given index. |
double |
stdev()
Standard Deviation of every element. |
SparseMatrix |
times(SparseMatrix B)
Matrix-matrix product (C = AB) |
SparseVector |
times(SparseVector x)
Matrix-vector product (b = Ax) |
DenseMatrix |
toDenseMatrix()
Convert the matrix into the array-based dense representation. |
DenseMatrix |
toDenseSubset(int[] indexList)
Convert the matrix into the array-based dense representation, but only with the selected indices. |
DenseMatrix |
toDenseSubset(int[] rowList,
int[] colList)
Convert the matrix into the array-based dense representation, but only with the selected indices, both rows and columns separately. |
java.lang.String |
toString()
Convert the matrix to a printable string. |
SparseMatrix |
transpose()
The transpose of the matrix. |
double |
variance()
Variance of every element. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private int M
private int N
private SparseVector[] rows
private SparseVector[] cols
Constructor Detail |
---|
public SparseMatrix(int m, int n)
m
- The number of rows.n
- The number of columns.public SparseMatrix(SparseMatrix sm)
sm
- The matrix having data being copied.Method Detail |
---|
public double getValue(int i, int j)
i
- The row index to retrieve.j
- The column index to retrieve.
public void setValue(int i, int j, double value)
i
- The row index to store new value.j
- The column index to store new value.value
- The value to store.public SparseVector getRowRef(int index)
index
- The row index to retrieve.
public SparseVector getRow(int index)
index
- The row index to retrieve.
public SparseVector getColRef(int index)
index
- The column index to retrieve.
public SparseVector getCol(int index)
index
- The column index to retrieve.
public DenseMatrix toDenseMatrix()
public DenseMatrix toDenseSubset(int[] indexList)
indexList
- The list of indices converting to dense matrix.
public DenseMatrix toDenseSubset(int[] rowList, int[] colList)
rowList
- The list of row indices converting to dense matrix.colList
- The list of column indices converting to dense matrix.
public int[] length()
public int itemCount()
public void setSize(int m, int n)
m
- The new row count.n
- The new column count.public SparseVector diagonal()
public double max()
public double min()
public double average()
public double variance()
public double stdev()
public SparseMatrix scale(double alpha)
alpha
- The scalar value to be multiplied to this matrix.
public void selfScale(double alpha)
alpha
- The scalar value to be multiplied to this matrix.public SparseMatrix add(double alpha)
alpha
- The scalar value to be added to this matrix.
public void selfAdd(double alpha)
alpha
- The scalar value to be added to this matrix.public SparseMatrix exp(double alpha)
alpha
- The exponent.
public SparseMatrix transpose()
public SparseVector times(SparseVector x)
x
- The vector to be multiplied to this matrix.
java.lang.RuntimeException
- when dimensions disagreepublic SparseMatrix times(SparseMatrix B)
B
- The matrix to be multiplied to this matrix.
java.lang.RuntimeException
- when dimensions disagreepublic void selfTimes(SparseMatrix B)
B
- The matrix to be multiplied to this matrix.
java.lang.RuntimeException
- when dimensions disagreepublic SparseMatrix plus(SparseMatrix B)
B
- The matrix to be added to this matrix.
java.lang.RuntimeException
- when dimensions disagreepublic static SparseMatrix makeIdentity(int n)
n
- The size of requested identity matrix.
public SparseMatrix inverse()
java.lang.RuntimeException
- when dimensions disagree.public SparseMatrix cholesky()
java.lang.RuntimeException
- when matrix is not square.public SparseMatrix covariance()
public SparseMatrix partScale(double alpha, int[] indexList)
alpha
- The scalar to be multiplied to this matrix.indexList
- The list of indices to be applied summation.
public SparseMatrix partPlus(SparseMatrix B, int[] indexList)
B
- The matrix to be added to this matrix.indexList
- The list of indices to be applied summation.
java.lang.RuntimeException
- when dimensions disagree.public SparseMatrix partMinus(SparseMatrix B, int[] indexList)
B
- The matrix to be subtracted from this matrix.indexList
- The list of indices to be applied subtraction.
java.lang.RuntimeException
- when dimensions disagree.public SparseVector partTimes(SparseVector x, int[] indexList)
x
- The vector to be multiplied to this matrix.indexList
- The list of indices to be applied multiplication.
public SparseMatrix partInverse(int[] indexList)
indexList
- The list of indices to be applied multiplication.
java.lang.RuntimeException
- when dimensions disagree.public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |