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

eigenvalues of a positive semidefinite matrix

Tags: None
(comma "," separated)
iljah
Registered Member
Posts
4
Karma
0
Hi,

i'm using Eigen to calculate eigenvalues of matrices. Currently i use the SelfAdjoinEigenSolver<MatrixXd>. Is there a faster way if the matrix is positive semidefinite and symmetric?

Regards,
iljah
User avatar
bjacob
Registered Member
Posts
658
Karma
3
Yes. Being selfadjoint is what matters, being positive doesn't help any further with eigenvalues computation.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
iljah
Registered Member
Posts
4
Karma
0
But if selfadjoint is what matters, why is your answer yes? I use the SelfAdjoinEigenSolver<MatrixXd> already.

Is there a better way than below, if the the matrix hold these conditions? Calculating on a 4000x4000 took up to 1 hour on my PC.

Code: Select all
Eigen::MatrixXd M = ...;
Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> solver(M, false);
Eigen::VectorXd vec = solver.eigenvalues();

Regards,
Iljah
User avatar
bjacob
Registered Member
Posts
658
Karma
3
When you use SelfAdjoinEigenSolver<MatrixXd> you are already telling Eigen to assume the matrix is selfadjoint. There's nothing more you can do to help Eigen.

Your code looks good.

There are two possible reasons why it took 1 hour.
1) have you correctly enabled optimization? Like -O2 -msse2.
2) This is a really huge size so cache-friendliness is crucial. In the case of this algorithm, cache-friendliness means block housholder transforms, which we don't do at the moment. So indeed there's no chance that we might have good performance right now on such sizes, for eigensolving. This is on the TODO, probably for Eigen 3.1.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
iljah
Registered Member
Posts
4
Karma
0
Ok the optimizations may cause this. I've never heared about them :-/ . Is there an article/doc/ref where I can find out what options (like -O2) are needed?

Thanks a lot,
Iljah
User avatar
bjacob
Registered Member
Posts
658
Karma
3
Every major compiler is able to do optimizations. Eigen relies heavily on that ability. I dont even know what compiler you are using. If it's MS visual studio, just select the 'release' mode in your project settings, and optionally enable SSE2. If you're using GCC, pass -O2 -DNDEBUG, and optionally -msse2 if you want to enable SSE2 instructions. See: http://eigen.tuxfamily.org/index.php?ti ... er_support


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
For your information it takes here 37 seconds to compute for a 4k^2 and floats, so ~1mn for double.

Make sure you compile with -O2 and -DNDEBUG.
iljah
Registered Member
Posts
4
Karma
0
Sorry for the late response. Your tip works great.

Is there a significant difference between -O2 and -O3?

Regards,
Iljah


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]