Spectra  1.0.1
Header-only C++ Library for Large Scale Eigenvalue Problems
Spectra::SymGEigsShiftSolver< OpType, BOpType, GEigsMode::ShiftInvert > Class Template Reference

#include <Spectra/SymGEigsShiftSolver.h>

Inheritance diagram for Spectra::SymGEigsShiftSolver< OpType, BOpType, GEigsMode::ShiftInvert >:
Spectra::SymEigsBase< SymGEigsShiftInvertOp< OpType, BOpType >, BOpType >

Public Member Functions

 SymGEigsShiftSolver (OpType &op, BOpType &Bop, Index nev, Index ncv, const Scalar &sigma)
 
- Public Member Functions inherited from Spectra::SymEigsBase< SymGEigsShiftInvertOp< OpType, BOpType >, BOpType >
void init (const Scalar *init_resid)
 
void init ()
 
Index compute (SortRule selection=SortRule::LargestMagn, Index maxit=1000, Scalar tol=1e-10, SortRule sorting=SortRule::LargestAlge)
 
CompInfo info () const
 
Index num_iterations () const
 
Index num_operations () const
 
Vector eigenvalues () const
 
virtual Matrix eigenvectors (Index nvec) const
 
virtual Matrix eigenvectors () const
 

Detailed Description

template<typename OpType, typename BOpType>
class Spectra::SymGEigsShiftSolver< OpType, BOpType, GEigsMode::ShiftInvert >

This class implements the generalized eigen solver for real symmetric matrices using the shift-and-invert spectral transformation. The original problem is to solve \(Ax=\lambda Bx\), where \(A\) is symmetric and \(B\) is positive definite. The transformed problem is \((A-\sigma B)^{-1}Bx=\nu x\), where \(\nu=1/(\lambda-\sigma)\), and \(\sigma\) is a user-specified shift.

This solver requires two matrix operation objects: one to compute \(y=(A-\sigma B)^{-1}x\) for any vector \(v\), and one for the matrix multiplication \(Bv\).

If \(A\) and \(B\) are stored as Eigen matrices, then the first operation object can be created using the SymShiftInvert class, and the second one can be created using the DenseSymMatProd or SparseSymMatProd classes. If the users need to define their own operation classes, then they should implement all the public member functions as in those built-in classes.

Template Parameters
OpTypeThe type of the first operation object. Users could either use the wrapper class SymShiftInvert, or define their own that implements the type definition Scalar and all the public member functions as in SymShiftInvert.
BOpTypeThe name of the matrix operation class for \(B\). Users could either use the wrapper classes such as DenseSymMatProd and SparseSymMatProd, or define their own that implements all the public member functions as in DenseSymMatProd.
ModeMode of the generalized eigen solver. In this solver it is Spectra::GEigsMode::ShiftInvert.

Below is an example that demonstrates the usage of this class.

#include <Eigen/Core>
#include <Eigen/SparseCore>
#include <Spectra/SymGEigsShiftSolver.h>
#include <Spectra/MatOp/SymShiftInvert.h>
#include <Spectra/MatOp/SparseSymMatProd.h>
#include <iostream>
using namespace Spectra;
int main()
{
// We are going to solve the generalized eigenvalue problem
// A * x = lambda * B * x,
// where A is symmetric and B is positive definite
const int n = 100;
// Define the A matrix
Eigen::MatrixXd M = Eigen::MatrixXd::Random(n, n);
Eigen::MatrixXd A = M + M.transpose();
// Define the B matrix, a tridiagonal matrix with 2 on the diagonal
// and 1 on the subdiagonals
Eigen::SparseMatrix<double> B(n, n);
B.reserve(Eigen::VectorXi::Constant(n, 3));
for (int i = 0; i < n; i++)
{
B.insert(i, i) = 2.0;
if (i > 0)
B.insert(i - 1, i) = 1.0;
if (i < n - 1)
B.insert(i + 1, i) = 1.0;
}
// Construct matrix operation objects using the wrapper classes
// A is dense, B is sparse
using OpType = SymShiftInvert<double, Eigen::Dense, Eigen::Sparse>;
using BOpType = SparseSymMatProd<double>;
OpType op(A, B);
BOpType Bop(B);
// Construct generalized eigen solver object, seeking three generalized
// eigenvalues that are closest to zero. This is equivalent to specifying
// a shift sigma = 0.0 combined with the SortRule::LargestMagn selection rule
SymGEigsShiftSolver<OpType, BOpType, GEigsMode::ShiftInvert>
geigs(op, Bop, 3, 6, 0.0);
// Initialize and compute
geigs.init();
int nconv = geigs.compute(SortRule::LargestMagn);
// Retrieve results
Eigen::VectorXd evalues;
Eigen::MatrixXd evecs;
if (geigs.info() == CompInfo::Successful)
{
evalues = geigs.eigenvalues();
evecs = geigs.eigenvectors();
}
std::cout << "Number of converged generalized eigenvalues: " << nconv << std::endl;
std::cout << "Generalized eigenvalues found:\n" << evalues << std::endl;
std::cout << "Generalized eigenvectors found:\n" << evecs.topRows(10) << std::endl;
return 0;
}
@ Successful
Computation was successful.

Definition at line 147 of file SymGEigsShiftSolver.h.

Constructor & Destructor Documentation

◆ SymGEigsShiftSolver()

template<typename OpType , typename BOpType >
Spectra::SymGEigsShiftSolver< OpType, BOpType, GEigsMode::ShiftInvert >::SymGEigsShiftSolver ( OpType &  op,
BOpType &  Bop,
Index  nev,
Index  ncv,
const Scalar &  sigma 
)
inline

Constructor to create a solver object.

Parameters
opThe matrix operation object that computes \(y=(A-\sigma B)^{-1}v\) for any vector \(v\). Users could either create the object from the wrapper class SymShiftInvert, or define their own that implements all the public members as in SymShiftInvert.
BopThe \(B\) matrix operation object that implements the matrix-vector multiplication \(Bv\). Users could either create the object from the wrapper classes such as DenseSymMatProd and SparseSymMatProd, or define their own that implements all the public member functions as in DenseSymMatProd. \(B\) needs to be positive definite.
nevNumber of eigenvalues requested. This should satisfy \(1\le nev \le n-1\), where \(n\) is the size of matrix.
ncvParameter that controls the convergence speed of the algorithm. Typically a larger ncv means faster convergence, but it may also result in greater memory use and more matrix operations in each iteration. This parameter must satisfy \(nev < ncv \le n\), and is advised to take \(ncv \ge 2\cdot nev\).
sigmaThe value of the shift.

Definition at line 200 of file SymGEigsShiftSolver.h.


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