This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Eigen3: Eigensolver for sparse matrix?

Tags: None
(comma "," separated)
ben0104
Registered Member
Posts
3
Karma
0
Hi all,
I'm looking for a sparse eigen solver. I installed Eigen3 and created a sparse matrix and now I'm trying to use some of the eigensolvers for my matrix. But I think Eigen3 can still not handle to calculate eigenvalues and eigenvectors for a sparse matrix, am I right?
Which sparse eigen solver in C++ would you suggest to me or do you know how to get the eigenvalues and eigenvectors with Eigen?
Thank's for your help!
Ann
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
ben0104
Registered Member
Posts
3
Karma
0
I don't have python on my windows computer, so I can't compile redsvd.
I can find no good explanation how to enter the values of a sparse matrix. With the redsvdTest.cpp in the sparse example, I can't understand how the function REDSVD::SMatrixXf works...
const int row = 10;
const int col = 10;
REDSVD::SMatrixXf A(row, col);
REDSVD::RedSVD svdOfA(A);

MatrixXf newA = svdOfA.matrixU() * svdOfA.singularValues().asDiagonal() * svdOfA.matrixV().transpose();

Is there any other possibility to find an eigensolver for sparse matrixes? I would just need three eigenvalues and vectors next to the value 0.
mattd
Registered Member
Posts
28
Karma
0
ben,

I don't use redsvd, but to answer a part of your question -- "SMatrixXf" is just a type alias:
typedef Eigen::SparseMatrix<float, Eigen::RowMajor> SMatrixXf;
so you don't have to type "Eigen::SparseMatrix<float, Eigen::RowMajor>" all the time, but be able to use the shorter synonym "SMatrixXf" instead.

// In case you don't know what "typedef" is: http://www.cplusplus.com/doc/tutorial/other_data_types/

So, this line:
REDSVD::SMatrixXf A(row, col);
constructs a sparse matrix "A" of type "SMatrixXf" (recall, type "SMatrixXf" is just an alias for "Eigen::SparseMatrix<float, Eigen::RowMajor>"), which has "row" rows and "col" columns.

The next line:
REDSVD::RedSVD svdOfA(A);
constructs an object "svdOfA" containing the singular value decomposition (SVD) of the previously-defined sparse matrix "A".
You can access all the components of the SVD by calling the appropriate member-functions of this object: "matrixU", "singularValues", and "matrixV" -- just as illustrated in the line computing "newA".

Since you're interested in the eigendecomposition, class "RedSymEigen" in the example below might of more use to you:
http://code.google.com/p/redsvd/source/ ... redsvd.hpp
http://code.google.com/p/redsvd/source/ ... redsvd.cpp

Notice, how it's used in the sparse case:
REDSVD::fileProcess<REDSVD::SMatrixXf, REDSVD::RedSymEigen>(input, output, rank);
http://code.google.com/p/redsvd/source/ ... vdMain.cpp
ben0104
Registered Member
Posts
3
Karma
0
All that sounds quite good, but I still can't compile redsvd. I guess I need an Mingw-python combinition on my windows computer, but this seems to be more difficult then expected...

Do you have maybe any suggestions what I could try to get this fixed?

Best, Ann
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
it seems there are only two relevant files: redsvd.hpp and redsvd.cpp, so simply import them in your project...
updogliu
Registered Member
Posts
13
Karma
0
OS
It seems that the code of RedSVD is quite short based on Eigen. Why doesn't Eigen develop a similar function for sparse matrix? It looks like only a one-week job for an experienced Eigen developer. SVD for sparse matrix is very common and useful.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
yes, integrating redSVD into Eigen is not difficult at all. The problem is that after some experiments by myself and others, this randomized algorithm is only usable in some very specific cases. In most cases, the results are very approximate.
ronakagrawal
Registered Member
Posts
5
Karma
0
ggael wrote:yes, integrating redSVD into Eigen is not difficult at all. The problem is that after some experiments by myself and others, this randomized algorithm is only usable in some very specific cases. In most cases, the results are very approximate.


Can you elaborate about those specific cases in sparse matrix.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
All the details are here: http://arxiv.org/pdf/0909.4061.pdf


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]