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

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

#include <STK_HDGaussian_AjkBkQkD.h>

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

Public Types

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

 HDGaussian_AjkBkQkD (int nbCluster)
 default constructor
 
 HDGaussian_AjkBkQkD (HDGaussian_AjkBkQkD const &model)
 copy constructor
 
 ~HDGaussian_AjkBkQkD ()
 destructor
 
Real lnComponentProbability (int i, int k) const
 
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
 
Array const *constp_data () const
 
- Public Member Functions inherited from STK::HDGaussianBase< HDGaussian_AjkBkQkD< Array > >
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.
 
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
 
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.
 
- Public Attributes inherited from STK::HDGaussianBase< HDGaussian_AjkBkQkD< Array > >
Parameters param_
 parameters of the derived mixture model.
 

Additional Inherited Members

- Protected Member Functions inherited from STK::HDGaussianBase< HDGaussian_AjkBkQkD< Array > >
 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.
 
- Protected Attributes inherited from STK::IMixtureDensity< Derived >
Parameters param_
 parameters of the derived mixture model.
 

Detailed Description

template<class Array>
class STK::HDGaussian_AjkBkQkD< Array >

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

Definition at line 102 of file STK_HDGaussian_AjkBkQkD.h.

Member Typedef Documentation

◆ Base

Constructor & Destructor Documentation

◆ HDGaussian_AjkBkQkD() [1/2]

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

default constructor

Parameters
nbClusternumber of cluster in the model

Definition at line 112 of file STK_HDGaussian_AjkBkQkD.h.

112: Base(nbCluster) {}
DiagGaussianBase< HDGaussian_AjkBkQkDk< Array > > Base

◆ HDGaussian_AjkBkQkD() [2/2]

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

copy constructor

Parameters
modelThe model to copy

Definition at line 116 of file STK_HDGaussian_AjkBkQkD.h.

116: Base(model) {}

◆ ~HDGaussian_AjkBkQkD()

destructor

Definition at line 118 of file STK_HDGaussian_AjkBkQkD.h.

118{}

Member Function Documentation

◆ computeNbFreeParameters()

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

Definition at line 140 of file STK_HDGaussian_AjkBkQkD.h.

141 { return 2*this->nbCluster()*p_data()->sizeCols();}
Array const *const & p_data() const

References STK::HDGaussianBase< HDGaussian_AjkBkQkD< Array > >::nbCluster(), and STK::HDGaussian_AjkBkQkD< Array >::p_data().

◆ lnComponentProbability()

template<class Array >
Real STK::HDGaussian_AjkBkQkD< Array >::lnComponentProbability ( int  i,
int  k 
) const
inline
Returns
the value of the probability of the i-th sample in the k-th component.
Parameters
i,kindexes of the sample and of the component

Definition at line 122 of file STK_HDGaussian_AjkBkQkD.h.

123 {
124 Real sum =0.;
125 for (int j=p_data()->beginCols(); j<p_data()->endCols(); ++j)
126 {
127 if (param_.sigma_[k][j])
128 { sum += Law::Normal::lpdf(p_data()->elt(i,j), param_.mean_[k][j], param_.sigma_[k][j]);}
129 }
130 return sum;
131 }
Parameters param_
parameters of the derived mixture model.
virtual Real lpdf(Real const &x) const
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::Law::Normal::lpdf(), STK::HDGaussian_AjkBkQkD< Array >::p_data(), STK::HDGaussian_AjkBkQkD< Array >::param_, and STK::sum().

◆ p_data()

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

Definition at line 60 of file STK_IMixtureDensity.h.

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

Referenced by STK::HDGaussian_AjkBkQkD< Array >::computeNbFreeParameters(), and STK::HDGaussian_AjkBkQkD< Array >::lnComponentProbability().

◆ randomInit()

template<class Array >
void STK::HDGaussian_AjkBkQkD< 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 149 of file STK_HDGaussian_AjkBkQkD.h.

150{
151 this->randomMean(p_tik);
152 // compute the standard deviation
153 for (int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
154 {
155 param_.sigma_[k] = Stat::varianceWithFixedMean(*p_data(), p_tik->col(k), param_.mean_[k], false).sqrt();
156 }
157#ifdef STK_MIXTURE_VERY_VERBOSE
158 stk_cout << _T("MixtureHDGaussian_ajk_bk_qk_d<Array>::randomInit( CArrayXX const* const& p_tik, CPointX const* const& p_tk) done\n");
159#endif
160}
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
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::HDGaussian_AjkBkQkD< Array >::run ( CArrayXX const *const p_tik,
CPointX const *const p_tk 
)

Compute the weighted mean and the common standard deviation.

Definition at line 164 of file STK_HDGaussian_AjkBkQkD.h.

165{
166 // compute the means
167 if (!this->updateMean(p_tik)) return false;
168 // compute the standard deviation
169 for (int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
170 {
171 param_.sigma_[k] = Stat::varianceWithFixedMean(*p_data(), p_tik->col(k), param_.mean_[k], false).sqrt();
172#ifdef STK_MIXTURE_DEBUG
173 if( (param_.sigma_[k] <= 0).any() )
174 {
175 stk_cout << _T("MixtureHDGaussian_ajk_bk_qk_d::run() failed\n");
176 stk_cout << _T("p_tik->col(") << k << _T(") =\n") << p_tik->col(k).transpose() << _T("\n");
177 stk_cout << _T("param_.mean_[") << k << _T("] =") << param_.mean_[k];
178 stk_cout << _T("param_.sigma_[") << k << _T("] =") << param_.sigma_[k];
179 }
180#endif
181 }
182 return true;
183}
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().

Member Data Documentation

◆ param_

template<class Array >
Parameters STK::IMixtureDensity< Derived >::param_

parameters of the derived mixture model.

Should be an instance of the STK::ModelParameters struct.

See also
STK::ModelParameters

Definition at line 59 of file STK_IMixtureDensity.h.

Referenced by STK::HDGaussian_AjkBkQkD< Array >::lnComponentProbability().


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