template<typename OpType = DenseSymShiftSolve<double>>
class Spectra::SymEigsShiftSolver< OpType >
This class implements the eigen solver for real symmetric matrices using the shift-and-invert mode. The background information of the symmetric eigen solver is documented in the SymEigsSolver class. Here we focus on explaining the shift-and-invert mode.
The shift-and-invert mode is based on the following fact: If
and
are a pair of eigenvalue and eigenvector of matrix
, such that
, then for any
, we have
where
which indicates that
is an eigenpair of the matrix
.
Therefore, if we pass the matrix operation
(rather than
) to the eigen solver, then we would get the desired values of
, and
can also be easily obtained by noting that
.
The reason why we need this type of manipulation is that the algorithm of Spectra (and also ARPACK) is good at finding eigenvalues with large magnitude, but may fail in looking for eigenvalues that are close to zero. However, if we really need them, we can set
, find the largest eigenvalues of
, and then transform back to
, since in this case largest values of
implies smallest values of
.
To summarize, in the shift-and-invert mode, the selection rule will apply to
rather than
. So a selection rule of LARGEST_MAGN
combined with shift
will find eigenvalues of
that are closest to
. But note that the eigenvalues() method will always return the eigenvalues in the original problem (i.e., returning
rather than
), and eigenvectors are the same for both the original problem and the shifted-and-inverted problem.
- Template Parameters
-
Below is an example that illustrates the use of the shift-and-invert mode:
#include <Eigen/Core>
#include <iostream>
{
Eigen::MatrixXd
M = Eigen::MatrixXd::Zero(10, 10);
for (
int i = 0;
i <
M.rows();
i++)
eigs.init();
{
Eigen::VectorXd evalues = eigs.eigenvalues();
std::cout << "Eigenvalues found:\n" << evalues << std::endl;
}
return 0;
}
Also an example for user-supplied matrix shift-solve operation class:
#include <Eigen/Core>
#include <iostream>
class MyDiagonalTenShiftSolve
{
private:
double sigma_;
public:
int rows()
const {
return 10; }
int cols()
const {
return 10; }
void perform_op(double *x_in, double *y_out) const
{
{
y_out[
i] = x_in[
i] / (
i + 1 - sigma_);
}
}
};
{
MyDiagonalTenShiftSolve op;
eigs.init();
{
Eigen::VectorXd evalues = eigs.eigenvalues();
std::cout << "Eigenvalues found:\n" << evalues << std::endl;
}
return 0;
}
Definition at line 149 of file SymEigsShiftSolver.h.