Eigen::GeneralizedSelfAdjointEigenSolver< MatrixType_ > Class Template Reference

Computes eigenvalues and eigenvectors of the generalized selfadjoint eigen problem. More...

#include <GeneralizedSelfAdjointEigenSolver.h>

+ Inheritance diagram for Eigen::GeneralizedSelfAdjointEigenSolver< MatrixType_ >:

Public Types

typedef MatrixType_ MatrixType
 
- Public Types inherited from Eigen::SelfAdjointEigenSolver< MatrixType_ >
enum  { Size = MatrixType::RowsAtCompileTime , ColsAtCompileTime = MatrixType::ColsAtCompileTime , Options = internal::traits<MatrixType>::Options , MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime }
 
typedef MatrixType_ MatrixType
 
typedef MatrixType::Scalar Scalar
 Scalar type for matrices of type MatrixType_. More...
 
typedef Eigen::Index Index
 
typedef Matrix< Scalar, Size, Size, ColMajor, MaxColsAtCompileTime, MaxColsAtCompileTimeEigenvectorsType
 
typedef NumTraits< Scalar >::Real RealScalar
 Real scalar type for MatrixType_. More...
 
typedef internal::plain_col_type< MatrixType, Scalar >::type VectorType
 Type for vector of eigenvalues as returned by eigenvalues(). More...
 
typedef internal::plain_col_type< MatrixType, RealScalar >::type RealVectorType
 
typedef Tridiagonalization< MatrixTypeTridiagonalizationType
 
typedef TridiagonalizationType::SubDiagonalType SubDiagonalType
 

Public Member Functions

 GeneralizedSelfAdjointEigenSolver ()
 Default constructor for fixed-size matrices. More...
 
 GeneralizedSelfAdjointEigenSolver (Index size)
 Constructor, pre-allocates memory for dynamic-size matrices. More...
 
 GeneralizedSelfAdjointEigenSolver (const MatrixType &matA, const MatrixType &matB, int options=ComputeEigenvectors|Ax_lBx)
 Constructor; computes generalized eigendecomposition of given matrix pencil. More...
 
GeneralizedSelfAdjointEigenSolvercompute (const MatrixType &matA, const MatrixType &matB, int options=ComputeEigenvectors|Ax_lBx)
 Computes generalized eigendecomposition of given matrix pencil. More...
 
- Public Member Functions inherited from Eigen::SelfAdjointEigenSolver< MatrixType_ >
EIGEN_DEVICE_FUNC SelfAdjointEigenSolver ()
 Default constructor for fixed-size matrices. More...
 
EIGEN_DEVICE_FUNC SelfAdjointEigenSolver (Index size)
 Constructor, pre-allocates memory for dynamic-size matrices. More...
 
template<typename InputType >
EIGEN_DEVICE_FUNC SelfAdjointEigenSolver (const EigenBase< InputType > &matrix, int options=ComputeEigenvectors)
 Constructor; computes eigendecomposition of given matrix. More...
 
template<typename InputType >
EIGEN_DEVICE_FUNC SelfAdjointEigenSolvercompute (const EigenBase< InputType > &matrix, int options=ComputeEigenvectors)
 Computes eigendecomposition of given matrix. More...
 
EIGEN_DEVICE_FUNC SelfAdjointEigenSolvercomputeDirect (const MatrixType &matrix, int options=ComputeEigenvectors)
 Computes eigendecomposition of given matrix using a closed-form algorithm. More...
 
SelfAdjointEigenSolvercomputeFromTridiagonal (const RealVectorType &diag, const SubDiagonalType &subdiag, int options=ComputeEigenvectors)
 Computes the eigen decomposition from a tridiagonal symmetric matrix. More...
 
EIGEN_DEVICE_FUNC const EigenvectorsTypeeigenvectors () const
 Returns the eigenvectors of given matrix. More...
 
EIGEN_DEVICE_FUNC const RealVectorTypeeigenvalues () const
 Returns the eigenvalues of given matrix. More...
 
EIGEN_DEVICE_FUNC MatrixType operatorSqrt () const
 Computes the positive-definite square root of the matrix. More...
 
EIGEN_DEVICE_FUNC MatrixType operatorInverseSqrt () const
 Computes the inverse square root of the matrix. More...
 
EIGEN_DEVICE_FUNC ComputationInfo info () const
 Reports whether previous computation was successful. More...
 
template<typename InputType >
EIGEN_DEVICE_FUNC SelfAdjointEigenSolver< MatrixType > & compute (const EigenBase< InputType > &a_matrix, int options)
 

Private Types

typedef SelfAdjointEigenSolver< MatrixType_ > Base
 

Additional Inherited Members

- Static Public Attributes inherited from Eigen::SelfAdjointEigenSolver< MatrixType_ >
static const int m_maxIterations = 30
 Maximum number of iterations. More...
 
- Protected Attributes inherited from Eigen::SelfAdjointEigenSolver< MatrixType_ >
EigenvectorsType m_eivec
 
VectorType m_workspace
 
RealVectorType m_eivalues
 
TridiagonalizationType::SubDiagonalType m_subdiag
 
TridiagonalizationType::CoeffVectorType m_hcoeffs
 
ComputationInfo m_info
 
bool m_isInitialized
 
bool m_eigenvectorsOk
 

Detailed Description

template<typename MatrixType_>
class Eigen::GeneralizedSelfAdjointEigenSolver< MatrixType_ >

Computes eigenvalues and eigenvectors of the generalized selfadjoint eigen problem.

\eigenvalues_module

Template Parameters
MatrixType_the type of the matrix of which we are computing the eigendecomposition; this is expected to be an instantiation of the Matrix class template.

This class solves the generalized eigenvalue problem \( Av = \lambda Bv \). In this case, the matrix \( A \) should be selfadjoint and the matrix \( B \) should be positive definite.

Only the lower triangular part of the input matrix is referenced.

Call the function compute() to compute the eigenvalues and eigenvectors of a given matrix. Alternatively, you can use the GeneralizedSelfAdjointEigenSolver(const MatrixType&, const MatrixType&, int) constructor which computes the eigenvalues and eigenvectors at construction time. Once the eigenvalue and eigenvectors are computed, they can be retrieved with the eigenvalues() and eigenvectors() functions.

The documentation for GeneralizedSelfAdjointEigenSolver(const MatrixType&, const MatrixType&, int) contains an example of the typical use of this class.

See also
class SelfAdjointEigenSolver, class EigenSolver, class ComplexEigenSolver

Member Typedef Documentation

◆ Base

template<typename MatrixType_ >
typedef SelfAdjointEigenSolver<MatrixType_> Eigen::GeneralizedSelfAdjointEigenSolver< MatrixType_ >::Base
private

◆ MatrixType

template<typename MatrixType_ >
typedef MatrixType_ Eigen::GeneralizedSelfAdjointEigenSolver< MatrixType_ >::MatrixType

Constructor & Destructor Documentation

◆ GeneralizedSelfAdjointEigenSolver() [1/3]

template<typename MatrixType_ >
Eigen::GeneralizedSelfAdjointEigenSolver< MatrixType_ >::GeneralizedSelfAdjointEigenSolver ( )
inline

Default constructor for fixed-size matrices.

The default constructor is useful in cases in which the user intends to perform decompositions via compute(). This constructor can only be used if MatrixType_ is a fixed-size matrix; use GeneralizedSelfAdjointEigenSolver(Index) for dynamic-size matrices.

64 : Base() {}
SelfAdjointEigenSolver< MatrixType_ > Base
Definition: GeneralizedSelfAdjointEigenSolver.h:52

◆ GeneralizedSelfAdjointEigenSolver() [2/3]

template<typename MatrixType_ >
Eigen::GeneralizedSelfAdjointEigenSolver< MatrixType_ >::GeneralizedSelfAdjointEigenSolver ( Index  size)
inlineexplicit

Constructor, pre-allocates memory for dynamic-size matrices.

Parameters
[in]sizePositive integer, size of the matrix whose eigenvalues and eigenvectors will be computed.

This constructor is useful for dynamic-size matrices, when the user intends to perform decompositions via compute(). The size parameter is only used as a hint. It is not an error to give a wrong size, but it may impair performance.

See also
compute() for an example
78 : Base(size) {}
Scalar Scalar int size
Definition: benchVecAdd.cpp:17

◆ GeneralizedSelfAdjointEigenSolver() [3/3]

template<typename MatrixType_ >
Eigen::GeneralizedSelfAdjointEigenSolver< MatrixType_ >::GeneralizedSelfAdjointEigenSolver ( const MatrixType matA,
const MatrixType matB,
int  options = ComputeEigenvectors | Ax_lBx 
)
inline

Constructor; computes generalized eigendecomposition of given matrix pencil.

Parameters
[in]matASelfadjoint matrix in matrix pencil. Only the lower triangular part of the matrix is referenced.
[in]matBPositive-definite matrix in matrix pencil. Only the lower triangular part of the matrix is referenced.
[in]optionsA or-ed set of flags {ComputeEigenvectors,EigenvaluesOnly} | {Ax_lBx,ABx_lx,BAx_lx}. Default is ComputeEigenvectors|Ax_lBx.

This constructor calls compute(const MatrixType&, const MatrixType&, int) to compute the eigenvalues and (if requested) the eigenvectors of the generalized eigenproblem \( Ax = \lambda B x \) with matA the selfadjoint matrix \( A \) and matB the positive definite matrix \( B \). Each eigenvector \( x \) satisfies the property \( x^* B x = 1 \). The eigenvectors are computed if options contains ComputeEigenvectors.

In addition, the two following variants can be solved via options:

  • ABx_lx: \( ABx = \lambda x \)
  • BAx_lx: \( BAx = \lambda x \)

Example:

MatrixXd X = MatrixXd::Random(5, 5);
MatrixXd A = X + X.transpose();
cout << "Here is a random symmetric matrix, A:" << endl << A << endl;
X = MatrixXd::Random(5, 5);
MatrixXd B = X * X.transpose();
cout << "and a random positive-definite matrix, B:" << endl << B << endl << endl;
GeneralizedSelfAdjointEigenSolver<MatrixXd> es(A, B);
cout << "The eigenvalues of the pencil (A,B) are:" << endl << es.eigenvalues() << endl;
cout << "The matrix of eigenvectors, V, is:" << endl << es.eigenvectors() << endl << endl;
double lambda = es.eigenvalues()[0];
cout << "Consider the first eigenvalue, lambda = " << lambda << endl;
VectorXd v = es.eigenvectors().col(0);
cout << "If v is the corresponding eigenvector, then A * v = " << endl << A * v << endl;
cout << "... and lambda * B * v = " << endl << lambda * B * v << endl << endl;
Array< int, Dynamic, 1 > v
Definition: Array_initializer_list_vector_cxx11.cpp:1
cout<< "The eigenvalues of A are:"<< endl<< ces.eigenvalues()<< endl;cout<< "The matrix of eigenvectors, V, is:"<< endl<< ces.eigenvectors()<< endl<< endl;complex< float > lambda
Definition: ComplexEigenSolver_compute.cpp:9
EigenSolver< MatrixXf > es
Definition: EigenSolver_compute.cpp:1
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47
Definition: matrices.h:74
#define X
Definition: icosphere.cpp:20

Output:

See also
compute(const MatrixType&, const MatrixType&, int)
108  : Base(matA.cols()) {
109  compute(matA, matB, options);
110  }
MatrixXf matB(2, 2)
GeneralizedSelfAdjointEigenSolver & compute(const MatrixType &matA, const MatrixType &matB, int options=ComputeEigenvectors|Ax_lBx)
Computes generalized eigendecomposition of given matrix pencil.
Definition: GeneralizedSelfAdjointEigenSolver.h:159
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: PlainObjectBase.h:192
Eigen::Matrix< Scalar, Dynamic, Dynamic, ColMajor > matA(size, size)

References Eigen::GeneralizedSelfAdjointEigenSolver< MatrixType_ >::compute(), matA(), and matB().

Member Function Documentation

◆ compute()

template<typename MatrixType >
GeneralizedSelfAdjointEigenSolver< MatrixType > & Eigen::GeneralizedSelfAdjointEigenSolver< MatrixType >::compute ( const MatrixType matA,
const MatrixType matB,
int  options = ComputeEigenvectors | Ax_lBx 
)

Computes generalized eigendecomposition of given matrix pencil.

Parameters
[in]matASelfadjoint matrix in matrix pencil. Only the lower triangular part of the matrix is referenced.
[in]matBPositive-definite matrix in matrix pencil. Only the lower triangular part of the matrix is referenced.
[in]optionsA or-ed set of flags {ComputeEigenvectors,EigenvaluesOnly} | {Ax_lBx,ABx_lx,BAx_lx}. Default is ComputeEigenvectors|Ax_lBx.
Returns
Reference to *this

According to options, this function computes eigenvalues and (if requested) the eigenvectors of one of the following three generalized eigenproblems:

  • Ax_lBx: \( Ax = \lambda B x \)
  • ABx_lx: \( ABx = \lambda x \)
  • BAx_lx: \( BAx = \lambda x \) with matA the selfadjoint matrix \( A \) and matB the positive definite matrix \( B \). In addition, each eigenvector \( x \) satisfies the property \( x^* B x = 1 \).

The eigenvalues() function can be used to retrieve the eigenvalues. If options contains ComputeEigenvectors, then the eigenvectors are also computed and can be retrieved by calling eigenvectors().

The implementation uses LLT to compute the Cholesky decomposition \( B = LL^* \) and computes the classical eigendecomposition of the selfadjoint matrix \( L^{-1} A (L^*)^{-1} \) if options contains Ax_lBx and of \( L^{*} A L \) otherwise. This solves the generalized eigenproblem, because any solution of the generalized eigenproblem \( Ax = \lambda B x \) corresponds to a solution \( L^{-1} A (L^*)^{-1} (L^* x) = \lambda (L^* x) \) of the eigenproblem for \( L^{-1} A (L^*)^{-1} \). Similar statements can be made for the two other variants.

Example:

MatrixXd X = MatrixXd::Random(5, 5);
MatrixXd A = X * X.transpose();
X = MatrixXd::Random(5, 5);
MatrixXd B = X * X.transpose();
GeneralizedSelfAdjointEigenSolver<MatrixXd> es(A, B, EigenvaluesOnly);
cout << "The eigenvalues of the pencil (A,B) are:" << endl << es.eigenvalues() << endl;
es.compute(B, A, false);
cout << "The eigenvalues of the pencil (B,A) are:" << endl << es.eigenvalues() << endl;
@ EigenvaluesOnly
Definition: Constants.h:398

Output:

See also
GeneralizedSelfAdjointEigenSolver(const MatrixType&, const MatrixType&, int)
160  {
161  eigen_assert(matA.cols() == matA.rows() && matB.rows() == matA.rows() && matB.cols() == matB.rows());
162  eigen_assert((options & ~(EigVecMask | GenEigMask)) == 0 && (options & EigVecMask) != EigVecMask &&
163  ((options & GenEigMask) == 0 || (options & GenEigMask) == Ax_lBx || (options & GenEigMask) == ABx_lx ||
164  (options & GenEigMask) == BAx_lx) &&
165  "invalid option parameter");
166 
167  bool computeEigVecs = ((options & EigVecMask) == 0) || ((options & EigVecMask) == ComputeEigenvectors);
168 
169  // Compute the cholesky decomposition of matB = L L' = U'U
170  LLT<MatrixType> cholB(matB);
171 
172  int type = (options & GenEigMask);
173  if (type == 0) type = Ax_lBx;
174 
175  if (type == Ax_lBx) {
176  // compute C = inv(L) A inv(L')
177  MatrixType matC = matA.template selfadjointView<Lower>();
178  cholB.matrixL().template solveInPlace<OnTheLeft>(matC);
179  cholB.matrixU().template solveInPlace<OnTheRight>(matC);
180 
181  Base::compute(matC, computeEigVecs ? ComputeEigenvectors : EigenvaluesOnly);
182 
183  // transform back the eigen vectors: evecs = inv(U) * evecs
184  if (computeEigVecs) cholB.matrixU().solveInPlace(Base::m_eivec);
185  } else if (type == ABx_lx) {
186  // compute C = L' A L
187  MatrixType matC = matA.template selfadjointView<Lower>();
188  matC = matC * cholB.matrixL();
189  matC = cholB.matrixU() * matC;
190 
191  Base::compute(matC, computeEigVecs ? ComputeEigenvectors : EigenvaluesOnly);
192 
193  // transform back the eigen vectors: evecs = inv(U) * evecs
194  if (computeEigVecs) cholB.matrixU().solveInPlace(Base::m_eivec);
195  } else if (type == BAx_lx) {
196  // compute C = L' A L
197  MatrixType matC = matA.template selfadjointView<Lower>();
198  matC = matC * cholB.matrixL();
199  matC = cholB.matrixU() * matC;
200 
201  Base::compute(matC, computeEigVecs ? ComputeEigenvectors : EigenvaluesOnly);
202 
203  // transform back the eigen vectors: evecs = L * evecs
204  if (computeEigVecs) Base::m_eivec = cholB.matrixL() * Base::m_eivec;
205  }
206 
207  return *this;
208 }
#define eigen_assert(x)
Definition: Macros.h:910
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: PlainObjectBase.h:191
EIGEN_DEVICE_FUNC SelfAdjointEigenSolver & compute(const EigenBase< InputType > &matrix, int options=ComputeEigenvectors)
Computes eigendecomposition of given matrix.
EigenvectorsType m_eivec
Definition: SelfAdjointEigenSolver.h:371
@ GenEigMask
Definition: Constants.h:414
@ EigVecMask
Definition: Constants.h:403
@ Ax_lBx
Definition: Constants.h:406
@ ComputeEigenvectors
Definition: Constants.h:401
@ BAx_lx
Definition: Constants.h:412
@ ABx_lx
Definition: Constants.h:409
type
Definition: compute_granudrum_aor.py:141

References Eigen::ABx_lx, Eigen::Ax_lBx, Eigen::BAx_lx, Eigen::PlainObjectBase< Derived >::cols(), compute(), Eigen::ComputeEigenvectors, eigen_assert, Eigen::EigenvaluesOnly, Eigen::EigVecMask, Eigen::GenEigMask, matA(), matB(), Eigen::LLT< MatrixType_, UpLo_ >::matrixL(), Eigen::LLT< MatrixType_, UpLo_ >::matrixU(), Eigen::PlainObjectBase< Derived >::rows(), and compute_granudrum_aor::type.

Referenced by generalized_eigensolver_real(), Eigen::GeneralizedSelfAdjointEigenSolver< MatrixType_ >::GeneralizedSelfAdjointEigenSolver(), and selfadjointeigensolver().


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