STK++ 0.9.13
STK::ISymEigen< Derived > Class Template Reference

The class ISymEigen is an interface class for the method computing the eigenvalue Decomposition of a symmetric ArrayXX. More...

#include <STK_ISymEigen.h>

Inheritance diagram for STK::ISymEigen< Derived >:
Inheritance graph

Public Member Functions

 ~ISymEigen ()
 virtual destructor
 
ISymEigenoperator= (ISymEigen const &eigen)
 Operator = : overwrite the ISymEigen with eigen.
 
Range constrange () const
 
Type constnorm () const
 
int constrank () const
 
Type constdet () const
 
Type consttrace () const
 
CArraySquare< Type, size_ > constrotation () const
 
CArraySquare< Type, size_ > consteigenVectors () const
 
CArrayVector< Type, size_ > consteigenValues () const
 
template<class OtherDerived >
void setData (ExprBase< OtherDerived > const &data)
 overloading of setData.
 
template<class ArraySquare >
ArraySquareginv (ArraySquare &res) const
 Compute the generalized inverse of the symmetric matrix and put the result in res.
 
template<class ArraySquare >
ArraySquareginvsqrt (ArraySquare &res) const
 Compute the generalized square root inverse of the symmetric matrix and put the result in res.
 
template<class ArraySquare >
ArraySquaregsqrt (ArraySquare &res) const
 Compute the square root of the symmetric matrix and put the result in res.
 
virtual bool run ()
 Find the eigenvalues and eigenvectors of the matrix.
 
- Public Member Functions inherited from STK::IRunnerBase
String consterror () const
 get the last error message.
 
- Public Member Functions inherited from STK::IRecursiveTemplate< Derived >
Derived & asDerived ()
 static cast : return a reference of this with a cast to the derived class.
 
Derived constasDerived () const
 static cast : return a const reference of this with a cast to the derived class.
 
Derived * asPtrDerived ()
 static cast : return a ptr on a Derived of this with a cast to the derived class.
 
Derived constasPtrDerived () const
 static cast : return a ptr on a constant Derived of this with a cast to the derived class.
 
Derived * clone () const
 create a leaf using the copy constructor of the Derived class.
 
Derived * clone (bool isRef) const
 create a leaf using the copy constructor of the Derived class and a flag determining if the clone is a reference or not.
 

Protected Types

enum  {
  structure_ = hidden::Traits< SquareArray >::structure_ , orient_ = hidden::Traits< SquareArray >::orient_ , sizeRows_ = hidden::Traits< SquareArray >::sizeRows_ , sizeCols_ = hidden::Traits< SquareArray >::sizeCols_ ,
  size_ = (sizeRows_<sizeCols_) ? sizeRows_ : sizeCols_
}
 
typedef IRunnerBase Base
 
typedef hidden::AlgebraTraits< Derived >::SquareArray SquareArray
 
typedef hidden::Traits< SquareArray >::Type Type
 

Protected Member Functions

 ISymEigen ()
 Default constructor.
 
 ISymEigen (SquareArray const &data, bool ref=false)
 Constructor The original data set can be overwritten by the eigenvectors if it is stored in a CSquareXd.
 
template<class OtherDerived >
 ISymEigen (ExprBase< OtherDerived > const &data)
 template constructor
 
 ISymEigen (ISymEigen const &eigen)
 Copy constructor.
 
void finalizeStep ()
 finalize the computation by computing the trace, rank, trace norm and determinant of the matrix.
 
- Protected Member Functions inherited from STK::IRunnerBase
 IRunnerBase ()
 default constructor
 
 IRunnerBase (IRunnerBase const &runner)
 copy constructor
 
virtual ~IRunnerBase ()
 destructor
 
virtual void update ()
 update the runner.
 
- Protected Member Functions inherited from STK::IRecursiveTemplate< Derived >
 IRecursiveTemplate ()
 constructor.
 
 ~IRecursiveTemplate ()
 destructor.
 

Protected Attributes

Range range_
 range of the original data set.
 
Type trace_
 trace norm
 
Type norm_
 trace norm
 
int rank_
 rank
 
Type det_
 determinant
 
CArraySquare< Type, size_eigenVectors_
 Square matrix or the eigenvectors.
 
CArrayVector< Type, size_eigenValues_
 Array of the eigenvalues.
 
CVectorXi SupportEigenVectors_
 Array for the support of the eigenvectors.
 
- Protected Attributes inherited from STK::IRunnerBase
String msg_error_
 String with the last error message.
 
bool hasRun_
 true if run has been used, false otherwise
 

Detailed Description

template<class Derived>
class STK::ISymEigen< Derived >

The class ISymEigen is an interface class for the method computing the eigenvalue Decomposition of a symmetric ArrayXX.

The decomposition of a symmetric matrix require

  • Input: A symmetric matrix A of size (n,n)
  • Output:
    1. P Array of size (n,n).
    2. D Vector of dimension n
    3. $ A = PDP' $ The matrix A can be copied or overwritten by the class.

The 2-norm (operator norm) of the matrix is given. if the 2-norm is less than the arithmetic precision of the type Real, the rank is not full. Thus the user can be faced with a deficient rank matrix and with a norm very small (i.e. not exactly 0.0).

Definition at line 64 of file STK_ISymEigen.h.

Member Typedef Documentation

◆ Base

template<class Derived >
typedef IRunnerBase STK::ISymEigen< Derived >::Base
protected

Definition at line 67 of file STK_ISymEigen.h.

◆ SquareArray

template<class Derived >
typedef hidden::AlgebraTraits<Derived>::SquareArray STK::ISymEigen< Derived >::SquareArray
protected

Definition at line 68 of file STK_ISymEigen.h.

◆ Type

template<class Derived >
typedef hidden::Traits<SquareArray>::Type STK::ISymEigen< Derived >::Type
protected

Definition at line 70 of file STK_ISymEigen.h.

Member Enumeration Documentation

◆ anonymous enum

template<class Derived >
anonymous enum
protected
Enumerator
structure_ 
orient_ 
sizeRows_ 
sizeCols_ 
size_ 

Definition at line 71 of file STK_ISymEigen.h.

72 {
73 structure_ = hidden::Traits< SquareArray >::structure_,
74 orient_ = hidden::Traits< SquareArray >::orient_,
75 sizeRows_ = hidden::Traits< SquareArray >::sizeRows_,
76 sizeCols_ = hidden::Traits< SquareArray >::sizeCols_,
78
79 };

Constructor & Destructor Documentation

◆ ISymEigen() [1/4]

template<class Derived >
STK::ISymEigen< Derived >::ISymEigen ( )
protected

Default constructor.

Definition at line 220 of file STK_ISymEigen.h.

221 : Base()
222 , range_(), trace_(Type(0)), norm_(Type(0)), rank_(Type(0)), det_(Type(0))
223 , eigenVectors_()
224 , eigenValues_()
226{
227 STK_STATIC_ASSERT( SquareArray::structure_==(int)Arrays::square_
228 || SquareArray::structure_==(int)Arrays::symmetric_
229 || SquareArray::structure_==(int)Arrays::upper_symmetric_
230 || SquareArray::structure_==(int)Arrays::lower_symmetric_
231 ,YOU_HAVE_TO_USE_A_SQUARE_MATRIX_IN_THIS_METHOD)
232}
#define STK_STATIC_ASSERT(COND, MSG)
Type norm_
trace norm
Range range_
range of the original data set.
hidden::Traits< SquareArray >::Type Type
Type trace_
trace norm
CArrayVector< Type, size_ > eigenValues_
Array of the eigenvalues.
Type det_
determinant
CArraySquare< Type, size_ > eigenVectors_
Square matrix or the eigenvectors.
CVectorXi SupportEigenVectors_
Array for the support of the eigenvectors.
IRunnerBase Base
@ lower_symmetric_
lower symmetric matrix/array/expression
@ symmetric_
symmetric matrix/array/expression
@ upper_symmetric_
upper symmetric matrix/array/expression
@ square_
square matrix/array/expression

References STK::Arrays::lower_symmetric_, STK::Arrays::square_, STK_STATIC_ASSERT, STK::Arrays::symmetric_, and STK::Arrays::upper_symmetric_.

◆ ISymEigen() [2/4]

template<class Derived >
STK::ISymEigen< Derived >::ISymEigen ( SquareArray const data,
bool  ref = false 
)
protected

Constructor The original data set can be overwritten by the eigenvectors if it is stored in a CSquareXd.

Observe that in this case the base index have to be 0.

Parameters
datareference on a symmetric square matrix
reftrue if we overwrite the data set, false otherwise

Definition at line 241 of file STK_ISymEigen.h.

242 : Base()
243 , range_(data.range()), trace_(Type(0)), norm_(Type(0)), rank_(Type(0)), det_(Type(0))
244 , eigenVectors_(data, ref)
245 , eigenValues_(data.size(), 0.)
246 , SupportEigenVectors_(2*data.size(), 0)
247{
248 STK_STATIC_ASSERT( SquareArray::structure_==(int)Arrays::square_
249 || SquareArray::structure_==(int)Arrays::symmetric_
250 || SquareArray::structure_==(int)Arrays::upper_symmetric_
251 || SquareArray::structure_==(int)Arrays::lower_symmetric_
252 ,YOU_HAVE_TO_USE_A_SQUARE_MATRIX_IN_THIS_METHOD)
253}

References STK::Arrays::lower_symmetric_, STK::Arrays::square_, STK_STATIC_ASSERT, STK::Arrays::symmetric_, and STK::Arrays::upper_symmetric_.

◆ ISymEigen() [3/4]

template<class Derived >
template<class OtherDerived >
STK::ISymEigen< Derived >::ISymEigen ( ExprBase< OtherDerived > const data)
protected

template constructor

Parameters
datareference on a symmetric square expression

Definition at line 259 of file STK_ISymEigen.h.

260 : Base()
261 , range_(data.range()), trace_(Type(0)), norm_(0.), rank_(0), det_(0.)
262 , eigenVectors_(data.asDerived())
263 , eigenValues_(data.size(), 0.)
264 , SupportEigenVectors_(2*data.size(), 0)
265{
266 STK_STATIC_ASSERT( SquareArray::structure_==(int)Arrays::square_
267 || SquareArray::structure_==(int)Arrays::symmetric_
268 || SquareArray::structure_==(int)Arrays::upper_symmetric_
269 || SquareArray::structure_==(int)Arrays::lower_symmetric_
270 ,YOU_HAVE_TO_USE_A_SQUARE_MATRIX_IN_THIS_METHOD)
271}

References STK::Arrays::lower_symmetric_, STK::Arrays::square_, STK_STATIC_ASSERT, STK::Arrays::symmetric_, and STK::Arrays::upper_symmetric_.

◆ ISymEigen() [4/4]

template<class Derived >
STK::ISymEigen< Derived >::ISymEigen ( ISymEigen< Derived > const eigen)
protected

Copy constructor.

Parameters
eigenthe EigenValue to copy

Definition at line 276 of file STK_ISymEigen.h.

277 : Base(eigen)
278 , range_(eigen.range_), trace_(eigen.trace_), norm_(eigen.norm_), rank_(eigen.rank_), det_(eigen.det_)
279 , eigenVectors_(eigen.eigenVectors_)
280 , eigenValues_(eigen.eigenValues_)
281 , SupportEigenVectors_(eigen.SupportEigenVectors_)
282{
283 STK_STATIC_ASSERT( SquareArray::structure_==(int)Arrays::square_
284 || SquareArray::structure_==(int)Arrays::symmetric_
285 || SquareArray::structure_==(int)Arrays::upper_symmetric_
286 || SquareArray::structure_==(int)Arrays::lower_symmetric_
287 ,YOU_HAVE_TO_USE_A_SQUARE_MATRIX_IN_THIS_METHOD)
288}

References STK::Arrays::lower_symmetric_, STK::Arrays::square_, STK_STATIC_ASSERT, STK::Arrays::symmetric_, and STK::Arrays::upper_symmetric_.

◆ ~ISymEigen()

template<class Derived >
STK::ISymEigen< Derived >::~ISymEigen ( )
inline

virtual destructor

Definition at line 102 of file STK_ISymEigen.h.

102{}

Member Function Documentation

◆ det()

◆ eigenValues()

template<class Derived >
CArrayVector< Type, size_ > const & STK::ISymEigen< Derived >::eigenValues ( ) const
inline
Returns
the eigenvalues

Definition at line 135 of file STK_ISymEigen.h.

135{ return eigenValues_;}

References STK::ISymEigen< Derived >::eigenValues_.

Referenced by main().

◆ eigenVectors()

template<class Derived >
CArraySquare< Type, size_ > const & STK::ISymEigen< Derived >::eigenVectors ( ) const
inline
Returns
the rotation matrix

Definition at line 133 of file STK_ISymEigen.h.

133{ return eigenVectors_;}

References STK::ISymEigen< Derived >::eigenVectors_.

Referenced by main().

◆ finalizeStep()

template<class Derived >
void STK::ISymEigen< Derived >::finalizeStep ( )
protected

finalize the computation by computing the trace, rank, trace norm and determinant of the matrix.

Definition at line 294 of file STK_ISymEigen.h.

295{
296 // compute sign and trace
297 trace_ = 0.;
298 int s = 1;
299 for (int i=eigenValues_.begin(); i< eigenValues_.end(); ++i )
300 {
301 Type value = eigenValues_[i];
302 s *= sign(value);
303 trace_ += value;
304 }
305
306 // compute norm_ (2-norm) and determinant
308 det_ = 0;
309 if (eigenValues_.abs().minElt() > 0)
310 { det_ = s * std::exp(eigenValues_.abs().log().sum());}
311
312 // compute norm_ rank_
313 rank_ = eigenValues_.size(); // full rank
314 Type tol = norm_ * Arithmetic<Type>::epsilon();
315 for (int i=eigenValues_.begin(); i< eigenValues_.end(); ++i )
316 { if (std::abs(eigenValues_[i]) < tol) { rank_--;}}
317}
UnaryOperator< AbsOp< Type >, Derived > abs() const
Type const maxElt(int &row, int &col) const
Type sign(Type const &x, Type const &y=Type(1))
template sign value sign(x) * y: Type should be an integral type
Definition STK_Misc.h:53

References STK::sign().

◆ ginv()

template<class Derived >
template<class ArraySquare >
ArraySquare & STK::ISymEigen< Derived >::ginv ( ArraySquare res) const
inline

Compute the generalized inverse of the symmetric matrix and put the result in res.

Parameters
resarray with the result
Returns
the result

Definition at line 156 of file STK_ISymEigen.h.

157 {
158 Type tol = Arithmetic<Type>::epsilon() * norm_;
159 if(tol==0) { tol = Arithmetic<Type>::min();}
160 // compute and return PD^{-1}P'
161 return (res = eigenVectors_ * eigenValues_.diagonalize().safeInverse(tol) * eigenVectors_.transpose());
162 }
TransposeOperator< Derived > const transpose() const
DiagonalizeOperator< Derived > const diagonalize() const

References STK::ArrayBase< Derived >::diagonalize(), STK::ISymEigen< Derived >::eigenValues_, STK::ISymEigen< Derived >::eigenVectors_, STK::ISymEigen< Derived >::norm_, and STK::ArrayBase< Derived >::transpose().

Referenced by STK::hidden::InvertLowerSymMatrixImpl< Matrix, Size_ >::invertLowerSymMatrixXX(), STK::hidden::InvertSymImpl< Matrix, Size_ >::invertSymMatrixXX(), and STK::hidden::InvertUpperSymMatrixImpl< Matrix, Size_ >::invertUpperSymMatrixXX().

◆ ginvsqrt()

template<class Derived >
template<class ArraySquare >
ArraySquare & STK::ISymEigen< Derived >::ginvsqrt ( ArraySquare res) const
inline

Compute the generalized square root inverse of the symmetric matrix and put the result in res.

Parameters
resarray with the result
Returns
the result

Definition at line 169 of file STK_ISymEigen.h.

170 {
171 Type tol = Arithmetic<Type>::epsilon() * norm_;
172 if(tol==0) { tol = Arithmetic<Type>::min();}
173 // compute and return PD^{-1/2}P'
174 return(res = eigenVectors_ * eigenValues_.diagonalize().sqrt().safeInverse(tol) * eigenVectors_.transpose());
175 }

References STK::ArrayBase< Derived >::diagonalize(), STK::ISymEigen< Derived >::eigenValues_, STK::ISymEigen< Derived >::eigenVectors_, STK::ISymEigen< Derived >::norm_, and STK::ArrayBase< Derived >::transpose().

◆ gsqrt()

template<class Derived >
template<class ArraySquare >
ArraySquare & STK::ISymEigen< Derived >::gsqrt ( ArraySquare res) const
inline

Compute the square root of the symmetric matrix and put the result in res.

Parameters
resarray with the result
Returns
the result

Definition at line 181 of file STK_ISymEigen.h.

182 {
183 Type tol = Arithmetic<Type>::epsilon() * norm_;
184 if(tol==0) { tol = Arithmetic<Type>::min();}
185 // compute and return PD^{1/2}P'
186 return(res = eigenVectors_ * eigenValues_.diagonalize().sqrt() * eigenVectors_.transpose());
187 }

References STK::ArrayBase< Derived >::diagonalize(), STK::ISymEigen< Derived >::eigenValues_, STK::ISymEigen< Derived >::eigenVectors_, STK::ISymEigen< Derived >::norm_, and STK::ArrayBase< Derived >::transpose().

◆ norm()

template<class Derived >
Type const & STK::ISymEigen< Derived >::norm ( ) const
inline
Returns
the trace norm of the matrix

Definition at line 123 of file STK_ISymEigen.h.

123{ return norm_;}

References STK::ISymEigen< Derived >::norm_.

◆ operator=()

template<class Derived >
ISymEigen & STK::ISymEigen< Derived >::operator= ( ISymEigen< Derived > const eigen)
inline

Operator = : overwrite the ISymEigen with eigen.

Parameters
eigenISymEigen to copy
Returns
a reference on this

Definition at line 107 of file STK_ISymEigen.h.

108 {
109 range_ = eigen.range_;
110 trace_ = eigen.trace_; // trace of the matrix
111 norm_ = eigen.norm_; // norm of the matrix
112 rank_ = eigen.rank_; // rank of the matrix
113 det_ = eigen.det_; // determinant of the matrix
114 eigenVectors_ = eigen.eigenVectors_;
115 eigenValues_ = eigen.eigenValues_;
116 SupportEigenVectors_ = eigen.SupportEigenVectors_;
117 return *this;
118 }

References STK::ISymEigen< Derived >::det_, STK::ISymEigen< Derived >::eigenValues_, STK::ISymEigen< Derived >::eigenVectors_, STK::ISymEigen< Derived >::norm_, STK::ISymEigen< Derived >::range_, STK::ISymEigen< Derived >::rank_, STK::ISymEigen< Derived >::SupportEigenVectors_, and STK::ISymEigen< Derived >::trace_.

◆ range()

template<class Derived >
Range const & STK::ISymEigen< Derived >::range ( ) const
inline
Returns
the range of the matrix

Definition at line 121 of file STK_ISymEigen.h.

121{ return range_;}

References STK::ISymEigen< Derived >::range_.

◆ rank()

template<class Derived >
int const & STK::ISymEigen< Derived >::rank ( ) const
inline
Returns
the rank of the matrix

Definition at line 125 of file STK_ISymEigen.h.

125{ return rank_;}

References STK::ISymEigen< Derived >::rank_.

◆ rotation()

template<class Derived >
CArraySquare< Type, size_ > const & STK::ISymEigen< Derived >::rotation ( ) const
inline
Returns
the rotation matrix

Definition at line 131 of file STK_ISymEigen.h.

131{ return eigenVectors_;}

References STK::ISymEigen< Derived >::eigenVectors_.

◆ run()

template<class Derived >
virtual bool STK::ISymEigen< Derived >::run ( )
inlinevirtual

Find the eigenvalues and eigenvectors of the matrix.

Implements STK::IRunnerBase.

Definition at line 189 of file STK_ISymEigen.h.

190 {
191 if (eigenVectors_.empty()) { return true;}
192 return this->asDerived().runImpl();
193 }
bool empty() const
Derived & asDerived()
static cast : return a reference of this with a cast to the derived class.

References STK::IRecursiveTemplate< Derived >::asDerived(), STK::ISymEigen< Derived >::eigenVectors_, and STK::ICArray< Derived >::empty().

Referenced by STK::hidden::InvertLowerSymMatrixImpl< Matrix, Size_ >::invertLowerSymMatrixXX(), STK::hidden::InvertSymImpl< Matrix, Size_ >::invertSymMatrixXX(), STK::hidden::InvertUpperSymMatrixImpl< Matrix, Size_ >::invertUpperSymMatrixXX(), and main().

◆ setData()

template<class Derived >
template<class OtherDerived >
void STK::ISymEigen< Derived >::setData ( ExprBase< OtherDerived > const data)
inline

overloading of setData.

Parameters
datathe data set to set.

Definition at line 141 of file STK_ISymEigen.h.

142 {
143 STK_STATIC_ASSERT(OtherDerived::structure_==(int)Arrays::square_,YOU_HAVE_TO_USE_A_SQUARE_MATRIX_IN_THIS_METHOD)
144 range_ = data.range(); trace_ = 0; norm_ = 0.; rank_ = 0; det_ = 0.;
145 eigenVectors_ = data;
147 SupportEigenVectors_.resize(2*data.size());
148 this->hasRun_ = false;
149 }
Derived & resize(Range const &I, Range const &J)
resize the Array.
bool hasRun_
true if run has been used, false otherwise
Definition STK_IRunner.h:98

References STK::ISymEigen< Derived >::det_, STK::ISymEigen< Derived >::eigenValues_, STK::ISymEigen< Derived >::eigenVectors_, STK::IRunnerBase::hasRun_, STK::ISymEigen< Derived >::norm_, STK::ISymEigen< Derived >::range_, STK::ISymEigen< Derived >::rank_, STK::ICArray< Derived >::resize(), STK::Arrays::square_, STK_STATIC_ASSERT, STK::ISymEigen< Derived >::SupportEigenVectors_, and STK::ISymEigen< Derived >::trace_.

◆ trace()

template<class Derived >
Type const & STK::ISymEigen< Derived >::trace ( ) const
inline
Returns
the trace of the Array

Definition at line 129 of file STK_ISymEigen.h.

129{ return trace_;}

References STK::ISymEigen< Derived >::trace_.

Member Data Documentation

◆ det_

template<class Derived >
Type STK::ISymEigen< Derived >::det_
protected

◆ eigenValues_

◆ eigenVectors_

◆ norm_

◆ range_

template<class Derived >
Range STK::ISymEigen< Derived >::range_
protected

range of the original data set.


Definition at line 197 of file STK_ISymEigen.h.

Referenced by STK::ISymEigen< Derived >::operator=(), STK::ISymEigen< Derived >::range(), and STK::ISymEigen< Derived >::setData().

◆ rank_

template<class Derived >
int STK::ISymEigen< Derived >::rank_
protected

◆ SupportEigenVectors_

template<class Derived >
CVectorXi STK::ISymEigen< Derived >::SupportEigenVectors_
protected

Array for the support of the eigenvectors.

Definition at line 211 of file STK_ISymEigen.h.

Referenced by STK::ISymEigen< Derived >::operator=(), and STK::ISymEigen< Derived >::setData().

◆ trace_

template<class Derived >
Type STK::ISymEigen< Derived >::trace_
protected

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