STK++ 0.9.13
STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ > Class Template Reference

Main class for HD matrix valued matrix models. More...

#include <STK_HDMatrixGaussianModel.h>

Inheritance diagram for STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >:
Inheritance graph

Public Types

typedef IMixtureDensity< HDMatrixGaussianModel< IdRow_, IdCol_, Array_ > > Base
 Base class.
 
typedef HDMatrixModelParameters< Array_Parameters
 Type of the structure storing the parameters of a MixturGaussian_sjk model.
 
- Public Types inherited from STK::IMixtureDensity< HDMatrixGaussianModel< IdRow_, IdCol_, Array_ > >
typedef hidden::MixtureTraits< HDMatrixGaussianModel< IdRow_, IdCol_, Array_ > >::Array Array
 
typedef hidden::MixtureTraits< HDMatrixGaussianModel< IdRow_, IdCol_, Array_ > >::Parameters Parameters
 
typedef hidden::Traits< Array >::Type Type
 

Public Member Functions

 HDMatrixGaussianModel (int nbCluster)
 constructor
 
 HDMatrixGaussianModel (HDMatrixGaussianModel const &model)
 constructor
 
 ~HDMatrixGaussianModel ()
 destructor
 
void randomInit (CArrayXX const *const &p_tik, CPointX const *const &p_tk)
 Initialize randomly the parameters of the Gaussian mixture.
 
bool run (CArrayXX const *const &p_tik, CPointX const *const &p_tk)
 Compute the weighted mean and the common standard deviation.
 
int computeNbFreeParameters () const
 
- Public Member Functions inherited from STK::IMixtureDensity< HDMatrixGaussianModel< IdRow_, IdCol_, Array_ > >
 ~IMixtureDensity ()
 destructor
 
int nbCluster () const
 
int nbSample () const
 
Real lnNbSample () const
 
Array const *constp_data () const
 
Parameters constparam () const
 
void setData (Array const &data)
 Set the data set.
 
void setData (Array const &data, int nbRow, int nbCol, bool byRow=true)
 Set the data set and give dimensions.
 
bool initializeStep ()
 This function will be called at the beginning of the estimation process once the model is created and data is set.
 
void setParametersStep ()
 set the parameters obtained with the intermediate results and release the intermediate results.
 
void finalizeStep ()
 This function will be called once the model is estimated.
 
Type sample (int i, int j, Weights const &tk) const
 
- 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 Attributes

int nbRow_
 number of rows and columns of the data
 
int nbCol_
 
bool isRowAj_
 Structure of the covariance matrices between clusters for the rows.
 
bool isRowAk_
 
bool isRowBk_
 
bool isRowQk_
 
bool isRowDk_
 
bool isColAj_
 Structure of the covariance matrices between clusters for the columns.
 
bool isColAk_
 
bool isColBk_
 
bool isColQk_
 
bool isColDk_
 
- Protected Attributes inherited from STK::IMixtureDensity< HDMatrixGaussianModel< IdRow_, IdCol_, Array_ > >
Parameters param_
 parameters of the derived mixture model.
 

Private Member Functions

bool runFreeOrientationByRow (CArrayXX const *const &p_tik, CPointX const *const &p_tk)
 Update parameters for models with free orientation by rows.
 
bool runCommonOrientationByRow (CArrayXX const *const &p_tik, CPointX const *const &p_tk)
 Update parameters for models with common orientation by rows.
 
bool runFreeOrientationByCol (CArrayXX const *const &p_tik, CPointX const *const &p_tk)
 Update parameters for models with free orientation by columns.
 
bool runCommonOrientationByCol (CArrayXX const *const &p_tik, CPointX const *const &p_tk)
 Update parameters for models with common orientation by columns.
 

Additional Inherited Members

- Protected Member Functions inherited from STK::IMixtureDensity< HDMatrixGaussianModel< IdRow_, IdCol_, Array_ > >
 IMixtureDensity (int nbCluster)
 Default constructor.
 
 IMixtureDensity (IMixtureDensity const &model)
 copy constructor.
 
void initializeModel ()
 Initialize the model before its first use.
 
bool initializeStepImpl ()
 default implementation of initializeStepImpl (do nothing and return true)
 
void finalizeStepImpl ()
 default implementation of finalizeStepImpl (do nothing)
 
void setNbSample (int nbSample)
 Set the number of sample of the model (needed by kernel models)
 
- Protected Member Functions inherited from STK::IRecursiveTemplate< Derived >
 IRecursiveTemplate ()
 constructor.
 
 ~IRecursiveTemplate ()
 destructor.
 

Detailed Description

template<int IdRow_, int IdCol_, class Array_>
class STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >

Main class for HD matrix valued matrix models.

Definition at line 67 of file STK_HDMatrixGaussianModel.h.

Member Typedef Documentation

◆ Base

◆ Parameters

Type of the structure storing the parameters of a MixturGaussian_sjk model.

Definition at line 74 of file STK_HDMatrixGaussianModel.h.

Constructor & Destructor Documentation

◆ HDMatrixGaussianModel() [1/2]

template<int IdRow_, int IdCol_, class Array_ >
STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >::HDMatrixGaussianModel ( int  nbCluster)
inline

constructor

Parameters
nbClusternumber of clusters

Definition at line 84 of file STK_HDMatrixGaussianModel.h.

86 , isRowAj_(hidden::HDCovarianceChooser<IdRow_>::isAj_)
87 , isRowAk_(hidden::HDCovarianceChooser<IdRow_>::isAk_)
88 , isRowBk_(hidden::HDCovarianceChooser<IdRow_>::isBk_)
89 , isRowQk_(hidden::HDCovarianceChooser<IdRow_>::isQk_)
90 , isRowDk_(hidden::HDCovarianceChooser<IdRow_>::isDk_)
91 , isColAj_(hidden::HDCovarianceChooser<IdCol_>::isAj_)
92 , isColAk_(hidden::HDCovarianceChooser<IdCol_>::isAk_)
93 , isColBk_(hidden::HDCovarianceChooser<IdCol_>::isBk_)
94 , isColQk_(hidden::HDCovarianceChooser<IdCol_>::isQk_)
95 , isColDk_(hidden::HDCovarianceChooser<IdCol_>::isDk_)
96 {}
IMixtureDensity< HDMatrixGaussianModel< IdRow_, IdCol_, Array_ > > Base
Base class.
bool isColAj_
Structure of the covariance matrices between clusters for the columns.
bool isRowAj_
Structure of the covariance matrices between clusters for the rows.

◆ HDMatrixGaussianModel() [2/2]

template<int IdRow_, int IdCol_, class Array_ >
STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >::HDMatrixGaussianModel ( HDMatrixGaussianModel< IdRow_, IdCol_, Array_ > const model)
inline

constructor

Parameters
nbClusternumber of clusters

Definition at line 100 of file STK_HDMatrixGaussianModel.h.

101 : Base(model)
102 , nbRow_(model.nbRow_)
103 , nbCol_(model.nbCol_)
104 , isRowAj_(model.isRowAj_), isRowAk_(model.isRowAk_)
105 , isRowBk_(model.isRowBk_)
106 , isRowQk_(model.isRowQk_)
107 , isRowDk_(model.isRowDk_)
108 , isColAj_(model.isColAj_), isColAk_(model.isColAk_)
109 , isColBk_(model.isColBk_)
110 , isColQk_(model.isColQk_)
111 , isColDk_(model.isColDk_)
112 {}
int nbRow_
number of rows and columns of the data

◆ ~HDMatrixGaussianModel()

template<int IdRow_, int IdCol_, class Array_ >
STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >::~HDMatrixGaussianModel ( )
inline

destructor

Definition at line 114 of file STK_HDMatrixGaussianModel.h.

114{}

Member Function Documentation

◆ computeNbFreeParameters()

template<int IdRow_, int IdCol_, class Array_ >
int STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >::computeNbFreeParameters ( ) const
Returns
the number of free parameters of the model

Definition at line 146 of file STK_HDMatrixGaussianModel.h.

147{
148 int sum = nbRow_*nbCol_;
149 int maxRowDk = param_.rowDk_.maxElt();
150 int maxColDk = param_.colDk_.maxElt();
151 // for Bk
152 sum += (isRowBk_)? nbCluster :1;
153 sum += (isColBk_)? nbCluster :1;
154 // for Ajk
155 sum += (isRowAk_) ? ((isRowAj_) ? param_.rowDk_.sum() : nbCluster_) : maxRowDk;
156 sum += (isColAk_) ? ((isColAj_) ? param_.colDk_.sum() : nbCluster_) : maxColDk;
157 // for Qk
158 if (isRowQk_)
159 {
160 int dk = param_.rowDk_[k];
161 sum += dk*nbRow_ - (dk*(dk+1))/2;
162 }
163 else
164 { sum += maxRowDk*nbRow - (maxRowDk*(maxRowDk+1))/2;}
165 if (isColQk_)
166 {
167 int dk = param_.colDk_[k];
168 sum += dk*nbCol_ - (dk*(dk+1))/2;
169 }
170 else
171 { sum += maxColDk*nbRow - (maxColDk*(maxColDk+1))/2;}
172 //
173 return sum;
174}
Arrays::SumOp< Lhs, Rhs >::result_type sum(Lhs const &lhs, Rhs const &rhs)
convenience function for summing two arrays

References STK::sum().

◆ randomInit()

template<int IdRow_, int IdCol_, class Array_ >
void STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >::randomInit ( CArrayXX const *const p_tik,
CPointX const *const p_tk 
)

Initialize randomly the parameters of the Gaussian mixture.

The centers will be selected randomly among the data set and the standard-deviation will be set to 1.

Definition at line 184 of file STK_HDMatrixGaussianModel.h.

185{
186 VectorXi indexes(p_data()->rows());
187 for(int i=indexes.begin(); i< indexes.end(); ++i) { indexes[i] = i;}
188 Range rind(p_data()->rows());
189 // sample mean between individuals without repetition
190 for (int k= p_tk->begin(); k < p_tk->end(); ++k)
191 {
192 // random number in [0, end-k[
193 int i = Law::UniformDiscrete::rand(rind.begin(), rind.end()-1);
194 // get ith individuals
195 param_.meank_[k] = p_data()->row(indexes[i]);
196 // exchange it with nth
197 indexes.swap(i, rind.lastIdx());
198 // decrease
199 rind.decLast(1);
200 }
201 //
203 Real colB = Law::Exponential::rand(1);;
204 Real rowA = rowB + Law::Exponential::rand(1);
205 Real colA = colB + Law::Exponential::rand(1);
206 //
207 for (int k= p_tk->begin(); k < p_tk->end(); ++k)
208 {
209 Real v = Law::Normal::rand(0,1), w = Law::Normal::rand(0,1);
210 param_.rowQk_[k] = v * Const::Identity(nbRow_);
211 param_.colQk_[k] = w * Const::Identity(nbCol_);
212 param_.rowAjk_[k] = rowA;
213 param_.rowBk_[k] = rowB;
214 param_.colAjk_[k] = colA;
215 param_.colBk_[k] = colB;
216 }
217}
virtual Real rand() const
Generate a pseudo Exponential random variate.
Real rand() const
Generate a pseudo Normal random variate.
virtual int rand() const
Generate a pseudo Uniform random variate.
double Real
STK fundamental type of Real values.
Array2DVector< int > VectorXi
TRange< UnknownSize > Range
Definition STK_Range.h:59

References STK::Law::Exponential::rand(), STK::Law::Normal::rand(), and STK::Law::UniformDiscrete::rand().

◆ run()

template<int IdRow_, int IdCol_, class Array_ >
bool STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >::run ( CArrayXX const *const p_tik,
CPointX const *const p_tk 
)

Compute the weighted mean and the common standard deviation.

Definition at line 177 of file STK_HDMatrixGaussianModel.h.

178{
179
180 return true;
181}

◆ runCommonOrientationByCol()

template<int IdRow_, int IdCol_, class Array_ >
bool STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >::runCommonOrientationByCol ( CArrayXX const *const p_tik,
CPointX const *const p_tk 
)
private

Update parameters for models with common orientation by columns.

◆ runCommonOrientationByRow()

template<int IdRow_, int IdCol_, class Array_ >
bool STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >::runCommonOrientationByRow ( CArrayXX const *const p_tik,
CPointX const *const p_tk 
)
private

Update parameters for models with common orientation by rows.

◆ runFreeOrientationByCol()

template<int IdRow_, int IdCol_, class Array_ >
bool STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >::runFreeOrientationByCol ( CArrayXX const *const p_tik,
CPointX const *const p_tk 
)
private

Update parameters for models with free orientation by columns.

◆ runFreeOrientationByRow()

template<int IdRow_, int IdCol_, class Array_ >
bool STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >::runFreeOrientationByRow ( CArrayXX const *const p_tik,
CPointX const *const p_tk 
)
private

Update parameters for models with free orientation by rows.

Definition at line 221 of file STK_HDMatrixGaussianModel.h.

222{
223 CSquareX w;
225 for (int k=p_tk->begin(); k< p_tk->end(); ++k)
226 {
227
228 // compute the unbiased covariance function
229 Stat::Covariance(*p_data(), p_tik()->col(k), false);
230 }
231}
CArraySquare< Real, UnknownSize, Arrays::by_col_ > CSquareX

Member Data Documentation

◆ isColAj_

template<int IdRow_, int IdCol_, class Array_ >
bool STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >::isColAj_
protected

Structure of the covariance matrices between clusters for the columns.

Definition at line 132 of file STK_HDMatrixGaussianModel.h.

◆ isColAk_

template<int IdRow_, int IdCol_, class Array_ >
bool STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >::isColAk_
protected

Definition at line 132 of file STK_HDMatrixGaussianModel.h.

◆ isColBk_

template<int IdRow_, int IdCol_, class Array_ >
bool STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >::isColBk_
protected

Definition at line 132 of file STK_HDMatrixGaussianModel.h.

◆ isColDk_

template<int IdRow_, int IdCol_, class Array_ >
bool STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >::isColDk_
protected

Definition at line 132 of file STK_HDMatrixGaussianModel.h.

◆ isColQk_

template<int IdRow_, int IdCol_, class Array_ >
bool STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >::isColQk_
protected

Definition at line 132 of file STK_HDMatrixGaussianModel.h.

◆ isRowAj_

template<int IdRow_, int IdCol_, class Array_ >
bool STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >::isRowAj_
protected

Structure of the covariance matrices between clusters for the rows.

Definition at line 130 of file STK_HDMatrixGaussianModel.h.

◆ isRowAk_

template<int IdRow_, int IdCol_, class Array_ >
bool STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >::isRowAk_
protected

Definition at line 130 of file STK_HDMatrixGaussianModel.h.

◆ isRowBk_

template<int IdRow_, int IdCol_, class Array_ >
bool STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >::isRowBk_
protected

Definition at line 130 of file STK_HDMatrixGaussianModel.h.

◆ isRowDk_

template<int IdRow_, int IdCol_, class Array_ >
bool STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >::isRowDk_
protected

Definition at line 130 of file STK_HDMatrixGaussianModel.h.

◆ isRowQk_

template<int IdRow_, int IdCol_, class Array_ >
bool STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >::isRowQk_
protected

Definition at line 130 of file STK_HDMatrixGaussianModel.h.

◆ nbCol_

template<int IdRow_, int IdCol_, class Array_ >
int STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >::nbCol_
protected

Definition at line 128 of file STK_HDMatrixGaussianModel.h.

◆ nbRow_

template<int IdRow_, int IdCol_, class Array_ >
int STK::HDMatrixGaussianModel< IdRow_, IdCol_, Array_ >::nbRow_
protected

number of rows and columns of the data

Definition at line 128 of file STK_HDMatrixGaussianModel.h.


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