Shapeworks Studio  2.1
Shape analysis software suite
List of all members | Public Types | Public Member Functions | Protected Types | Protected Attributes
Eigen::GeneralizedEigenSolver< _MatrixType > Class Template Reference

Computes the generalized eigenvalues and eigenvectors of a pair of general matrices. More...

#include <GeneralizedEigenSolver.h>

+ Collaboration diagram for Eigen::GeneralizedEigenSolver< _MatrixType >:

Public Types

enum  {
  RowsAtCompileTime = MatrixType::RowsAtCompileTime, ColsAtCompileTime = MatrixType::ColsAtCompileTime, Options = MatrixType::Options, MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
  MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime
}
 
typedef _MatrixType MatrixType
 Synonym for the template parameter _MatrixType.
 
typedef MatrixType::Scalar Scalar
 Scalar type for matrices of type MatrixType.
 
typedef NumTraits< Scalar >::Real RealScalar
 
typedef MatrixType::Index Index
 
typedef std::complex< RealScalar > ComplexScalar
 Complex scalar type for MatrixType. More...
 
typedef Matrix< Scalar, ColsAtCompileTime, 1, Options &~RowMajor, MaxColsAtCompileTime, 1 > VectorType
 Type for vector of real scalar values eigenvalues as returned by betas(). More...
 
typedef Matrix< ComplexScalar, ColsAtCompileTime, 1, Options &~RowMajor, MaxColsAtCompileTime, 1 > ComplexVectorType
 Type for vector of complex scalar values eigenvalues as returned by betas(). More...
 
typedef CwiseBinaryOp< internal::scalar_quotient_op< ComplexScalar, Scalar >, ComplexVectorType, VectorTypeEigenvalueType
 Expression type for the eigenvalues as returned by eigenvalues().
 
typedef Matrix< ComplexScalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTime > EigenvectorsType
 Type for matrix of eigenvectors as returned by eigenvectors(). More...
 

Public Member Functions

 GeneralizedEigenSolver ()
 Default constructor. More...
 
 GeneralizedEigenSolver (Index size)
 Default constructor with memory preallocation. More...
 
 GeneralizedEigenSolver (const MatrixType &A, const MatrixType &B, bool computeEigenvectors=true)
 Constructor; computes the generalized eigendecomposition of given matrix pair. More...
 
EigenvalueType eigenvalues () const
 Returns an expression of the computed generalized eigenvalues. More...
 
ComplexVectorType alphas () const
 
VectorType betas () const
 
GeneralizedEigenSolvercompute (const MatrixType &A, const MatrixType &B, bool computeEigenvectors=true)
 Computes generalized eigendecomposition of given matrix. More...
 
ComputationInfo info () const
 
GeneralizedEigenSolversetMaxIterations (Index maxIters)
 

Protected Types

typedef Matrix< Scalar, ColsAtCompileTime, 1, Options &~RowMajor, MaxColsAtCompileTime, 1 > ColumnVectorType
 

Protected Attributes

MatrixType m_eivec
 
ComplexVectorType m_alphas
 
VectorType m_betas
 
bool m_isInitialized
 
bool m_eigenvectorsOk
 
RealQZ< MatrixTypem_realQZ
 
MatrixType m_matS
 
ColumnVectorType m_tmp
 

Detailed Description

template<typename _MatrixType>
class Eigen::GeneralizedEigenSolver< _MatrixType >

Computes the generalized eigenvalues and eigenvectors of a pair of general matrices.

Template Parameters
_MatrixTypethe type of the matrices of which we are computing the eigen-decomposition; this is expected to be an instantiation of the Matrix class template. Currently, only real matrices are supported.

The generalized eigenvalues and eigenvectors of a matrix pair $ A $ and $ B $ are scalars $ \lambda $ and vectors $ v $ such that $ Av = \lambda Bv $. If $ D $ is a diagonal matrix with the eigenvalues on the diagonal, and $ V $ is a matrix with the eigenvectors as its columns, then $ A V = B V D $. The matrix $ V $ is almost always invertible, in which case we have $ A = B V D V^{-1} $. This is called the generalized eigen-decomposition.

The generalized eigenvalues and eigenvectors of a matrix pair may be complex, even when the matrices are real. Moreover, the generalized eigenvalue might be infinite if the matrix B is singular. To workaround this difficulty, the eigenvalues are provided as a pair of complex $ \alpha $ and real $ \beta $ such that: $ \lambda_i = \alpha_i / \beta_i $. If $ \beta_i $ is (nearly) zero, then one can consider the well defined left eigenvalue $ \mu = \beta_i / \alpha_i$ such that: $ \mu_i A v_i = B v_i $, or even $ \mu_i u_i^T A = u_i^T B $ where $ u_i $ is called the left eigenvector.

Call the function compute() to compute the generalized eigenvalues and eigenvectors of a given matrix pair. Alternatively, you can use the GeneralizedEigenSolver(const MatrixType&, const MatrixType&, bool) 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.

Here is an usage example of this class: Example:

Output:

See also
MatrixBase::eigenvalues(), class ComplexEigenSolver, class SelfAdjointEigenSolver

Definition at line 57 of file GeneralizedEigenSolver.h.

Member Typedef Documentation

template<typename _MatrixType >
typedef std::complex<RealScalar> Eigen::GeneralizedEigenSolver< _MatrixType >::ComplexScalar

Complex scalar type for MatrixType.

This is std::complex<Scalar> if Scalar is real (e.g., float or double) and just Scalar if Scalar is complex.

Definition at line 83 of file GeneralizedEigenSolver.h.

template<typename _MatrixType >
typedef Matrix<ComplexScalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> Eigen::GeneralizedEigenSolver< _MatrixType >::ComplexVectorType

Type for vector of complex scalar values eigenvalues as returned by betas().

This is a column vector with entries of type ComplexScalar. The length of the vector is the size of MatrixType.

Definition at line 97 of file GeneralizedEigenSolver.h.

template<typename _MatrixType >
typedef Matrix<ComplexScalar, RowsAtCompileTime, ColsAtCompileTime, Options, MaxRowsAtCompileTime, MaxColsAtCompileTime> Eigen::GeneralizedEigenSolver< _MatrixType >::EigenvectorsType

Type for matrix of eigenvectors as returned by eigenvectors().

This is a square matrix with entries of type ComplexScalar. The size is the same as the size of MatrixType.

Definition at line 108 of file GeneralizedEigenSolver.h.

template<typename _MatrixType >
typedef Matrix<Scalar, ColsAtCompileTime, 1, Options & ~RowMajor, MaxColsAtCompileTime, 1> Eigen::GeneralizedEigenSolver< _MatrixType >::VectorType

Type for vector of real scalar values eigenvalues as returned by betas().

This is a column vector with entries of type Scalar. The length of the vector is the size of MatrixType.

Definition at line 90 of file GeneralizedEigenSolver.h.

Constructor & Destructor Documentation

template<typename _MatrixType >
Eigen::GeneralizedEigenSolver< _MatrixType >::GeneralizedEigenSolver ( )
inline

Default constructor.

The default constructor is useful in cases in which the user intends to perform decompositions via EigenSolver::compute(const MatrixType&, bool).

See also
compute() for an example.

Definition at line 117 of file GeneralizedEigenSolver.h.

117 : m_eivec(), m_alphas(), m_betas(), m_isInitialized(false), m_realQZ(), m_matS(), m_tmp() {}
template<typename _MatrixType >
Eigen::GeneralizedEigenSolver< _MatrixType >::GeneralizedEigenSolver ( Index  size)
inline

Default constructor with memory preallocation.

Like the default constructor but with preallocation of the internal data according to the specified problem size.

See also
GeneralizedEigenSolver()

Definition at line 125 of file GeneralizedEigenSolver.h.

126  : m_eivec(size, size),
127  m_alphas(size),
128  m_betas(size),
129  m_isInitialized(false),
130  m_eigenvectorsOk(false),
131  m_realQZ(size),
132  m_matS(size, size),
133  m_tmp(size)
134  {}
template<typename _MatrixType >
Eigen::GeneralizedEigenSolver< _MatrixType >::GeneralizedEigenSolver ( const MatrixType A,
const MatrixType B,
bool  computeEigenvectors = true 
)
inline

Constructor; computes the generalized eigendecomposition of given matrix pair.

Parameters
[in]ASquare matrix whose eigendecomposition is to be computed.
[in]BSquare matrix whose eigendecomposition is to be computed.
[in]computeEigenvectorsIf true, both the eigenvectors and the eigenvalues are computed; if false, only the eigenvalues are computed.

This constructor calls compute() to compute the generalized eigenvalues and eigenvectors.

See also
compute()

Definition at line 148 of file GeneralizedEigenSolver.h.

149  : m_eivec(A.rows(), A.cols()),
150  m_alphas(A.cols()),
151  m_betas(A.cols()),
152  m_isInitialized(false),
153  m_eigenvectorsOk(false),
154  m_realQZ(A.cols()),
155  m_matS(A.rows(), A.cols()),
156  m_tmp(A.cols())
157  {
158  compute(A, B, computeEigenvectors);
159  }
GeneralizedEigenSolver & compute(const MatrixType &A, const MatrixType &B, bool computeEigenvectors=true)
Computes generalized eigendecomposition of given matrix.

Member Function Documentation

template<typename _MatrixType >
ComplexVectorType Eigen::GeneralizedEigenSolver< _MatrixType >::alphas ( ) const
inline
Returns
A const reference to the vectors containing the alpha values

This vector permits to reconstruct the j-th eigenvalues as alphas(i)/betas(j).

See also
betas(), eigenvalues()

Definition at line 209 of file GeneralizedEigenSolver.h.

210  {
211  eigen_assert(m_isInitialized && "GeneralizedEigenSolver is not initialized.");
212  return m_alphas;
213  }
template<typename _MatrixType >
VectorType Eigen::GeneralizedEigenSolver< _MatrixType >::betas ( ) const
inline
Returns
A const reference to the vectors containing the beta values

This vector permits to reconstruct the j-th eigenvalues as alphas(i)/betas(j).

See also
alphas(), eigenvalues()

Definition at line 220 of file GeneralizedEigenSolver.h.

221  {
222  eigen_assert(m_isInitialized && "GeneralizedEigenSolver is not initialized.");
223  return m_betas;
224  }
template<typename MatrixType >
GeneralizedEigenSolver< MatrixType > & Eigen::GeneralizedEigenSolver< MatrixType >::compute ( const MatrixType A,
const MatrixType B,
bool  computeEigenvectors = true 
)

Computes generalized eigendecomposition of given matrix.

Parameters
[in]ASquare matrix whose eigendecomposition is to be computed.
[in]BSquare matrix whose eigendecomposition is to be computed.
[in]computeEigenvectorsIf true, both the eigenvectors and the eigenvalues are computed; if false, only the eigenvalues are computed.
Returns
Reference to *this

This function computes the eigenvalues of the real matrix matrix. The eigenvalues() function can be used to retrieve them. If computeEigenvectors is true, then the eigenvectors are also computed and can be retrieved by calling eigenvectors().

The matrix is first reduced to real generalized Schur form using the RealQZ class. The generalized Schur decomposition is then used to compute the eigenvalues and eigenvectors.

The cost of the computation is dominated by the cost of the generalized Schur decomposition.

This method reuses of the allocated data in the GeneralizedEigenSolver object.

Definition at line 291 of file GeneralizedEigenSolver.h.

292 {
293  using std::sqrt;
294  using std::abs;
295  eigen_assert(A.cols() == A.rows() && B.cols() == A.rows() && B.cols() == B.rows());
296 
297  // Reduce to generalized real Schur form:
298  // A = Q S Z and B = Q T Z
299  m_realQZ.compute(A, B, computeEigenvectors);
300 
301  if (m_realQZ.info() == Success)
302  {
303  m_matS = m_realQZ.matrixS();
304  if (computeEigenvectors)
305  m_eivec = m_realQZ.matrixZ().transpose();
306 
307  // Compute eigenvalues from matS
308  m_alphas.resize(A.cols());
309  m_betas.resize(A.cols());
310  Index i = 0;
311  while (i < A.cols())
312  {
313  if (i == A.cols() - 1 || m_matS.coeff(i+1, i) == Scalar(0))
314  {
315  m_alphas.coeffRef(i) = m_matS.coeff(i, i);
316  m_betas.coeffRef(i) = m_realQZ.matrixT().coeff(i,i);
317  ++i;
318  }
319  else
320  {
321  Scalar p = Scalar(0.5) * (m_matS.coeff(i, i) - m_matS.coeff(i+1, i+1));
322  Scalar z = sqrt(abs(p * p + m_matS.coeff(i+1, i) * m_matS.coeff(i, i+1)));
323  m_alphas.coeffRef(i) = ComplexScalar(m_matS.coeff(i+1, i+1) + p, z);
324  m_alphas.coeffRef(i+1) = ComplexScalar(m_matS.coeff(i+1, i+1) + p, -z);
325 
326  m_betas.coeffRef(i) = m_realQZ.matrixT().coeff(i,i);
327  m_betas.coeffRef(i+1) = m_realQZ.matrixT().coeff(i,i);
328  i += 2;
329  }
330  }
331  }
332 
333  m_isInitialized = true;
334  m_eigenvectorsOk = false;//computeEigenvectors;
335 
336  return *this;
337 }
ComputationInfo info() const
Reports whether previous computation was successful.
Definition: RealQZ.h:166
std::complex< RealScalar > ComplexScalar
Complex scalar type for MatrixType.
MatrixType::Scalar Scalar
Scalar type for matrices of type MatrixType.
const MatrixType & matrixT() const
Returns matrix S in the QZ decomposition.
Definition: RealQZ.h:148
const MatrixType & matrixS() const
Returns matrix S in the QZ decomposition.
Definition: RealQZ.h:139
const MatrixType & matrixZ() const
Returns matrix Z in the QZ decomposition.
Definition: RealQZ.h:129
EIGEN_STRONG_INLINE void resize(Index nbRows, Index nbCols)
RealQZ & compute(const MatrixType &A, const MatrixType &B, bool computeQZ=true)
Computes QZ decomposition of given matrix.
Definition: RealQZ.h:557
template<typename _MatrixType >
EigenvalueType Eigen::GeneralizedEigenSolver< _MatrixType >::eigenvalues ( ) const
inline

Returns an expression of the computed generalized eigenvalues.

Returns
An expression of the column vector containing the eigenvalues.

It is a shortcut for

this->alphas().cwiseQuotient(this->betas());

Not that betas might contain zeros. It is therefore not recommended to use this function, but rather directly deal with the alphas and betas vectors.

Precondition
Either the constructor GeneralizedEigenSolver(const MatrixType&,const MatrixType&,bool) or the member function compute(const MatrixType&,const MatrixType&,bool) has been called before.

The eigenvalues are repeated according to their algebraic multiplicity, so there are as many eigenvalues as rows in the matrix. The eigenvalues are not sorted in any particular order.

See also
alphas(), betas(), eigenvectors()

Definition at line 198 of file GeneralizedEigenSolver.h.

199  {
200  eigen_assert(m_isInitialized && "GeneralizedEigenSolver is not initialized.");
201  return EigenvalueType(m_alphas,m_betas);
202  }
CwiseBinaryOp< internal::scalar_quotient_op< ComplexScalar, Scalar >, ComplexVectorType, VectorType > EigenvalueType
Expression type for the eigenvalues as returned by eigenvalues().
template<typename _MatrixType >
GeneralizedEigenSolver& Eigen::GeneralizedEigenSolver< _MatrixType >::setMaxIterations ( Index  maxIters)
inline

Sets the maximal number of iterations allowed.

Definition at line 259 of file GeneralizedEigenSolver.h.

260  {
261  m_realQZ.setMaxIterations(maxIters);
262  return *this;
263  }
RealQZ & setMaxIterations(Index maxIters)
Definition: RealQZ.h:183

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