|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectmpv2.AllMatrices
mpv2.SparseMatrix
public class SparseMatrix
This class is a sparse matrix implementation.
The class SparseMatrices contains stores the matrix elements in a way
well suitable to sparse matrices, i.e. most of the entries are zero.
For each non-zero element a structure with 5 fields are stored:
the row index, the coluimn index, the value, a pointer to next in same row
and a pointer to next in same column. Thus the sparsness factor, i.e.
number of non-zero elements divided by total number of elements, should
be lower that 0.2 to get any effect, and lower than 0.1 to get significant
improvement related to the Matrix-class. Read access, especially to
a row or column is effective, while write access, especially to elements
which are zero, are slower.
There is a quite large number of methods available for matrices in general
and in this class specially, see the AllMatrices class for a general overview.
Here is a brief overview for added methods:
| Field Summary |
|---|
| Fields inherited from class mpv2.AllMatrices |
|---|
K, N |
| Constructor Summary | |
|---|---|
SparseMatrix(AllMatrices B)
Construct a new matrix from another matrix (of any kind) |
|
SparseMatrix(double[][] A)
Construct a matrix from a 2-D array. |
|
SparseMatrix(double[] vals,
int m)
Construct a matrix from a one-dimensional packed array |
|
SparseMatrix(int m,
int n)
Construct an m-by-n sparse matrix of zeros. |
|
| Method Summary | |
|---|---|
void |
addColumn(int k,
double factor,
double[] x)
Add a column of the matrix multiplied by a factor to x, x = x + A[][k] Legal range of the integer argument is 0 <= k < K. |
double |
get(int n,
int k)
Get a single element. |
int |
getCapacity()
Returns current size (capacity for non-zero values) in sparse matrix. |
double[] |
getColumn(int k)
Copy a column of the matrix Legal range of the integer argument is 0 <= k < K. |
void |
getColumn(int k,
double[] d)
Sets argument d to a column of the matrix, i.e. a dictionary element or atom. |
double[] |
getColumnPackedCopy()
Make a one-dimensional column packed copy of the matrix. |
int |
getNonZeroCount()
Returns number of non-zeros elements in sparse matrix. |
double[] |
getRow(int n)
Copy a row of the matrix Legal range of the integer argument is 0 <= n < N. |
void |
getRow(int n,
double[] r)
Copy a row of the matrix Legal range of the integer argument is 0 <= n < N. |
double[] |
getRowPackedCopy()
Make a one-dimensional row packed copy of the matrix. |
double |
innerProduct(int k1,
int k2)
Returns the inner product of two dictionary elements, i.e. matrix column vectors. |
double |
normF()
Frobenius norm |
void |
set(int n,
int k,
double val)
Set an entry (a value) in the dictionary. |
void |
setAll(double[] vals)
Set all entries of to matrix to the supplied new values If argument is wrong length an IllegalArgumentException is thrown. |
JamaMatrix |
times(AllMatrices B)
Multiplies the matrix by an another matrix, return C = A * B |
void |
times(double[] y,
double[] x)
Multiplies the dictionary D by array y. |
JamaMatrix |
transposeTimes(AllMatrices C)
Multiplies the transposed matrix by an another matrix, return B = A' * C |
void |
transposeTimes(double[] x,
double[] y)
Multiplies the transposed dictionary D' by array x. |
| Methods inherited from class mpv2.AllMatrices |
|---|
chol, columnNorm0, columnNorm1, columnNorm2, columnNormInf, cond, det, eig, eqConstant, eqCopy, eqCopy, eqCopy, eqCopy, eqCopy, eqDifference, eqEProduct, eqEQuotient, eqIdentity, eqInverse, eqIProduct, eqNegate, eqOnes, eqPermuteColumns, eqPermuteRows, eqProduct, eqProduct, eqRandom, eqScaleColumns, eqScaleRows, eqSum, eqTProduct, eqTranspose, eqZeros, getAll, getAll, getColumnDimension, getK, getN, getRowDimension, getSubMatrix, getSubMatrix, getSubMatrix, getSubMatrix, getValue, lu, lup, norm1, norm2, normInf, pluseqOuterProduct, print, print, print, print, qr, rank, setColumn, setRow, setValue, sumAll, svd, times, times, times, trace, transposeTimes, transposeTimes, transposeTimes |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public SparseMatrix(int m,
int n)
m - Number of rows.n - Number of colums.public SparseMatrix(double[][] A)
A - Two-dimensional array of doubles.
java.lang.IllegalArgumentException - All rows must have the same length
public SparseMatrix(double[] vals,
int m)
vals - One-dimensional array of doubles, packed by columns (ala Fortran).m - Number of rows, i.e. length of columns.
java.lang.IllegalArgumentException - Array length must be a multiple of m.public SparseMatrix(AllMatrices B)
B - a matrix of any kind, class is a subclass of AllMatrices| Method Detail |
|---|
public double get(int n,
int k)
get in class AllMatricesn - row number for the returned entry value.k - column number for the returned entry value.
java.lang.ArrayIndexOutOfBoundsException
public void set(int n,
int k,
double val)
0 <= n < N and 0 <= k < K.
If any argument is outside legal range nothing is done.
set in class AllMatricesn - row number for the entry value to be changed.k - column number for the entry value to be changed.val - the value to be put into the given entry of the dictionary.public int getNonZeroCount()
public int getCapacity()
public double[] getColumnPackedCopy()
public double[] getRowPackedCopy()
public void setAll(double[] vals)
setAll in class AllMatricesvals - One-dimensional array of doubles, packed by columns (ala Fortran).
public double innerProduct(int k1,
int k2)
0 <= k1 < K and 0 <= k2 < K.
If k1 or k2 are out of range, 0.0 should be returned.
innerProduct in class AllMatricesk1 - number for the first dictionary element.k2 - number for the second dictionary element.public double[] getColumn(int k)
0 <= k < K.
If argument is out of range a length N array of zeros should be returned. A(:,k+1).
getColumn in class AllMatricesk - number of the column in the matrix
public void getColumn(int k,
double[] d)
0 <= k < K.
If argument is out of range a length N array of zeros should be returned. D(:,k+1).
getColumn in class AllMatricesk - number of the column in dictionary, i.e. matrix D.d - the given column of matrix D.
public void addColumn(int k,
double factor,
double[] x)
0 <= k < K. x = x+f*A(:,k+1).
Note that this function can not be used from Matlab, use getColumn(k) to
get A(:,k+1) and calculate the new x in Matlab.
addColumn in class AllMatricesk - number of the column the matrix A.factor - a factor to multiply the column vector by.x - an array of length N.public double[] getRow(int n)
0 <= n < N.
If argument is out of range a length K array of zeros should be returned. A(n+1,:).
getRow in class AllMatricesn - number of the row in the matrix A.
public void getRow(int n,
double[] r)
0 <= n < N.
If argument is out of range a length K array of zeros should be returned. r = A(n+1,:).
getRow in class AllMatricesn - number of the row in the matrix A.r - the given row of matrix A.public double normF()
normF in class AllMatrices
public void transposeTimes(double[] x,
double[] y)
D' by array x.
D is the matrix representing the dictionary, each column is a dictionary
element. An array y is returned. D is
N×K, x is N×1,
and y is K×1. y = D'*x.
transposeTimes in class AllMatricesx - the signal (column vector) that is multiplied by the transposed dictionary.y - the results as an array of length K.
public void times(double[] y,
double[] x)
D by array y.
D is the matrix representing the dictionary,
each column is a dictionary element.
An array x is returned. D is
N×K, x is N×1,
and y is K×1. x = D*y.
times in class AllMatricesy - the coefficient vector that is multiplied by the dictionary.x - the results as an array of length N.public JamaMatrix times(AllMatrices B)
B - another matrix
java.lang.IllegalArgumentException - Matrix inner dimensions must agree.public JamaMatrix transposeTimes(AllMatrices C)
C - another matrix
java.lang.IllegalArgumentException - Matrix inner dimensions must agree.
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||