Public Member Functions | Private Types | List of all members
Spectra::SymEigsSolver< Scalar, SelectionRule, OpType > Class Template Reference

#include <SymEigsSolver.h>

Inheritance diagram for Spectra::SymEigsSolver< Scalar, SelectionRule, OpType >:
Inheritance graph
[legend]

Public Member Functions

 SymEigsSolver (OpType *op, Index nev, Index ncv)
 
- Public Member Functions inherited from Spectra::SymEigsBase< double, LARGEST_MAGN, DenseSymMatProd< double >, IdentityBOp >
Index compute (Index maxit=1000, double tol=1e-10, int sort_rule=LARGEST_ALGE)
 
Vector eigenvalues () const
 
virtual Matrix eigenvectors () const
 
virtual Matrix eigenvectors (Index nvec) const
 
int info () const
 
void init ()
 
void init (const double *init_resid)
 
Index num_iterations () const
 
Index num_operations () const
 

Private Types

typedef Eigen::Index Index
 

Additional Inherited Members

- Protected Member Functions inherited from Spectra::SymEigsBase< double, LARGEST_MAGN, DenseSymMatProd< double >, IdentityBOp >
virtual void sort_ritzpair (int sort_rule)
 
- Protected Attributes inherited from Spectra::SymEigsBase< double, LARGEST_MAGN, DenseSymMatProd< double >, IdentityBOp >
LanczosFac m_fac
 
const Index m_n
 
const Index m_ncv
 
const Index m_nev
 
Index m_niter
 
Index m_nmatop
 
DenseSymMatProd< double > * m_op
 
Vector m_ritz_val
 

Detailed Description

template<typename Scalar = double, int SelectionRule = LARGEST_MAGN, typename OpType = DenseSymMatProd<double>>
class Spectra::SymEigsSolver< Scalar, SelectionRule, OpType >

This class implements the eigen solver for real symmetric matrices, i.e., to solve $Ax=\lambda x$ where $A$ is symmetric.

Spectra is designed to calculate a specified number ( $k$) of eigenvalues of a large square matrix ( $A$). Usually $k$ is much less than the size of the matrix ( $n$), so that only a few eigenvalues and eigenvectors are computed.

Rather than providing the whole $A$ matrix, the algorithm only requires the matrix-vector multiplication operation of $A$. Therefore, users of this solver need to supply a class that computes the result of $Av$ for any given vector $v$. The name of this class should be given to the template parameter OpType, and instance of this class passed to the constructor of SymEigsSolver.

If the matrix $A$ is already stored as a matrix object in Eigen, for example Eigen::MatrixXd, then there is an easy way to construct such matrix operation class, by using the built-in wrapper class DenseSymMatProd which wraps an existing matrix object in Eigen. This is also the default template parameter for SymEigsSolver. For sparse matrices, the wrapper class SparseSymMatProd can be used similarly.

If the users need to define their own matrix-vector multiplication operation class, it should implement all the public member functions as in DenseSymMatProd.

Template Parameters
ScalarThe element type of the matrix. Currently supported types are float, double and long double.
SelectionRuleAn enumeration value indicating the selection rule of the requested eigenvalues, for example LARGEST_MAGN to retrieve eigenvalues with the largest magnitude. The full list of enumeration values can be found in Enumerations.
OpTypeThe name of the matrix operation class. 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.

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

#include <Eigen/Core>
// <Spectra/MatOp/DenseSymMatProd.h> is implicitly included
#include <iostream>
using namespace Spectra;
int main()
{
// We are going to calculate the eigenvalues of M
Eigen::MatrixXd A = Eigen::MatrixXd::Random(10, 10);
Eigen::MatrixXd M = A + A.transpose();
// Construct matrix operation object using the wrapper class DenseSymMatProd
// Construct eigen solver object, requesting the largest three eigenvalues
// Initialize and compute
eigs.init();
int nconv = eigs.compute();
// Retrieve results
Eigen::VectorXd evalues;
if(eigs.info() == SUCCESSFUL)
evalues = eigs.eigenvalues();
std::cout << "Eigenvalues found:\n" << evalues << std::endl;
return 0;
}

And here is an example for user-supplied matrix operation class.

#include <Eigen/Core>
#include <iostream>
using namespace Spectra;
// M = diag(1, 2, ..., 10)
class MyDiagonalTen
{
public:
int rows() { return 10; }
int cols() { return 10; }
// y_out = M * x_in
void perform_op(double *x_in, double *y_out)
{
for(int i = 0; i < rows(); i++)
{
y_out[i] = x_in[i] * (i + 1);
}
}
};
int main()
{
MyDiagonalTen op;
eigs.init();
eigs.compute();
if(eigs.info() == SUCCESSFUL)
{
Eigen::VectorXd evalues = eigs.eigenvalues();
// Will get (10, 9, 8)
std::cout << "Eigenvalues found:\n" << evalues << std::endl;
}
return 0;
}

Definition at line 141 of file SymEigsSolver.h.

Member Typedef Documentation

◆ Index

template<typename Scalar = double, int SelectionRule = LARGEST_MAGN, typename OpType = DenseSymMatProd<double>>
typedef Eigen::Index Spectra::SymEigsSolver< Scalar, SelectionRule, OpType >::Index
private

Definition at line 144 of file SymEigsSolver.h.

Constructor & Destructor Documentation

◆ SymEigsSolver()

template<typename Scalar = double, int SelectionRule = LARGEST_MAGN, typename OpType = DenseSymMatProd<double>>
Spectra::SymEigsSolver< Scalar, SelectionRule, OpType >::SymEigsSolver ( OpType *  op,
Index  nev,
Index  ncv 
)
inline

Constructor to create a solver object.

Parameters
opPointer to the matrix operation object, which should implement the matrix-vector multiplication operation of $A$: calculating $Av$ for any vector $v$. Users could either create the object from the wrapper class such as DenseSymMatProd, or define their own that implements all the public member functions as in DenseSymMatProd.
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$.

Definition at line 164 of file SymEigsSolver.h.


The documentation for this class was generated from the following file:
Spectra::SymEigsSolver
Definition: SymEigsSolver.h:141
Spectra::DenseSymMatProd< double >
rows
int rows
Definition: Tutorial_commainit_02.cpp:1
main
int main(int argc, char **argv)
Definition: cmake/example_cmake_find_gtsam/main.cpp:63
A
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:48
SymEigsSolver.h
Spectra
Definition: LOBPCGSolver.h:19
Spectra::SUCCESSFUL
@ SUCCESSFUL
Computation was successful.
Definition: CompInfo.h:19
cols
int cols
Definition: Tutorial_commainit_02.cpp:1
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
M
Matrix< RealScalar, Dynamic, Dynamic > M
Definition: bench_gemm.cpp:51


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:16:52