STK++ 0.9.13
STK::WeightedSvd< Array, WRows, WCols > Class Template Reference

This class perform a weighted svd decomposition. More...

#include <STK_WeightedSvd.h>

Inheritance diagram for STK::WeightedSvd< Array, WRows, WCols >:
Inheritance graph

Public Types

typedef ISvd< WeightedSvd< Array, WRows, WCols > > Base
 

Public Member Functions

 WeightedSvd (Array const &a, WRows const &wrows, WCols const &wcols, int dim)
 default constructor.
 
virtual ~WeightedSvd ()
 destructor
 
virtual bool run ()
 run the weighted svd
 
- Public Member Functions inherited from STK::ISvd< WeightedSvd< Array, WRows, WCols > >
Type det () const
 
Type trace () const
 
Type norm () const
 
int rank () const
 
ArrayU constU () const
 
ArrayV constV () const
 
ArrayD constD () const
 
void setData (OtherArray const &A, bool withU=true, bool withV=true)
 Set a new data set to ISvd class.
 
OtherArrayginv (OtherArray &res) const
 Compute the generalized inverse of the matrix and put the result in res.
 
- 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.
 

Private Attributes

CVectorX wrows_
 rows weights
 
CPointX wcols_
 columns weights
 
int dim_
 number of eigenvectors (left and right)
 

Additional Inherited Members

- Protected Types inherited from STK::ISvd< WeightedSvd< Array, WRows, WCols > >
typedef hidden::AlgebraTraits< WeightedSvd< Array, WRows, WCols > >::ArrayU ArrayU
 
typedef hidden::AlgebraTraits< WeightedSvd< Array, WRows, WCols > >::ArrayD ArrayD
 
typedef hidden::AlgebraTraits< WeightedSvd< Array, WRows, WCols > >::ArrayV ArrayV
 
typedef ArrayU::Type Type
 
- Protected Member Functions inherited from STK::ISvd< WeightedSvd< Array, WRows, WCols > >
 ISvd (ArrayU const &A, bool ref, bool withU=true, bool withV=true)
 Default constructor.
 
 ISvd (ArrayBase< OtherDerived > const &A, bool withU=true, bool withV=true)
 constructor with other kind of array/expression
 
 ISvd (ISvd const &S)
 Copy Constructor.
 
virtual ~ISvd ()
 destructor.
 
ISvdoperator= (const ISvd &S)
 Operator = : overwrite the ISvd with S.
 
virtual void finalize ()
 Finalize any operations that have to be done after the computation of the decomposition.
 
int nrowU () const
 
int ncolU () const
 
int nrowD () const
 
int ncolD () const
 
int nrowV () const
 
int ncolV () const
 
- 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 inherited from STK::ISvd< WeightedSvd< Array, WRows, WCols > >
ArrayU U_
 U_ matrix.
 
ArrayV V_
 V_ matrix.
 
ArrayD D_
 Diagonal array of the singular values.
 
bool withU_
 Compute U_ ?
 
bool withV_
 Compute V_ ?
 
Type norm_
 trace norm
 
int rank_
 rank
 
Type trace_
 trace norm
 
Type det_
 determinant
 
- 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 Array, class WRows, class WCols>
class STK::WeightedSvd< Array, WRows, WCols >

This class perform a weighted svd decomposition.

Definition at line 59 of file STK_WeightedSvd.h.

Member Typedef Documentation

◆ Base

template<class Array , class WRows , class WCols >
typedef ISvd< WeightedSvd<Array, WRows, WCols> > STK::WeightedSvd< Array, WRows, WCols >::Base

Definition at line 62 of file STK_WeightedSvd.h.

Constructor & Destructor Documentation

◆ WeightedSvd()

template<class Array , class WRows , class WCols >
STK::WeightedSvd< Array, WRows, WCols >::WeightedSvd ( Array const a,
WRows const wrows,
WCols const wcols,
int  dim 
)
inline

default constructor.

The matrix U_ will be weigthed by this constructor on the fly. The decomposition will be achieved using lapack (if present) or STK++ implementations (otherwise) when the methode @© run is called.

Parameters
athe matrix to decompose
wrows,wcolsweights of the rows and columns
dimthe number of left and right eigenVectors required

Definition at line 74 of file STK_WeightedSvd.h.

75 : Base(a, false, (dim>0) ? true:false, (dim>0) ? true:false)
76 , wrows_(wrows), wcols_(wcols), dim_(dim)
77
78 {
79 if (wrows.range() != U_.rows()) { wrows_.resize(U_.rows()).setValue(1./U_.sizeRows());}
80 else { wrows_ /= wrows.sum();}
81 if (wcols.range() != U_.cols()) { wcols_.resize(U_.cols()).setOne();}
82 dim_ = std::min(dim_, U_.sizeRows());
83 dim_ = std::min(dim_, U_.sizeCols());
84 }
Type const sum() const
Derived & resize(Range const &I, Range const &J)
resize the Array.
ISvd< WeightedSvd< Array, WRows, WCols > > Base
CPointX wcols_
columns weights
int dim_
number of eigenvectors (left and right)
CVectorX wrows_
rows weights

References STK::WeightedSvd< Array, WRows, WCols >::dim_, STK::ICArray< Derived >::resize(), STK::ISvd< WeightedSvd< Array, WRows, WCols > >::U_, STK::WeightedSvd< Array, WRows, WCols >::wcols_, and STK::WeightedSvd< Array, WRows, WCols >::wrows_.

◆ ~WeightedSvd()

template<class Array , class WRows , class WCols >
virtual STK::WeightedSvd< Array, WRows, WCols >::~WeightedSvd ( )
inlinevirtual

destructor

Definition at line 86 of file STK_WeightedSvd.h.

86{}

Member Function Documentation

◆ run()

template<class Array , class WRows , class WCols >
virtual bool STK::WeightedSvd< Array, WRows, WCols >::run ( )
inlinevirtual

run the weighted svd

Reimplemented from STK::ISvd< WeightedSvd< Array, WRows, WCols > >.

Definition at line 88 of file STK_WeightedSvd.h.

89 {
91#ifdef STKUSELAPACK
92 lapack::Svd solver(U_, false, this->withU_, this->withV_);
93 // if there is no cv, fall back to STK++ svd
94 if (!solver.run())
95 {
96 Svd<CArrayXX> dec(U_, true, this->withU_, this->withV_);
97 if (!dec.run()) return false;
98 else
99 {
100 U_.move(dec.U_);
101 D_ = dec.D_;
102 V_ = dec.V_;
103 }
104 }
105 else
106 {
107 U_.move(solver.U_);
108 D_.move(solver.D_);
109 V_.move(solver.V_);
110 }
111#else
112 Svd<CArrayXX> solver(U_, true, this->withU_, this->withV_);
113 if (!solver.run()) return false;
114 else
115 {
116 U_.move(dec.U_);
117 D_ = dec.D_;
118 V_ = dec.V_;
119 }
120
121#endif
122 // weight back
123 return true;
124 }
DiagonalizeOperator< Derived > const diagonalize() const
ArrayD D_
Diagonal array of the singular values.
Definition STK_ISvd.h:193

References STK::ISvd< WeightedSvd< Array, WRows, WCols > >::D_, STK::ArrayBase< Derived >::diagonalize(), STK::ISvd< Derived >::run(), STK::IRegression< YArray, XArray, Weights >::run(), STK::ISvd< WeightedSvd< Array, WRows, WCols > >::U_, STK::ISvd< WeightedSvd< Array, WRows, WCols > >::V_, STK::WeightedSvd< Array, WRows, WCols >::wcols_, STK::ISvd< WeightedSvd< Array, WRows, WCols > >::withU_, STK::ISvd< WeightedSvd< Array, WRows, WCols > >::withV_, and STK::WeightedSvd< Array, WRows, WCols >::wrows_.

Member Data Documentation

◆ dim_

template<class Array , class WRows , class WCols >
int STK::WeightedSvd< Array, WRows, WCols >::dim_
private

number of eigenvectors (left and right)

Definition at line 131 of file STK_WeightedSvd.h.

Referenced by STK::WeightedSvd< Array, WRows, WCols >::WeightedSvd().

◆ wcols_

template<class Array , class WRows , class WCols >
CPointX STK::WeightedSvd< Array, WRows, WCols >::wcols_
private

◆ wrows_

template<class Array , class WRows , class WCols >
CVectorX STK::WeightedSvd< Array, WRows, WCols >::wrows_
private

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