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

The diagonal Gaussian mixture model DiagGaussian_sjk is the most general diagonal Gaussian model and have a density function of the form. More...

#include <STK_DiagGaussian_sjk.h>

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

Public Types

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

The diagonal Gaussian mixture model DiagGaussian_sjk is the most general diagonal Gaussian model and have 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^j_{k}} \exp\left\{-\frac{(x^j-\mu^j_k)^2}{2(\sigma^j_{k})^2}\right\}.
\]

Definition at line 70 of file STK_DiagGaussian_sjk.h.

Member Typedef Documentation

◆ Base

Constructor & Destructor Documentation

◆ DiagGaussian_sjk() [1/2]

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

default constructor

Parameters
nbClusternumber of cluster in the model

Definition at line 80 of file STK_DiagGaussian_sjk.h.

80: Base(nbCluster) {}
DiagGaussianBase< DiagGaussian_sjk< Array > > Base

◆ DiagGaussian_sjk() [2/2]

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

copy constructor

Parameters
modelThe model to copy

Definition at line 84 of file STK_DiagGaussian_sjk.h.

84: Base(model) {}

◆ ~DiagGaussian_sjk()

destructor

Definition at line 86 of file STK_DiagGaussian_sjk.h.

86{}

Member Function Documentation

◆ computeNbFreeParameters()

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

Definition at line 95 of file STK_DiagGaussian_sjk.h.

96 { return 2*this->nbCluster()*p_data()->sizeCols();}

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

◆ randomInit()

template<class Array >
void STK::DiagGaussian_sjk< 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 104 of file STK_DiagGaussian_sjk.h.

105{
106 this->randomMean(p_tik);
107 // compute the standard deviation
108 for (int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
109 {
110 param_.sigma_[k] = Stat::varianceWithFixedMean(*p_data(), p_tik->col(k), param_.mean_[k], false).sqrt();
111 }
112#ifdef STK_MIXTURE_VERY_VERBOSE
113 stk_cout << _T("DiagGaussian_sjk<Array>::randomInit( CArrayXX const* const& p_tik, CPointX const* const& p_tk) done\n");
114#endif
115}
#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.
hidden::FunctorTraits< Derived, VarianceWithFixedMeanOp >::Row varianceWithFixedMean(Derived const &A, MeanType const &mean, bool unbiased)
Compute the VarianceWithFixedMean(s) value(s) of A.

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

◆ run()

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

Compute the weighted mean and the common standard deviation.

Definition at line 119 of file STK_DiagGaussian_sjk.h.

120{
121 // compute the means
122 if (!this->updateMean(p_tik)) return false;
123 // compute the standard deviation
124 for (int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
125 {
126 param_.sigma_[k] = Stat::varianceWithFixedMean(*p_data(), p_tik->col(k), param_.mean_[k], false).sqrt();
127#ifdef STK_MIXTURE_DEBUG
128 if( (param_.sigma_[k] <= 0).any() )
129 {
130 stk_cout << _T("DiagGaussian_sjk::run() failed\n");
131 stk_cout << _T("p_tik->col(") << k << _T(") =\n") << p_tik->col(k).transpose() << _T("\n");
132 stk_cout << _T("param_.mean_[") << k << _T("] =") << param_.mean_[k];
133 stk_cout << _T("param_.sigma_[") << k << _T("] =") << param_.sigma_[k];
134 }
135#endif
136 }
137 return true;
138}
bool updateMean(CArrayXX const *p_tik)
compute the weighted mean of a Gaussian mixture.

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


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