lambda-lanczos 2.0.0
Loading...
Searching...
No Matches
lambda_lanczos::LambdaLanczos< T > Class Template Reference

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...
 

Detailed Description

template<typename T>
class lambda_lanczos::LambdaLanczos< T >

Calculation engine for Lanczos algorithm.

Member Typedef Documentation

◆ real_t

template<typename T >
template<typename n_type >
using lambda_lanczos::LambdaLanczos< T >::real_t = util::real_t<n_type>
private

See util::real_t for details.

Constructor & Destructor Documentation

◆ LambdaLanczos()

template<typename T >
lambda_lanczos::LambdaLanczos< T >::LambdaLanczos ( std::function< void(const std::vector< T > &, std::vector< T > &)>  mv_mul,
size_t  matrix_size,
bool  find_maximum,
size_t  num_eigs 
)
inline

Constructs Lanczos calculation engine.

Parameters
mv_mulMatrix-vector multiplication routine. See mv_mul for details.
matrix_sizeThe size of your matrix, i.e. if your matrix is n by n, matrix_size should be n.
find_maximumspecifies which of the minimum or maximum eigenvalue to be calculated.
num_eigsspecifies how many eigenpairs to be calculate, e.g., if find_maximum = true and num_eig = 3, LambdaLanczos calculates 3 maximum eigenpairs.

Member Function Documentation

◆ getIterationCounts()

template<typename T >
const std::vector< size_t > & lambda_lanczos::LambdaLanczos< T >::getIterationCounts ( ) const
inline

Returns the latest iteration counts.

◆ run() [1/3]

template<typename T >
std::tuple< std::vector< real_t< T > >, std::vector< std::vector< T > > > lambda_lanczos::LambdaLanczos< T >::run ( )
inline

Executes Lanczos algorithm and return result as a tuple.

This function provides C++17 multiple-value-return interface.

Returns
Eigenvalues. eigenvalues[k] stores the k-th eigenvalue.
Eigenvectors. eigenvectors[k][:] stores the k-th eigenvector.

◆ run() [2/3]

template<typename T >
void lambda_lanczos::LambdaLanczos< T >::run ( real_t< T > &  eigenvalue,
std::vector< T > &  eigenvector 
)
inline

Executes Lanczos algorithm that calculate one eigenpair regardless of num_eigs.

Parameters
[out]eigenvalueEigenvalue.
[out]eigenvectorEigenvector.

◆ run() [3/3]

template<typename T >
void lambda_lanczos::LambdaLanczos< T >::run ( std::vector< real_t< T > > &  eigenvalues,
std::vector< std::vector< T > > &  eigenvectors 
)
inline

Executes Lanczos algorithm and stores the result into reference variables passed as arguments.

Parameters
[out]eigenvaluesEigenvalues. eigenvalues[k] stores the k-th eigenvalue.
[out]eigenvectorsEigenvectors. eigenvectors[k][:] stores the k-th eigenvector.

◆ run_iteration()

template<typename T >
template<typename Iterable >
size_t lambda_lanczos::LambdaLanczos< T >::run_iteration ( std::vector< real_t< T > > &  eigvalues,
std::vector< std::vector< T > > &  eigvecs,
size_t  nroot,
Iterable  orthogonalizeTo 
) const
inline

Not documented (In most cases, run() is preferred).

Lanczos algorithm and stores the result into reference variables passed as arguments.

Returns
Lanczos-iteration count

Member Data Documentation

◆ eigenvalue_offset

template<typename T >
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.

◆ eps

template<typename T >
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

◆ find_maximum

template<typename T >
bool lambda_lanczos::LambdaLanczos< T >::find_maximum

true to calculate maximum eigenvalue, false to calculate minimum one.

◆ init_vector

template<typename T >
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.

◆ initial_vector_size

template<typename T >
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.

◆ iter_counts

template<typename T >
std::vector<size_t> lambda_lanczos::LambdaLanczos< T >::iter_counts
private

Iteration counts of the latest run.

◆ matrix_size

template<typename T >
size_t lambda_lanczos::LambdaLanczos< T >::matrix_size

Dimension of the matrix to be diagonalized.

◆ max_iteration

template<typename T >
size_t lambda_lanczos::LambdaLanczos< T >::max_iteration

Iteration limit of Lanczos algorithm, set to matrix_size automatically.

◆ mv_mul

template<typename T >
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.

◆ num_eigs

template<typename T >
size_t lambda_lanczos::LambdaLanczos< T >::num_eigs = 1

Number of eigenpairs to be calculated.

◆ num_eigs_per_iteration

template<typename T >
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.


The documentation for this class was generated from the following file: