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

Base class for the diagonal Gaussian models. More...

#include <STK_HDGaussianBase.h>

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

Public Types

typedef IMixtureDensity< Derived > Base
 
- Public Types inherited from STK::IMixtureDensity< Derived >
typedef hidden::MixtureTraits< Derived >::Array Array
 
typedef hidden::MixtureTraits< Derived >::Parameters Parameters
 
typedef hidden::Traits< Array >::Type Type
 

Public Member Functions

Real constmean (int k, int j) const
 
int constd (int k) const
 
Real constb (int k) const
 
Real constq (int k) const
 
Real consta (int j, int k) const
 
void initializeModelImpl ()
 Initialize the parameters of the model.
 
template<class Weights >
Real impute (int i, int j, Weights const &pk) const
 
Real rand (int i, int j, int k) const
 
template<class Array >
void getParameters (Array &params) const
 This function is used in order to get the current values of the means and standard deviations.
 
void writeParameters (CArrayXX const *p_tik, ostream &os) const
 This function can be used to write summary of parameters to the output stream.
 
int nbCluster () const
 
Array const *constp_data () const
 
- Public Member Functions inherited from STK::IMixtureDensity< Derived >
 ~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.
 
template<class Weights >
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.
 

Public Attributes

Parameters param_
 parameters of the derived mixture model.
 

Protected Member Functions

 HDGaussianBase (int nbCluster)
 default constructor
 
 HDGaussianBase (HDGaussianBase const &model)
 copy constructor
 
 ~HDGaussianBase ()
 destructor
 
void randomMean (CArrayXX const *p_tik)
 sample randomly the mean of each component by sampling randomly a row of the data set.
 
bool updateMean (CArrayXX const *p_tik)
 compute the weighted mean of a Gaussian mixture.
 
- Protected Member Functions inherited from STK::IMixtureDensity< Derived >
 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.
 

Additional Inherited Members

- Protected Attributes inherited from STK::IMixtureDensity< Derived >
Parameters param_
 parameters of the derived mixture model.
 

Detailed Description

template<class Derived>
class STK::HDGaussianBase< Derived >

Base class for the diagonal Gaussian models.

Definition at line 55 of file STK_HDGaussianBase.h.

Member Typedef Documentation

◆ Base

template<class Derived >
typedef IMixtureDensity<Derived > STK::HDGaussianBase< Derived >::Base

Definition at line 58 of file STK_HDGaussianBase.h.

Constructor & Destructor Documentation

◆ HDGaussianBase() [1/2]

template<class Derived >
STK::HDGaussianBase< Derived >::HDGaussianBase ( int  nbCluster)
inlineprotected

default constructor

Parameters
nbClusternumber of cluster in the model

Definition at line 67 of file STK_HDGaussianBase.h.

67: Base(nbCluster) {}
IMixtureDensity< Derived > Base

◆ HDGaussianBase() [2/2]

template<class Derived >
STK::HDGaussianBase< Derived >::HDGaussianBase ( HDGaussianBase< Derived > const model)
inlineprotected

copy constructor

Parameters
modelThe model to copy

Definition at line 71 of file STK_HDGaussianBase.h.

71: Base(model) {}

◆ ~HDGaussianBase()

template<class Derived >
STK::HDGaussianBase< Derived >::~HDGaussianBase ( )
inlineprotected

destructor

Definition at line 73 of file STK_HDGaussianBase.h.

73{}

Member Function Documentation

◆ a()

template<class Derived >
Real const & STK::HDGaussianBase< Derived >::a ( int  j,
int  k 
) const
inline
Returns
rotation matrix of the kth cluster

Definition at line 85 of file STK_HDGaussianBase.h.

85{ return param_.a(k, j);}
Parameters param_
parameters of the derived mixture model.

References STK::HDGaussianBase< Derived >::param_.

◆ b()

template<class Derived >
Real const & STK::HDGaussianBase< Derived >::b ( int  k) const
inline
Returns
noise variance of the kth cluster

Definition at line 81 of file STK_HDGaussianBase.h.

81{ return param_.b(k);}

References STK::HDGaussianBase< Derived >::param_.

◆ d()

template<class Derived >
int const & STK::HDGaussianBase< Derived >::d ( int  k) const
inline
Returns
dimension of low sub-subspace of the kth cluster

Definition at line 79 of file STK_HDGaussianBase.h.

79{ return param_.d(k);}

References STK::HDGaussianBase< Derived >::param_.

◆ getParameters()

template<class Derived >
template<class Array >
void STK::HDGaussianBase< Derived >::getParameters ( Array params) const

This function is used in order to get the current values of the means and standard deviations.

Parameters
[out]paramsthe array with the parameters of the mixture.

Definition at line 169 of file STK_HDGaussianBase.h.

170{
171 int nbClust = nbCluster();
172 params.resize(2*nbClust, p_data()->cols());
173 for (int k= 0; k < nbClust; ++k)
174 {
175 for (int j= params.beginCols(); j< params.endCols(); ++j)
176 {
177 params(baseIdx+2*k , j) = mean(baseIdx + k, j);
178 params(baseIdx+2*k+1, j) = sigma(baseIdx + k, j);
179 }
180 }
181}
Array const *const & p_data() const
Real const & mean(int k, int j) const
const int baseIdx
base index of the containers created in STK++.

References STK::baseIdx, and STK::mean().

◆ impute()

template<class Derived >
template<class Weights >
Real STK::HDGaussianBase< Derived >::impute ( int  i,
int  j,
Weights const pk 
) const
Returns
an imputation value for the jth variable of the ith sample
Parameters
i,jindexes of the data to impute
pkthe probabilities of each class for the ith individual

Definition at line 123 of file STK_HDGaussianBase.h.

124{
125 Real sum = 0.;
126 for (int k= pk.begin(); k < pk.end(); ++k)
127 { sum += pk[k] * mean(k,j);}
128 return sum;
129}
Arrays::SumOp< Lhs, Rhs >::result_type sum(Lhs const &lhs, Rhs const &rhs)
convenience function for summing two arrays
double Real
STK fundamental type of Real values.

References STK::mean(), and STK::sum().

◆ initializeModelImpl()

template<class Derived >
void STK::HDGaussianBase< Derived >::initializeModelImpl ( )
inline

Initialize the parameters of the model.

Definition at line 88 of file STK_HDGaussianBase.h.

88{ param_.resize(p_data()->cols());}

References STK::HDGaussianBase< Derived >::p_data(), and STK::HDGaussianBase< Derived >::param_.

◆ mean()

template<class Derived >
Real const & STK::HDGaussianBase< Derived >::mean ( int  k,
int  j 
) const
inline
Returns
mean of the kth cluster and jth variable

Definition at line 77 of file STK_HDGaussianBase.h.

77{ return param_.mean(k,j);}

References STK::HDGaussianBase< Derived >::param_.

Referenced by STK::HDGaussianBase< Derived >::rand().

◆ nbCluster()

template<class Derived >
int STK::IMixtureDensity< Derived >::nbCluster ( ) const
inline
Returns
the number of cluster

Definition at line 124 of file STK_IMixtureDensity.h.

124{ return nbCluster_;}
int nbCluster_
number of cluster.

◆ p_data()

template<class Derived >
Array const *const & STK::IMixtureDensity< Derived >::p_data ( ) const
inline
Returns
a pointer on the current data set

Definition at line 131 of file STK_IMixtureDensity.h.

131{ return p_dataij_;}
Array const * p_dataij_
pointer on the data set

Referenced by STK::HDGaussianBase< Derived >::initializeModelImpl().

◆ q()

template<class Derived >
Real const & STK::HDGaussianBase< Derived >::q ( int  k) const
inline
Returns
rotation matrix of the kth cluster

Definition at line 83 of file STK_HDGaussianBase.h.

83{ return param_.q(k);}

References STK::HDGaussianBase< Derived >::param_.

◆ rand()

template<class Derived >
Real STK::HDGaussianBase< Derived >::rand ( int  i,
int  j,
int  k 
) const
inline
Returns
a simulated value for the jth variable of the ith sample in the kth cluster
Parameters
i,j,kindexes of the data to simulate

Definition at line 98 of file STK_HDGaussianBase.h.

99 { return Law::Normal::rand(mean(k, j), sigma(k,j));}
Real rand() const
Generate a pseudo Normal random variate.

References STK::HDGaussianBase< Derived >::mean(), and STK::Law::Normal::rand().

◆ randomMean()

template<class Derived >
void STK::HDGaussianBase< Derived >::randomMean ( CArrayXX const p_tik)
protected

sample randomly the mean of each component by sampling randomly a row of the data set.

Definition at line 132 of file STK_HDGaussianBase.h.

133{
134 // indexes array
135 VectorXi indexes(this->nbSample());
136 for(int i=p_data()->beginRows(); i< p_data()->endRows(); ++i) { indexes[i] = i;}
137 Range rind = this->nbSample();
138 // sample without repetition
139 for (int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
140 {
141 // random number in [0, end-k[
142 int i = Law::UniformDiscrete::rand(rind.begin(), rind.end()-1);
143 // get ith individuals
144 param_.mean_[k] = p_data()->row(indexes[i]);
145 // exchange it with nth
146 indexes.swap(i, rind.lastIdx());
147 // decrease
148 rind.decLast(1);
149 }
150}
virtual int rand() const
Generate a pseudo Uniform random variate.
Array2DVector< int > VectorXi
TRange< UnknownSize > Range
Definition STK_Range.h:59

References STK::Law::UniformDiscrete::rand().

◆ updateMean()

template<class Derived >
bool STK::HDGaussianBase< Derived >::updateMean ( CArrayXX const p_tik)
protected

compute the weighted mean of a Gaussian mixture.

Definition at line 153 of file STK_HDGaussianBase.h.

154{
155 for (int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
156 {
157 for (int j=p_data()->beginCols(); j< p_data()->endCols(); ++j)
158 { param_.mean_[k][j] = p_data()->col(j).wmean(p_tik->col(k));}
159 }
160 return true;
161}

References STK::ICArray< Derived >::col().

◆ writeParameters()

template<class Derived >
void STK::HDGaussianBase< Derived >::writeParameters ( CArrayXX const p_tik,
ostream os 
) const

This function can be used to write summary of parameters to the output stream.

Parameters
p_tika constant pointer on the posterior probabilities
osStream where you want to write the summary of parameters.

Definition at line 189 of file STK_HDGaussianBase.h.

190{
191 CPointX m(p_data()->cols()), s(p_data()->cols());
192 for (int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
193 {
194 // store sigma values in an array for a nice output
195 for (int j= s.begin(); j < s.end(); ++j)
196 { m[j] = mean(k,j); s[j] = sigma(k,j);}
197 os << _T("---> Component ") << k << _T("\n");
198 os << _T("mean = ") << m;
199 os << _T("sigma = ")<< s;
200 }
201}
#define _T(x)
Let x unmodified.
CArrayPoint< Real, UnknownSize, Arrays::by_col_ > CPointX

References _T, and STK::mean().

Member Data Documentation

◆ param_


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