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

Robust Cholesky decomposition of a matrix with pivoting. More...

#include <LDLT.h>

+ Collaboration diagram for Eigen::LDLT< _MatrixType, _UpLo >:

Public Types

enum  {
  RowsAtCompileTime = MatrixType::RowsAtCompileTime, ColsAtCompileTime = MatrixType::ColsAtCompileTime, Options = MatrixType::Options & ~RowMajorBit, MaxRowsAtCompileTime = MatrixType::MaxRowsAtCompileTime,
  MaxColsAtCompileTime = MatrixType::MaxColsAtCompileTime, UpLo = _UpLo
}
 
typedef _MatrixType MatrixType
 
typedef MatrixType::Scalar Scalar
 
typedef NumTraits< typename MatrixType::Scalar >::Real RealScalar
 
typedef MatrixType::Index Index
 
typedef Matrix< Scalar, RowsAtCompileTime, 1, Options, MaxRowsAtCompileTime, 1 > TmpMatrixType
 
typedef Transpositions< RowsAtCompileTime, MaxRowsAtCompileTime > TranspositionType
 
typedef PermutationMatrix< RowsAtCompileTime, MaxRowsAtCompileTime > PermutationType
 
typedef internal::LDLT_Traits< MatrixType, UpLo > Traits
 

Public Member Functions

 LDLT ()
 Default Constructor. More...
 
 LDLT (Index size)
 Default Constructor with memory preallocation. More...
 
 LDLT (const MatrixType &matrix)
 Constructor with decomposition. More...
 
void setZero ()
 
Traits::MatrixU matrixU () const
 
Traits::MatrixL matrixL () const
 
const TranspositionTypetranspositionsP () const
 
Diagonal< const MatrixType > vectorD () const
 
bool isPositive () const
 
bool isNegative (void) const
 
template<typename Rhs >
const internal::solve_retval< LDLT, Rhs > solve (const MatrixBase< Rhs > &b) const
 
template<typename Derived >
bool solveInPlace (MatrixBase< Derived > &bAndX) const
 
LDLTcompute (const MatrixType &matrix)
 
template<typename Derived >
LDLTrankUpdate (const MatrixBase< Derived > &w, const RealScalar &alpha=1)
 
const MatrixType & matrixLDLT () const
 
MatrixType reconstructedMatrix () const
 
Index rows () const
 
Index cols () const
 
ComputationInfo info () const
 Reports whether previous computation was successful. More...
 
template<typename Derived >
LDLT< MatrixType, _UpLo > & rankUpdate (const MatrixBase< Derived > &w, const typename NumTraits< typename MatrixType::Scalar >::Real &sigma)
 

Protected Attributes

MatrixType m_matrix
 
TranspositionType m_transpositions
 
TmpMatrixType m_temporary
 
int m_sign
 
bool m_isInitialized
 

Detailed Description

template<typename _MatrixType, int _UpLo>
class Eigen::LDLT< _MatrixType, _UpLo >

Robust Cholesky decomposition of a matrix with pivoting.

Parameters
MatrixTypethe type of the matrix of which to compute the LDL^T Cholesky decomposition
UpLothe triangular part that will be used for the decompositon: Lower (default) or Upper. The other triangular part won't be read.

Perform a robust Cholesky decomposition of a positive semidefinite or negative semidefinite matrix $ A $ such that $ A = P^TLDL^*P $, where P is a permutation matrix, L is lower triangular with a unit diagonal and D is a diagonal matrix.

The decomposition uses pivoting to ensure stability, so that L will have zeros in the bottom right rank(A) - n submatrix. Avoiding the square root on D also stabilizes the computation.

Remember that Cholesky decompositions are not rank-revealing. Also, do not use a Cholesky decomposition to determine whether a system of equations has a solution.

See also
MatrixBase::ldlt(), class LLT

Definition at line 45 of file LDLT.h.

Constructor & Destructor Documentation

template<typename _MatrixType, int _UpLo>
Eigen::LDLT< _MatrixType, _UpLo >::LDLT ( )
inline

Default Constructor.

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

Definition at line 72 of file LDLT.h.

72 : m_matrix(), m_transpositions(), m_isInitialized(false) {}
template<typename _MatrixType, int _UpLo>
Eigen::LDLT< _MatrixType, _UpLo >::LDLT ( 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
LDLT()

Definition at line 80 of file LDLT.h.

81  : m_matrix(size, size),
82  m_transpositions(size),
83  m_temporary(size),
84  m_isInitialized(false)
85  {}
template<typename _MatrixType, int _UpLo>
Eigen::LDLT< _MatrixType, _UpLo >::LDLT ( const MatrixType &  matrix)
inline

Constructor with decomposition.

This calculates the decomposition for the input matrix.

See also
LDLT(Index size)

Definition at line 92 of file LDLT.h.

93  : m_matrix(matrix.rows(), matrix.cols()),
94  m_transpositions(matrix.rows()),
95  m_temporary(matrix.rows()),
96  m_isInitialized(false)
97  {
98  compute(matrix);
99  }
Definition: math3d.h:219
LDLT & compute(const MatrixType &matrix)
Definition: LDLT.h:437

Member Function Documentation

template<typename MatrixType , int _UpLo>
LDLT< MatrixType, _UpLo > & Eigen::LDLT< MatrixType, _UpLo >::compute ( const MatrixType &  a)

Compute / recompute the LDLT decomposition A = L D L^* = U^* D U of matrix

Definition at line 437 of file LDLT.h.

438 {
439  eigen_assert(a.rows()==a.cols());
440  const Index size = a.rows();
441 
442  m_matrix = a;
443 
444  m_transpositions.resize(size);
445  m_isInitialized = false;
446  m_temporary.resize(size);
447 
448  internal::ldlt_inplace<UpLo>::unblocked(m_matrix, m_transpositions, m_temporary, &m_sign);
449 
450  m_isInitialized = true;
451  return *this;
452 }
void resize(int newSize)
EIGEN_STRONG_INLINE void resize(Index nbRows, Index nbCols)
template<typename _MatrixType, int _UpLo>
ComputationInfo Eigen::LDLT< _MatrixType, _UpLo >::info ( ) const
inline

Reports whether previous computation was successful.

Returns
Success if computation was succesful, NumericalIssue if the matrix.appears to be negative.

Definition at line 221 of file LDLT.h.

222  {
223  eigen_assert(m_isInitialized && "LDLT is not initialized.");
224  return Success;
225  }
template<typename _MatrixType, int _UpLo>
bool Eigen::LDLT< _MatrixType, _UpLo >::isNegative ( void  ) const
inline
Returns
true if the matrix is negative (semidefinite)

Definition at line 153 of file LDLT.h.

154  {
155  eigen_assert(m_isInitialized && "LDLT is not initialized.");
156  return m_sign == -1;
157  }
template<typename _MatrixType, int _UpLo>
bool Eigen::LDLT< _MatrixType, _UpLo >::isPositive ( ) const
inline
Returns
true if the matrix is positive (semidefinite)

Definition at line 139 of file LDLT.h.

140  {
141  eigen_assert(m_isInitialized && "LDLT is not initialized.");
142  return m_sign == 1;
143  }
template<typename _MatrixType, int _UpLo>
Traits::MatrixL Eigen::LDLT< _MatrixType, _UpLo >::matrixL ( ) const
inline
Returns
a view of the lower triangular matrix L

Definition at line 117 of file LDLT.h.

118  {
119  eigen_assert(m_isInitialized && "LDLT is not initialized.");
120  return Traits::getL(m_matrix);
121  }
template<typename _MatrixType, int _UpLo>
const MatrixType& Eigen::LDLT< _MatrixType, _UpLo >::matrixLDLT ( ) const
inline
Returns
the internal LDLT decomposition matrix

TODO: document the storage layout

Definition at line 205 of file LDLT.h.

206  {
207  eigen_assert(m_isInitialized && "LDLT is not initialized.");
208  return m_matrix;
209  }
template<typename _MatrixType, int _UpLo>
Traits::MatrixU Eigen::LDLT< _MatrixType, _UpLo >::matrixU ( ) const
inline
Returns
a view of the upper triangular matrix U

Definition at line 110 of file LDLT.h.

111  {
112  eigen_assert(m_isInitialized && "LDLT is not initialized.");
113  return Traits::getU(m_matrix);
114  }
template<typename _MatrixType, int _UpLo>
template<typename Derived >
LDLT<MatrixType,_UpLo>& Eigen::LDLT< _MatrixType, _UpLo >::rankUpdate ( const MatrixBase< Derived > &  w,
const typename NumTraits< typename MatrixType::Scalar >::Real &  sigma 
)

Update the LDLT decomposition: given A = L D L^T, efficiently compute the decomposition of A + sigma w w^T.

Parameters
wa vector to be incorporated into the decomposition.
sigmaa scalar, +1 for updates and -1 for "downdates," which correspond to removing previously-added column vectors. Optional; default value is +1.
See also
setZero()

Definition at line 461 of file LDLT.h.

462 {
463  const Index size = w.rows();
464  if (m_isInitialized)
465  {
466  eigen_assert(m_matrix.rows()==size);
467  }
468  else
469  {
470  m_matrix.resize(size,size);
471  m_matrix.setZero();
472  m_transpositions.resize(size);
473  for (Index i = 0; i < size; i++)
474  m_transpositions.coeffRef(i) = i;
475  m_temporary.resize(size);
476  m_sign = sigma>=0 ? 1 : -1;
477  m_isInitialized = true;
478  }
479 
480  internal::ldlt_inplace<UpLo>::update(m_matrix, m_transpositions, m_temporary, w, sigma);
481 
482  return *this;
483 }
void resize(int newSize)
Index & coeffRef(Index i)
EIGEN_STRONG_INLINE void resize(Index nbRows, Index nbCols)
template<typename MatrixType , int _UpLo>
MatrixType Eigen::LDLT< MatrixType, _UpLo >::reconstructedMatrix ( ) const
Returns
the matrix represented by the decomposition, i.e., it returns the product: P^T L D L^* P. This function is provided for debug purpose.

Definition at line 557 of file LDLT.h.

558 {
559  eigen_assert(m_isInitialized && "LDLT is not initialized.");
560  const Index size = m_matrix.rows();
561  MatrixType res(size,size);
562 
563  // P
564  res.setIdentity();
565  res = transpositionsP() * res;
566  // L^* P
567  res = matrixU() * res;
568  // D(L^*P)
569  res = vectorD().asDiagonal() * res;
570  // L(DL^*P)
571  res = matrixL() * res;
572  // P^T (LDL^*P)
573  res = transpositionsP().transpose() * res;
574 
575  return res;
576 }
Diagonal< const MatrixType > vectorD() const
Definition: LDLT.h:132
Traits::MatrixU matrixU() const
Definition: LDLT.h:110
Traits::MatrixL matrixL() const
Definition: LDLT.h:117
const TranspositionType & transpositionsP() const
Definition: LDLT.h:125
Transpose< TranspositionsBase > transpose() const
template<typename _MatrixType, int _UpLo>
void Eigen::LDLT< _MatrixType, _UpLo >::setZero ( )
inline

Clear any existing decomposition

See also
rankUpdate(w,sigma)

Definition at line 104 of file LDLT.h.

105  {
106  m_isInitialized = false;
107  }
template<typename _MatrixType, int _UpLo>
template<typename Rhs >
const internal::solve_retval<LDLT, Rhs> Eigen::LDLT< _MatrixType, _UpLo >::solve ( const MatrixBase< Rhs > &  b) const
inline
Returns
a solution x of $ A x = b $ using the current decomposition of A.

This function also supports in-place solves using the syntax x = decompositionObject.solve(x) .

More precisely, this method solves $ A x = b $ using the decomposition $ A = P^T L D L^* P $ by solving the systems $ P^T y_1 = b $, $ L y_2 = y_1 $, $ D y_3 = y_2 $, $ L^* y_4 = y_3 $ and $ P x = y_4 $ in succession. If the matrix $ A $ is singular, then $ D $ will also be singular (all the other matrices are invertible). In that case, the least-square solution of $ D y_3 = y_2 $ is computed. This does not mean that this function computes the least-square solution of $ A x = b $ is $ A $ is singular.

See also
MatrixBase::ldlt()

Definition at line 176 of file LDLT.h.

177  {
178  eigen_assert(m_isInitialized && "LDLT is not initialized.");
179  eigen_assert(m_matrix.rows()==b.rows()
180  && "LDLT::solve(): invalid number of rows of the right hand side matrix b");
181  return internal::solve_retval<LDLT, Rhs>(*this, b.derived());
182  }
template<typename _MatrixType, int _UpLo>
const TranspositionType& Eigen::LDLT< _MatrixType, _UpLo >::transpositionsP ( ) const
inline
Returns
the permutation matrix P as a transposition sequence.

Definition at line 125 of file LDLT.h.

126  {
127  eigen_assert(m_isInitialized && "LDLT is not initialized.");
128  return m_transpositions;
129  }
template<typename _MatrixType, int _UpLo>
Diagonal<const MatrixType> Eigen::LDLT< _MatrixType, _UpLo >::vectorD ( ) const
inline
Returns
the coefficients of the diagonal matrix D

Definition at line 132 of file LDLT.h.

133  {
134  eigen_assert(m_isInitialized && "LDLT is not initialized.");
135  return m_matrix.diagonal();
136  }

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