C++ adaptive and header-only Lanczos algorithm library
Lambda Lanczos calculates the smallest or largest eigenvalue and the corresponding eigenvector of a symmetric (Hermitian) matrix.
The characteristic feature is the matrix-vector multiplication routine used in the Lanczos algorithm is adaptable:
#include <lambda_lanczos/lambda_lanczos.hpp>using lambda_lanczos::LambdaLanczos;/* Some include and using declarations are omitted */void sample() { const int n = 3; double matrix[n][n] = { {2.0, 1.0, 1.0}, {1.0, 2.0, 1.0}, {1.0, 1.0, 2.0} }; // Its eigenvalues are {4, 1, 1} /* Prepare matrix-vector multiplication routine used in Lanczos algorithm */ auto mv_mul = [&](const vector<double>& in, vector<double>& out) {for(int i = 0;i < n;i++) { for(int j = 0;j < n;j++) { out[i] += matrix[i][j]*in[j]; } } }; /* Execute Lanczos algorithm */ LambdaLanczos<double> engine(mv_mul, n, true, 1); // Find 1 maximum eigenvalue vector<double> eigenvalues; vector<vector<double>> eigenvectors; engine.run(eigenvalues, eigenvectors); //// If C++17 is available, the following notation does the same thing: // auto [eigenvalues, eigenvectors] = engine.run() /* Print result */ cout << "Eigenvalue: " << setprecision(16) << eigenvalues[0] << endl; cout << "Eigenvector:"; for(int i = 0; i < n; i++) { cout << eigenvectors[0][i] << " "; } cout << endl; }
This feature allows you to
easily combine Lambda Lanczos with existing matrix libraries (e.g. Eigen; see a sample code).
use a matrix whose elements are partially given, e.g. a sparse matrix whose non-zero elements are stored as a list of {row-index, column-index, value} tuples.
Lambda Lanczos provides the following two interfaces:
LambdaLanczos
class computes maximum (minimum) eigenvalues and
corresponding eigenvectors. Degenerate eigenvalues are taken into account.
This class aims problems that require one or a few eigenpairs
(e.g. low-energy excitation of a quantum system).
Exponentiator
class computes the following type of matrix-vector multiplication:
where
As an application, this class may be used for time evolution of a quantum many-body system:
and more sophisticated algorithms, such as TDVP and other tensor networks.
See here.
API reference
C++11 compatible environment
Lambda Lanczos itself does not depend on any libraries.
In order to run tests, Google Test is required.
Lambda Lanczos is a header-only library. So the installation step is as follows:
Clone or download the latest version from Github.
Place the include/lambda_lanczos
directory anywhere your project can find.
MIT
mrcdr