lambda-lanczos 2.0.0
|
Calculation engine for Lanczos algorithm. More...
#include <lambda_lanczos.hpp>
Public Member Functions | |
LambdaLanczos (std::function< void(const std::vector< T > &, std::vector< T > &)> mv_mul, size_t matrix_size, bool find_maximum, size_t num_eigs) | |
Constructs Lanczos calculation engine. More... | |
template<typename Iterable > | |
size_t | run_iteration (std::vector< real_t< T > > &eigvalues, std::vector< std::vector< T > > &eigvecs, size_t nroot, Iterable orthogonalizeTo) const |
Not documented (In most cases, run() is preferred). More... | |
void | run (std::vector< real_t< T > > &eigenvalues, std::vector< std::vector< T > > &eigenvectors) |
Executes Lanczos algorithm and stores the result into reference variables passed as arguments. More... | |
std::tuple< std::vector< real_t< T > >, std::vector< std::vector< T > > > | run () |
Executes Lanczos algorithm and return result as a tuple. More... | |
void | run (real_t< T > &eigenvalue, std::vector< T > &eigenvector) |
Executes Lanczos algorithm that calculate one eigenpair regardless of num_eigs . More... | |
const std::vector< size_t > & | getIterationCounts () const |
Returns the latest iteration counts. More... | |
Public Attributes | |
std::function< void(const std::vector< T > &in, std::vector< T > &out)> | mv_mul |
Matrix-vector multiplication routine. More... | |
std::function< void(std::vector< T > &vec)> | init_vector = VectorRandomInitializer<T>::init |
Function to initialize the initial Lanczos vector. More... | |
size_t | matrix_size |
Dimension of the matrix to be diagonalized. More... | |
size_t | max_iteration |
Iteration limit of Lanczos algorithm, set to matrix_size automatically. More... | |
real_t< T > | eps = std::numeric_limits<real_t<T>>::epsilon() * 1e3 |
Convergence threshold of Lanczos iteration. More... | |
bool | find_maximum |
true to calculate maximum eigenvalue, false to calculate minimum one. More... | |
size_t | num_eigs = 1 |
Number of eigenpairs to be calculated. More... | |
real_t< T > | eigenvalue_offset = 0.0 |
Shifts the eigenvalues of the given matrix A. More... | |
size_t | num_eigs_per_iteration = 5 |
(Not necessary to change) More... | |
size_t | initial_vector_size = 200 |
(Not necessary to change) More... | |
Private Types | |
template<typename n_type > | |
using | real_t = util::real_t< n_type > |
See util::real_t for details. More... | |
Private Attributes | |
std::vector< size_t > | iter_counts |
Iteration counts of the latest run. More... | |
Calculation engine for Lanczos algorithm.
|
private |
See util::real_t for details.
|
inline |
Constructs Lanczos calculation engine.
mv_mul | Matrix-vector multiplication routine. See mv_mul for details. |
matrix_size | The size of your matrix, i.e. if your matrix is n by n, matrix_size should be n. |
find_maximum | specifies which of the minimum or maximum eigenvalue to be calculated. |
num_eigs | specifies how many eigenpairs to be calculate, e.g., if find_maximum = true and num_eig = 3 , LambdaLanczos calculates 3 maximum eigenpairs. |
|
inline |
Returns the latest iteration counts.
|
inline |
Executes Lanczos algorithm and return result as a tuple.
This function provides C++17 multiple-value-return interface.
eigenvalues[k]
stores the k-th eigenvalue. eigenvectors[k][:]
stores the k-th eigenvector.
|
inline |
Executes Lanczos algorithm that calculate one eigenpair regardless of num_eigs
.
[out] | eigenvalue | Eigenvalue. |
[out] | eigenvector | Eigenvector. |
|
inline |
Executes Lanczos algorithm and stores the result into reference variables passed as arguments.
[out] | eigenvalues | Eigenvalues. eigenvalues[k] stores the k-th eigenvalue. |
[out] | eigenvectors | Eigenvectors. eigenvectors[k][:] stores the k-th eigenvector. |
|
inline |
Not documented (In most cases, run()
is preferred).
Lanczos algorithm and stores the result into reference variables passed as arguments.
real_t<T> lambda_lanczos::LambdaLanczos< T >::eigenvalue_offset = 0.0 |
Shifts the eigenvalues of the given matrix A.
The algorithm will calculate the eigenvalue of matrix (A+eigenvalue_offset
*E), here E is the identity matrix. The result eigenvalue from run()
will take this shifting into account, so you don't have to "reshift" the result with eigenvalue_offset
.
real_t<T> lambda_lanczos::LambdaLanczos< T >::eps = std::numeric_limits<real_t<T>>::epsilon() * 1e3 |
Convergence threshold of Lanczos iteration.
eps
= 1e-12 means that the eigenvalue will be calculated with 12 digits of precision.
Default value is system-dependent. On usual 64-bit systems:
type (including complex one) | size (system-dep.) | eps |
---|---|---|
float | 4 bytes | 1e-4 |
double | 8 bytes | 1e-12 |
long double | 16 bytes | 1e-19 |
bool lambda_lanczos::LambdaLanczos< T >::find_maximum |
true to calculate maximum eigenvalue, false to calculate minimum one.
std::function<void(std::vector<T>& vec)> lambda_lanczos::LambdaLanczos< T >::init_vector = VectorRandomInitializer<T>::init |
Function to initialize the initial Lanczos vector.
After this function called, the output vector will be normalized automatically. Default value is lambda_lanczos::VectorRandomInitializer::init.
size_t lambda_lanczos::LambdaLanczos< T >::initial_vector_size = 200 |
(Not necessary to change)
This variable specifies the initial reserved size of Lanczos vectors. Controlling this variable might affect reserving efficiency, but that would be very small compared to matrix-vector-multiplication cost.
|
private |
Iteration counts of the latest run.
size_t lambda_lanczos::LambdaLanczos< T >::matrix_size |
Dimension of the matrix to be diagonalized.
size_t lambda_lanczos::LambdaLanczos< T >::max_iteration |
Iteration limit of Lanczos algorithm, set to matrix_size
automatically.
std::function<void(const std::vector<T>& in, std::vector<T>& out)> lambda_lanczos::LambdaLanczos< T >::mv_mul |
Matrix-vector multiplication routine.
This must be a function to calculate A*in
and store the result into out
, where A
is the matrix to be diagonalized. You can assume the output vector out
has been initialized with zeros before the mv_mul
is called.
size_t lambda_lanczos::LambdaLanczos< T >::num_eigs = 1 |
Number of eigenpairs to be calculated.
size_t lambda_lanczos::LambdaLanczos< T >::num_eigs_per_iteration = 5 |
(Not necessary to change)
This variable specifies the number of eigenpairs to be calculated per Lanczos iteration. For example, when num_eigs == 20
and num_eigs_per_iteration == 5
, run()
will executes 4 Lanczos iterations.