Spectra
1.0.1
Header-only C++ Library for Large Scale Eigenvalue Problems
|
Spectra stands for Sparse Eigenvalue Computation Toolkit as a Redesigned ARPACK. It is a C++ library for large scale eigenvalue problems, built on top of Eigen, an open source linear algebra library.
Spectra is implemented as a header-only C++ library, whose only dependency, Eigen, is also header-only. Hence Spectra can be easily embedded in C++ projects that require calculating eigenvalues of large matrices.
The development page of Spectra is at https://github.com/yixuan/spectra/.
ARPACK is a software written in FORTRAN for solving large scale eigenvalue problems. The development of Spectra is much inspired by ARPACK, and as the whole name indicates, Spectra is a redesign of the ARPACK library using the C++ language.
In fact, Spectra is based on the algorithm described in the ARPACK Users' Guide, the implicitly restarted Arnoldi/Lanczos method. However, it does not use the ARPACK code, and it is NOT a clone of ARPACK for C++. In short, Spectra implements the major algorithms in ARPACK, but Spectra provides a completely different interface, and it does not depend on ARPACK.
Spectra is designed to calculate a specified number ( \(k\)) of eigenvalues of a large square matrix ( \(A\)). Usually \(k\) is much smaller than the size of matrix ( \(n\)), so that only a few eigenvalues and eigenvectors are computed, which in general is more efficient than calculating the whole spectral decomposition. Users can choose eigenvalue selection rules to pick the eigenvalues of interest, such as the largest \(k\) eigenvalues, or eigenvalues with largest real parts, etc.
To use the eigen solvers in this library, the user does not need to directly provide the whole matrix, but instead, the algorithm only requires certain operations defined on \(A\). In the basic setting, it is simply the matrix-vector multiplication. Therefore, if the matrix-vector product \(Ax\) can be computed efficiently, which is the case when \(A\) is sparse, Spectra will be very powerful for large scale eigenvalue problems.
There are two major steps to use the Spectra library:
Below is a list of the available eigen solvers in Spectra:
Below is an example that demonstrates the use of the eigen solver for symmetric matrices.
Sparse matrix is supported via classes such as Spectra::SparseGenMatProd and Spectra::SparseSymMatProd.
And here is an example for user-supplied matrix operation class.
When it is needed to find eigenvalues that are closest to a number \(\sigma\), for example to find the smallest eigenvalues of a positive definite matrix (in which case \(\sigma=0\)), it is advised to use the shift-and-invert mode of eigen solvers.
In the shift-and-invert mode, selection rules are applied to \(1/(\lambda-\sigma)\) rather than \(\lambda\), where \(\lambda\) are eigenvalues of \(A\). To use this mode, users need to define the shift-solve matrix operation. See the documentation of Spectra::SymEigsShiftSolver for details.
Spectra is an open source project licensed under MPL2, the same license used by Eigen.