|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.AbstractCollection<E> java.util.AbstractList<E> java.util.ArrayList<SparseVector> org.knowceans.mcl.SparseMatrix
public class SparseMatrix
SparseMatrix is a sparse matrix with row-major format.
Conventions: except for the inherited methods and normalise(double), operations leave this ummodified (immutable) if there is a return value. Within operations, no pruning of values close to zero is done. Pruning can be controlled via the prune() method.
Field Summary | |
---|---|
private int |
maxVLength
|
private static long |
serialVersionUID
|
Fields inherited from class java.util.AbstractList |
---|
modCount |
Constructor Summary | |
---|---|
SparseMatrix()
empty sparse matrix |
|
SparseMatrix(double[][] x)
create sparse matrix from full matrix |
|
SparseMatrix(int rows,
int cols)
empty sparse matrix with allocated number of rows |
|
SparseMatrix(SparseMatrix matrix)
copy contructor |
Method Summary | |
---|---|
double |
add(int i,
int j,
double a)
adds a to the specified element, growing the matrix if necessary. |
void |
adjustMaxIndex(int i,
int j)
adjusts the size of the matrix. |
SparseMatrix |
copy()
copy the matrix and its elements |
double |
get(int i,
int j)
get number at index or 0. if not set. |
SparseVector |
getColum(int i)
get a column of the sparse matrix (expensive). |
double[][] |
getDense()
create dense representation |
int[] |
getSize()
get the size of the matrix |
void |
hadamardPower(double s)
mutable m2 = m .^ s |
void |
hadamardProduct(SparseMatrix m)
mutable Hadamard product |
private void |
increase(int i)
increase the size of the matrix with empty element SparseVectors. |
SparseMatrix |
matrixTimes(SparseMatrix m)
immutable multiply matrix M with this (A) : M * A |
SparseVector |
normalise(double rowsum)
normalise rows to rowsum |
void |
normaliseCols()
normalise by minor dimension (columns), expensive. |
void |
normaliseRows()
normalise by major dimension (rows) |
void |
prune(double threshold)
prune all values whose magnitude is below threshold |
double |
set(int i,
int j,
double a)
set the value at the index i,j, returning the old value or 0. |
SparseVector |
set(int i,
SparseVector x)
set the sparse vector at index i. |
SparseMatrix |
times(SparseMatrix m)
immutable multiply this matrix (A) with M : A * M |
SparseVector |
times(SparseVector v)
immutable multiply this times the vector: A * x, i.e., rowwise. |
SparseMatrix |
timesTransposed(SparseMatrix m)
mutable multiply this matrix (A) with M : A * M' |
java.lang.String |
toString()
|
java.lang.String |
toStringDense()
prints a dense representation |
SparseMatrix |
transpose()
immutable transpose. |
SparseVector |
vectorTimes(SparseVector v)
immutable multiply the vector times this: x' * A, i.e., colwise. |
Methods inherited from class java.util.ArrayList |
---|
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, remove, remove, removeRange, size, toArray, toArray, trimToSize |
Methods inherited from class java.util.AbstractList |
---|
equals, hashCode, iterator, listIterator, listIterator, subList |
Methods inherited from class java.util.AbstractCollection |
---|
containsAll, removeAll, retainAll |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.List |
---|
containsAll, equals, hashCode, iterator, listIterator, listIterator, removeAll, retainAll, subList |
Field Detail |
---|
private static final long serialVersionUID
private int maxVLength
Constructor Detail |
---|
public SparseMatrix()
public SparseMatrix(int rows, int cols)
rows
- cols
- public SparseMatrix(double[][] x)
x
- public SparseMatrix(SparseMatrix matrix)
matrix
- Method Detail |
---|
public double[][] getDense()
public SparseVector set(int i, SparseVector x)
set
in interface java.util.List<SparseVector>
set
in class java.util.ArrayList<SparseVector>
i
- x
-
public double get(int i, int j)
i
- j
-
public double set(int i, int j, double a)
i
- j
- a
-
public void adjustMaxIndex(int i, int j)
i
- index addressedj
- index addressedprivate void increase(int i)
i
- public int[] getSize()
public double add(int i, int j, double a)
i
- j
- a
-
public SparseVector normalise(double rowsum)
rowsum
- for each row
public void normaliseRows()
public void normaliseCols()
public SparseMatrix copy()
public SparseVector times(SparseVector v)
v
-
public SparseVector vectorTimes(SparseVector v)
v
-
public SparseMatrix timesTransposed(SparseMatrix m)
m
-
public SparseMatrix times(SparseMatrix m)
m
-
public SparseMatrix matrixTimes(SparseMatrix m)
m
-
public SparseMatrix transpose()
public SparseVector getColum(int i)
public void hadamardProduct(SparseMatrix m)
m
- public void hadamardPower(double s)
s
- public java.lang.String toString()
toString
in class java.util.AbstractCollection<SparseVector>
public java.lang.String toStringDense()
public void prune(double threshold)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |