STK++ 0.9.13
STK::Kmm_s Class Reference

The Gaussian mixture model Kmm_s is an isotrope Gaussian mixture model on a kernel space. More...

#include <STK_Kmm_s.h>

Inheritance diagram for STK::Kmm_s:
Inheritance graph

Public Types

typedef KmmBase< Kmm_sBase
 
- Public Types inherited from STK::KmmBase< Kmm_s >
typedef IMixtureDensity< Kmm_sBase
 
typedef hidden::MixtureTraits< Kmm_s >::Array Array
 
- 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

 Kmm_s (int nbCluster)
 default constructor
 
 Kmm_s (Kmm_s const &model)
 copy constructor
 
 ~Kmm_s ()
 destructor
 
int computeNbFreeParameters () const
 
Real lnComponentProbability (int i, int k) const
 
void randomInit (CArrayXX const *const &p_tik, CPointX const *const &p_tk)
 Initialize randomly the variances of the Gaussian kernel mixture.
 
bool run (CArrayXX const *const &p_tik, CPointX const *const &p_tk)
 update the variances.
 
- Public Member Functions inherited from STK::KmmBase< Kmm_s >
Real sigma2 (int k) const
 
Real dim (int k) const
 
Kernel::IKernel const *const p_kernel () const
 
CArrayXX dik () const
 
void setDim (Real const &dim)
 set the dimensions of the kernel mixture model using an unique value
 
void setDim (ExprBase< Vector > const &dim)
 set the dimension of the kernel mixture model
 
void setKernel (Kernel::IKernel const *p_kernel)
 set the dimensions of the kernel mixture model using an unique value.
 
Real impute (int i, int j, Weights const &pk) const
 
Real rand (int i, int j, int k) const
 
void getParameters (ArrayParam &params) const
 This function is used in order to get the current values of the parameters in an array.
 
void writeParameters (CArrayXX const *p_tik, ostream &os) const
 This function can be used to write summary of parameters to the output stream.
 
int nbSample () const
 
int nbCluster () 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::KmmBase< Kmm_s >
Parameters param_
 parameters of the derived mixture model.
 
- Protected Member Functions inherited from STK::KmmBase< Kmm_s >
 KmmBase (int nbCluster)
 default constructor
 
 KmmBase (KmmBase const &model)
 copy constructor
 
 ~KmmBase ()
 destructor
 
void initializeModel ()
 Initialize the model before its first use.
 
void compute_dik (CArrayXX const *p_tik, CPointX const *p_tk)
 compute the distance of the ith individual to the kth centroid
 
void initializeModelImpl ()
 default implementation of initializeModelImpl (do nothing)
 
- 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::KmmBase< Kmm_s >
Kernel::IKernel constp_kernel_
 pointer on the kernel
 
CArrayXX dik_
 Array of the intermediate results dik.
 
- Protected Attributes inherited from STK::IMixtureDensity< Derived >
Parameters param_
 parameters of the derived mixture model.
 

Detailed Description

The Gaussian mixture model Kmm_s is an isotrope Gaussian mixture model on a kernel space.

It has a density function of the form

\[
 f(\mathbf{x}|\theta) = \sum_{k=1}^K p_k
   \sum_{k=1}^K p_k \left(\frac{1}{\sqrt{2\pi}\sigma}\right)^{d_k}
   \exp\left\{ -\frac{\|\phi(x)-m_k\|^2}{2\sigma^2}  \right\}
\]

where $ \phi $ denote a feature mapping from the original space to an RKHS.

In a Kmm_s model, the data set refer to the Gram's matrix.

Definition at line 73 of file STK_Kmm_s.h.

Member Typedef Documentation

◆ Base

Definition at line 76 of file STK_Kmm_s.h.

Constructor & Destructor Documentation

◆ Kmm_s() [1/2]

STK::Kmm_s::Kmm_s ( int  nbCluster)

default constructor

Parameters
nbClusternumber of cluster in the model

Definition at line 48 of file STK_Kmm_s.cpp.

48: Base(nbCluster) {}
KmmBase< Kmm_s > Base
Definition STK_Kmm_s.h:76

◆ Kmm_s() [2/2]

STK::Kmm_s::Kmm_s ( Kmm_s const model)

copy constructor

Parameters
modelThe model to copy

Definition at line 52 of file STK_Kmm_s.cpp.

52: Base(model) {}

◆ ~Kmm_s()

STK::Kmm_s::~Kmm_s ( )

destructor

Definition at line 54 of file STK_Kmm_s.cpp.

54{}

Member Function Documentation

◆ computeNbFreeParameters()

int STK::Kmm_s::computeNbFreeParameters ( ) const
Returns
the number of free parameters of the model

Definition at line 56 of file STK_Kmm_s.cpp.

57{ return param_.dim_.sum() + 1;}
Parameters param_
parameters of the derived mixture model.

References STK::KmmBase< Kmm_s >::param_.

◆ lnComponentProbability()

Real STK::Kmm_s::lnComponentProbability ( int  i,
int  k 
) const
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 62 of file STK_Kmm_s.cpp.

63{
64 return(- dik_.elt(i,k)/(2.*param_.sigma2_)
65 - (std::log(param_.sigma2_)+2.*Const::_LNSQRT2PI_)*param_.dim_[k]/2.);
66}
CArrayXX dik_
Array of the intermediate results dik.

References STK::KmmBase< Kmm_s >::dik_, and STK::KmmBase< Kmm_s >::param_.

◆ randomInit()

void STK::Kmm_s::randomInit ( CArrayXX const *const p_tik,
CPointX const *const p_tk 
)

Initialize randomly the variances of the Gaussian kernel mixture.

Definition at line 69 of file STK_Kmm_s.cpp.

70{
71#if STK_Kernel_DEBUG | STK_MIXTURE_VERBOSE
72 stk_cout << _T("Entering Kmm_s::randomInit( CArrayXX const* const& p_tik, CPointX const* const& p_tk)\n");
73#endif
74 // compute the standard deviation
75 compute_dik(p_tik, p_tk);
76 param_.sigma2_ = dik_.prod(*p_tik).sum()/(this->nbSample() * param_.dim_.sum())
77 + std::abs(Law::generator.randGauss(0, 0.05));
78#ifdef STK_MIXTURE_VERBOSE
79 stk_cout << _T("Kmm_s::randomInit( CArrayXX const* const& p_tik, CPointX const* const& p_tk) done\n");
80 stk_cout << param_.sigma2_ << "\n";
81#endif
82}
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
hidden::OperatorSelector< Derived, Rhs, Arrays::productOp_ >::Result const prod(ExprBase< Rhs > const &other) const
void compute_dik(CArrayXX const *p_tik, CPointX const *p_tk)
compute the distance of the ith individual to the kth centroid

References _T, STK::KmmBase< Kmm_s >::compute_dik(), STK::KmmBase< Kmm_s >::dik_, STK::KmmBase< Kmm_s >::nbSample(), STK::KmmBase< Kmm_s >::param_, STK::ExprBase< Derived >::prod(), and stk_cout.

◆ run()

bool STK::Kmm_s::run ( CArrayXX const *const p_tik,
CPointX const *const p_tk 
)

update the variances.

Definition at line 85 of file STK_Kmm_s.cpp.

86{
87#if STK_Kernel_DEBUG | STK_MIXTURE_VERBOSE
88 stk_cout << _T("Entering Kmm_s::run( CArrayXX const* const& p_tik, CPointX const* const& p_tk)\n");
89#endif
90 compute_dik(p_tik, p_tk);
91 param_.sigma2_ = p_tik->prod(dik_).sum()/p_tk->dot(param_.dim_);
92#ifdef STK_MIXTURE_VERBOSE
93 stk_cout << _T("Kmm_s::run( CArrayXX const* const& p_tik, CPointX const* const& p_tk) done\n");
94 stk_cout << param_.sigma2_ << "\n";
95#endif
96 return (param_.sigma2_ <= 0.) ? false : true;
97}

References _T, STK::KmmBase< Kmm_s >::compute_dik(), STK::KmmBase< Kmm_s >::dik_, STK::ExprBase< Derived >::dot(), STK::KmmBase< Kmm_s >::param_, STK::ExprBase< Derived >::prod(), and stk_cout.


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