Largest eigenvalues (and corresponding eigenvectors) in C++

走远了吗. 提交于 2019-12-12 14:37:00

问题


What is the easiest and fastest way (with some library, of course) to compute k largest eigenvalues and eigenvectors for a large dense matrix in C++? I'm looking for an equivalent of MATLAB's eigs function; I've looked through Armadillo and Eigen but couldn't find one, and computing all eigenvalues takes forever in my case (I need top 10 eigenvectors for an approx. 30000x30000 dense non-symmetric real matrix).

Desperate, I've even tried to implement power iterations by myself with Armadillo's QR decomposition but ran into complex pairs of eigenvalues and gave up. :)


回答1:


AFAIK the problem of finding the first k eigenvalues of a generic matrix has no easy solution. The Matlab function eigs you mentioned is supposed to work with sparse matrices.

Matlab probably uses Arnoldi/Lanczos, you might try if it works decently in your case even if your matrix is not sparse. The reference package for Arnlodi is ARPACK which has a C++ interface.




回答2:


Did you tried https://github.com/yixuan/spectra ? It similar to ARPACK but with nice Eigen-like interface (it compatible with Eigen!)

I used it for 30kx30k matrices (PCA) and it was quite ok




回答3:


Eigen has an EigenValues module that works pretty well.. But, I've never used it on anything quite that large.



来源:https://stackoverflow.com/questions/24468537/largest-eigenvalues-and-corresponding-eigenvectors-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!