#include <RowMapSparseMatrix.h>
Inheritance diagram for PLearn::RowMapSparseMatrix< T >:
Public Member Functions | |
RowMapSparseMatrix (int n_rows=0, int n_columns=0) | |
RowMapSparseMatrix (string filename) | |
RowMapSparseMatrix (const Mat &m, bool fill_all=true) | |
RowMapSparseMatrix (const SparseMatrix &sm, int n_rows, int n_cols) | |
Accepts a FORTRAN formatted sparse matrix as an initializer. | |
void | resize (int n_rows, int n_columns) |
THIS ALSO CLEARS THE MATRIX. | |
void | clear () |
this is equivalent to setting all values to "0" (the default value of T) | |
void | clearRow (int i) |
T & | operator() (int i, int j) |
const T & | operator() (int i, int j) const |
map< int, T > & | operator() (int i) |
int | size () const |
NOTE THIS IS A BIT EXPENSIVE! | |
int | length () const |
int | width () const |
void | save (string filename) const |
void | saveAscii (string filename) |
void | load (string filename) |
determines automatically whether file is binary or ascii | |
void | read (istream &in) |
void | write (ostream &out) const |
mode used to write depends on save_binary flag | |
void | saveNonZeroElements (string filename) const |
void | product (const Vec &x, Vec &y) |
multiply a sparse matrix by a full vector and set resulting vector y = matrix * x | |
Mat | toMat () |
bool | isSymmetric (real tolerance=0) |
bool | fillSymmetricPart (real tolerance=0) |
void | diag (Vec &d) |
set d[i] = A[i,i] | |
void | diagonalOfSquare (Vec &d) |
d = diagonal(A*A'), i.e. | |
real | dotRow (int i, Vec v) |
return dot product of i-th row with vector v | |
real | dotColumn (int j, Vec v) |
return dot product of j-th column with vector v | |
void | transposeProduct (RowMapSparseMatrix &m, bool verbose=false) |
M = A' * A. | |
void | add2Rows (Vec row, bool only_on_non_zeros=true) |
add vector to each row; by default do it only on the non-zero elements | |
void | add2Columns (Vec col, bool only_on_non_zeros=true) |
add vector to each column; by default do it only on the non-zero elements | |
void | add (real scalar, bool only_on_non_zeros=true) |
add a scalar everywhere; by default do it only on the non-zero elements | |
void | averageAcrossRowsAndColumns (Vec avg_across_rows, Vec avg_across_columns, bool only_on_non_zeros=true) |
real | sumRow (int i) |
void | operator *= (real scalar) |
multiply each (non-zero) element | |
void | exportToMatlabReadableFormat (string filename) |
real | density () |
Compute the matrix density, that is : number_of_nonzero_elements / (length*width). | |
Static Public Member Functions | |
void | transpose (RowMapSparseMatrix< T > &src, RowMapSparseMatrix< T > &dest) |
D = S'. | |
real | multiplyVecs (map< int, T > &map1, map< int, T > &map2) |
Sparse vectors mutliplication. | |
real | euclidianDistance (map< int, real > &map1, map< int, real > &map2) |
void | substractVecs (map< int, real > &map1, map< int, real > &map2, Vec &dest) |
Vec dest[i] = map1[i] - map2[i]. | |
int | getMaxColumnIndex (map< int, T > &map1, map< int, T > &map2) |
Return the last non-zero position of a sparse vector (used for sparse operations that need to know the "end" of a vector). | |
Public Attributes | |
vector< map< int, T > > | rows |
bool | save_binary |
Protected Attributes | |
int | _width |
We assume that there are elements in each ROW.
We associate an STL map to each row: column index --> value
Space used is about O( size_of_elements * number_of_non_zero_elements )
Random access time is O(log(number_of_elements_per_row))
Row-wise iterations can be done in constant time per access.
Binary or ascii load/save streaming are available. Recommended filename extensions are .armsm and .brmsm respectively for Ascii Row Map Sparse Matrix or Binary Row Map Sparse Matrix.
Definition at line 69 of file RowMapSparseMatrix.h.
|
Definition at line 78 of file RowMapSparseMatrix.h. |
|
Definition at line 81 of file RowMapSparseMatrix.h. |
|
Definition at line 83 of file RowMapSparseMatrix.h. |
|
Accepts a FORTRAN formatted sparse matrix as an initializer.
Definition at line 106 of file RowMapSparseMatrix.h. |
|
add a scalar everywhere; by default do it only on the non-zero elements
Definition at line 507 of file RowMapSparseMatrix.h. |
|
add vector to each column; by default do it only on the non-zero elements
Definition at line 491 of file RowMapSparseMatrix.h. |
|
add vector to each row; by default do it only on the non-zero elements
Definition at line 475 of file RowMapSparseMatrix.h. |
|
average across rows on one hand, and in parallel average across columns (thus getting two averages). The boolean argument specifies whether the average is across the explicit elements (the non-zeros) or across everything (currently unsupported). Reimplemented in PLearn::RowMapSparseValueMatrix< T >. Definition at line 526 of file RowMapSparseMatrix.h. |
|
this is equivalent to setting all values to "0" (the default value of T)
Definition at line 127 of file RowMapSparseMatrix.h. Referenced by PLearn::RowMapSparseMatrix< real >::resize(), and PLearn::RowMapSparseMatrix< real >::transpose(). |
|
Definition at line 133 of file RowMapSparseMatrix.h. |
|
Compute the matrix density, that is : number_of_nonzero_elements / (length*width).
Definition at line 793 of file RowMapSparseMatrix.h. |
|
set d[i] = A[i,i]
Definition at line 383 of file RowMapSparseMatrix.h. |
|
d = diagonal(A*A'), i.e. d[i] = |A[i]|^2 where A[i] is i-th row Definition at line 392 of file RowMapSparseMatrix.h. |
|
return dot product of j-th column with vector v
Definition at line 426 of file RowMapSparseMatrix.h. |
|
return dot product of i-th row with vector v
Definition at line 408 of file RowMapSparseMatrix.h. |
|
This is not a "true" euclidian distance Reimplemented in PLearn::RowMapSparseValueMatrix< T >. Definition at line 651 of file RowMapSparseMatrix.h. |
|
Export as matlab readable [i, j , v] format to file <out> Matlab : (1) load <out> (2) A = spconvert(out) (note: the file extension must be '.dat') Add the bottom right corner, to make sure that the sparse matrix has the right dimensions Definition at line 763 of file RowMapSparseMatrix.h. Referenced by PLearn::MatlabInterface::eigs_r11(), and PLearn::matlabR11eigs(). |
|
if A(i,j) is specified and not A(j,i) then set A(j,i)=A(i,j). if both were specified but different, up to the tolerance (in abs. value difference), then abort the operation and return false (there is a problem!). Otherwise return true. see if entry i exists in row j not found, then set A(j,i) to A(i,j) check if they are equal Definition at line 354 of file RowMapSparseMatrix.h. |
|
Return the last non-zero position of a sparse vector (used for sparse operations that need to know the "end" of a vector).
Definition at line 750 of file RowMapSparseMatrix.h. |
|
Definition at line 329 of file RowMapSparseMatrix.h. |
|
|
determines automatically whether file is binary or ascii
Definition at line 193 of file RowMapSparseMatrix.h. |
|
Sparse vectors mutliplication.
Definition at line 608 of file RowMapSparseMatrix.h. |
|
multiply each (non-zero) element
Definition at line 576 of file RowMapSparseMatrix.h. |
|
Get i-th row. Exemple to iterate on i-th row: map<int,T>& row_i = A(i); < note very important: row_i is a reference (&) map<int,T>::const_iterator it = row_i.begin(); map<int,T>::const_iterator end = row_i.end(); for (;it!=end;++it) { int j = it->first; T Aij = it->second; ... } Reimplemented in PLearn::RowMapSparseValueMatrix< T >. Definition at line 172 of file RowMapSparseMatrix.h. |
|
Reimplemented in PLearn::RowMapSparseValueMatrix< T >. Definition at line 147 of file RowMapSparseMatrix.h. |
|
Reimplemented in PLearn::RowMapSparseValueMatrix< T >. Definition at line 138 of file RowMapSparseMatrix.h. |
|
multiply a sparse matrix by a full vector and set resulting vector y = matrix * x
Definition at line 293 of file RowMapSparseMatrix.h. Referenced by PLearn::product(). |
|
Definition at line 194 of file RowMapSparseMatrix.h. |
|
THIS ALSO CLEARS THE MATRIX.
Definition at line 120 of file RowMapSparseMatrix.h. |
|
Definition at line 184 of file RowMapSparseMatrix.h. |
|
Definition at line 187 of file RowMapSparseMatrix.h. |
|
saves the non-zero elements in an ascii file with the following simple format: first line: <length> <width> <numbernonzero> subsequent lines: <row> <column> <value> Definition at line 277 of file RowMapSparseMatrix.h. |
|
NOTE THIS IS A BIT EXPENSIVE!
Definition at line 175 of file RowMapSparseMatrix.h. Referenced by PLearn::RowMapSparseMatrix< real >::density(), and PLearn::RowMapSparseMatrix< real >::saveNonZeroElements(). |
|
Vec dest[i] = map1[i] - map2[i].
Definition at line 704 of file RowMapSparseMatrix.h. |
|
average across rows on one hand, and in parallel average across columns (thus getting two averages). The boolean argument specifies whether the average is across the explicit elements (the non-zeros) or across everything (currently unsupported). Definition at line 563 of file RowMapSparseMatrix.h. |
|
Reimplemented in PLearn::RowMapSparseValueMatrix< T >. Definition at line 314 of file RowMapSparseMatrix.h. |
|
D = S'.
Definition at line 589 of file RowMapSparseMatrix.h. |
|
M = A' * A.
Definition at line 442 of file RowMapSparseMatrix.h. |
|
|
mode used to write depends on save_binary flag
Definition at line 237 of file RowMapSparseMatrix.h. |
|
Definition at line 73 of file RowMapSparseMatrix.h. |
|
Definition at line 71 of file RowMapSparseMatrix.h. |
|
Definition at line 76 of file RowMapSparseMatrix.h. |