Sparse eigenvalues ​​using eigen / sparse

Is there a clear and efficient way to find the eigenvalues ​​and eigenvectors of a real, symmetric, very large, even 10000x10000 sparse matrix in Eigen3 ? For dense matrices, there exists an eigenvalue solver, but it does not use the matrix property, for example. it is a symmetry. In addition, I do not want to keep the matrix in a dense state.

Or (alternatively) is there a better (+ better documented) library for this?

+5
source share
2 answers

Armadillo will do it with eigs_sym

Note that calculating all eigenvalues ​​is a very expensive operation, whatever you do, usually what is done is to find only the largest or smallest eigenvalues ​​(this is what this will do).

+4
source

For Eigen there is a library with the name of the Spectra . As described on his web page, Spectra is a redesign of the ARPACK library using the C ++ language.

Unlike Armadillo suggested in another answer , Spectra supports long double and any other real floating point type (e.g. boost::multiprecision::float128 ).

Here's a usage example (same as the version in the documentation, but adapted for experimenting with different types of floating point):

 #include <Eigen/Core> #include <SymEigsSolver.h> // Also includes <MatOp/DenseSymMatProd.h> #include <iostream> #include <limits> int main() { using Real=long double; using Matrix=Eigen::Matrix<Real, Eigen::Dynamic, Eigen::Dynamic>; // We are going to calculate the eigenvalues of M const auto A = Matrix::Random(10, 10); const Matrix M = A + A.transpose(); // Construct matrix operation object using the wrapper class DenseGenMatProd Spectra::DenseSymMatProd<Real> op(M); // Construct eigen solver object, requesting the largest three eigenvalues Spectra::SymEigsSolver<Real, Spectra::LARGEST_ALGE, Spectra::DenseSymMatProd<Real>> eigs(&op, 3, 6); // Initialize and compute eigs.init(); const auto nconv = eigs.compute(); std::cout << nconv << " eigenvalues converged.\n"; // Retrieve results if(eigs.info() == Spectra::SUCCESSFUL) { const auto evalues = eigs.eigenvalues(); std::cout.precision(std::numeric_limits<Real>::digits10); std::cout << "Eigenvalues found:\n" << evalues << '\n'; } } 
+2
source

All Articles