STK++ 0.9.13
STK::DiagGaussian_sk< Array > Class Template Reference

The diagonal Gaussian mixture model DiagGaussian_sk assumes an equal standard deviation in each cluster and has a density function of the form. More...

#include <STK_DiagGaussian_sk.h>

Inheritance diagram for STK::DiagGaussian_sk< Array >:
Inheritance graph

Public Types

typedef DiagGaussianBase< DiagGaussian_sk< Array > > Base
 
- Public Types inherited from STK::DiagGaussianBase< DiagGaussian_sk< Array > >
typedef IMixtureDensity< DiagGaussian_sk< Array > > 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

 DiagGaussian_sk (int nbCluster)
 default constructor
 
 DiagGaussian_sk (DiagGaussian_sk const &model)
 copy constructor
 
 ~DiagGaussian_sk ()
 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::DiagGaussianBase< DiagGaussian_sk< Array > >
Real constmean (int k, int j) const
 
Real constsigma (int k, int j) const
 
void initializeModelImpl ()
 Initialize the parameters of the model.
 
Real lnComponentProbability (int i, int k) const
 
Real impute (int i, int j, Weights const &pk) const
 
Real rand (int i, int j, int k) const
 
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
 
int nbSample () 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.
 

Additional Inherited Members

- Public Attributes inherited from STK::DiagGaussianBase< DiagGaussian_sk< Array > >
Parameters param_
 parameters of the derived mixture model.
 
- Protected Member Functions inherited from STK::DiagGaussianBase< DiagGaussian_sk< Array > >
 DiagGaussianBase (int nbCluster)
 default constructor
 
 DiagGaussianBase (DiagGaussianBase const &model)
 copy constructor
 
 ~DiagGaussianBase ()
 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.
 
- Protected Attributes inherited from STK::IMixtureDensity< Derived >
Parameters param_
 parameters of the derived mixture model.
 

Detailed Description

template<class Array>
class STK::DiagGaussian_sk< Array >

The diagonal Gaussian mixture model DiagGaussian_sk assumes an equal standard deviation in each cluster and has a density function of the form.

\[
 f(\mathbf{x}|\theta) = \sum_{k=1}^K p_k \prod_{j=1}^d
   \frac{1}{\sqrt{2\pi}\sigma_{k}} \exp\left\{-\frac{(x^j-\mu^j_k)^2}{2(\sigma_{k})^2}\right\}.
\]

Definition at line 69 of file STK_DiagGaussian_sk.h.

Member Typedef Documentation

◆ Base

Constructor & Destructor Documentation

◆ DiagGaussian_sk() [1/2]

template<class Array >
STK::DiagGaussian_sk< Array >::DiagGaussian_sk ( int  nbCluster)
inline

default constructor

Parameters
nbClusternumber of cluster in the model

Definition at line 79 of file STK_DiagGaussian_sk.h.

79: Base(nbCluster) {}
DiagGaussianBase< DiagGaussian_sk< Array > > Base

◆ DiagGaussian_sk() [2/2]

template<class Array >
STK::DiagGaussian_sk< Array >::DiagGaussian_sk ( DiagGaussian_sk< Array > const model)
inline

copy constructor

Parameters
modelThe model to copy

Definition at line 83 of file STK_DiagGaussian_sk.h.

83: Base(model) {}

◆ ~DiagGaussian_sk()

destructor

Definition at line 85 of file STK_DiagGaussian_sk.h.

85{}

Member Function Documentation

◆ computeNbFreeParameters()

template<class Array >
int STK::DiagGaussian_sk< Array >::computeNbFreeParameters ( ) const
inline
Returns
the number of free parameters of the model

Definition at line 94 of file STK_DiagGaussian_sk.h.

95 { return this->nbCluster()*p_data()->sizeCols() + this->nbCluster();}

References STK::DiagGaussianBase< DiagGaussian_sk< Array > >::nbCluster(), and STK::DiagGaussianBase< DiagGaussian_sk< Array > >::p_data().

◆ randomInit()

template<class Array >
void STK::DiagGaussian_sk< 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-deviations will be set to 1.

Definition at line 103 of file STK_DiagGaussian_sk.h.

104{
105 this->randomMean(p_tik);
106 // compute the standard deviation
108 for (int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
109 {
110 variance = sqrt( ( p_tik->col(k).transpose()
111 *(*p_data() - (Const::Vector<Real>(this->nbSample()) * param_.mean_[k])
112 ).square()
113 ).sum() / (p_data()->sizeCols()*p_tk->elt(k))
114 );
115 param_.sigma_[k] = ((variance<=0) || !Arithmetic<Real>::isFinite(variance))
116 ? 1.
117 : std::sqrt(variance/(this->nbSample()*p_data()->sizeCols()));
118 }
119#ifdef STK_MIXTURE_VERY_VERBOSE
120 stk_cout << _T("DiagGaussian_sk<Array>::randomInit( CArrayXX const* const& p_tik, CPointX const* const& p_tk) done\n");
121#endif
122}
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
Parameters param_
parameters of the derived mixture model.
void randomMean(CArrayXX const *p_tik)
sample randomly the mean of each component by sampling randomly a row of the data set.
double Real
STK fundamental type of Real values.
hidden::FunctorTraits< Derived, VarianceOp >::Row variance(Derived const &A, bool unbiased=false)
Compute the variance(s) value(s) of A.

References _T, STK::ICArray< Derived >::col(), and stk_cout.

◆ run()

template<class Array >
bool STK::DiagGaussian_sk< Array >::run ( CArrayXX const *const p_tik,
CPointX const *const p_tk 
)

Compute the weighted mean and the common standard deviation.

Definition at line 126 of file STK_DiagGaussian_sk.h.

127{
128 // compute the means
129 if (!this->updateMean(p_tik)) return false;
130 // compute the standard deviation
131 for (int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
132 {
133 param_.sigma_[k]
134 = sqrt( ( p_tik->col(k).transpose()
135 *(*p_data() - (Const::Vector<Real>(this->nbSample()) * param_.mean_[k])
136 ).square()
137 ).sum()
138 /(p_data()->sizeCols()*p_tk->elt(k))
139 );
140// if (param(k).sigma_ <= 0.) return false;
141 }
142 return true;
143}
bool updateMean(CArrayXX const *p_tik)
compute the weighted mean of a Gaussian mixture.

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


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