STK++ 0.9.13
STK::Kmm_sk Class Reference

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

#include <STK_Kmm_sk.h>

Inheritance diagram for STK::Kmm_sk:
Inheritance graph

Public Types

typedef KmmBase< Kmm_skBase
 
- Public Types inherited from STK::KmmBase< Kmm_sk >
typedef IMixtureDensity< Kmm_skBase
 
typedef hidden::MixtureTraits< Kmm_sk >::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_sk (int nbCluster)
 default constructor
 
 Kmm_sk (Kmm_sk const &model)
 copy constructor
 
 ~Kmm_sk ()
 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_sk >
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_sk >
Parameters param_
 parameters of the derived mixture model.
 
- Protected Member Functions inherited from STK::KmmBase< Kmm_sk >
 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_sk >
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_sk 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_k}\right)^{d_k}
   \exp\left\{ -\frac{\|\phi(x)-m_k\|^2}{2\sigma_k^2} \right\}
\]

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

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

Definition at line 75 of file STK_Kmm_sk.h.

Member Typedef Documentation

◆ Base

Definition at line 78 of file STK_Kmm_sk.h.

Constructor & Destructor Documentation

◆ Kmm_sk() [1/2]

STK::Kmm_sk::Kmm_sk ( int  nbCluster)

default constructor

Parameters
nbClusternumber of cluster in the model

Definition at line 50 of file STK_Kmm_sk.cpp.

50: Base(nbCluster) {}
KmmBase< Kmm_sk > Base
Definition STK_Kmm_sk.h:78

◆ Kmm_sk() [2/2]

STK::Kmm_sk::Kmm_sk ( Kmm_sk const model)

copy constructor

Parameters
modelThe model to copy

Definition at line 54 of file STK_Kmm_sk.cpp.

54: Base(model) {}

◆ ~Kmm_sk()

STK::Kmm_sk::~Kmm_sk ( )

destructor

Definition at line 56 of file STK_Kmm_sk.cpp.

56{}

Member Function Documentation

◆ computeNbFreeParameters()

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

Definition at line 58 of file STK_Kmm_sk.cpp.

59{ return param_.dim_.sum() + this->nbCluster();}
Parameters param_
parameters of the derived mixture model.

References STK::KmmBase< Kmm_sk >::nbCluster(), and STK::KmmBase< Kmm_sk >::param_.

◆ lnComponentProbability()

Real STK::Kmm_sk::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 64 of file STK_Kmm_sk.cpp.

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

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

◆ randomInit()

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

Initialize randomly the variances of the Gaussian kernel mixture.

Definition at line 71 of file STK_Kmm_sk.cpp.

72{
73#if STK_Kernel_DEBUG | STK_MIXTURE_VERBOSE
74 stk_cout << _T("Entering Kmm_sk::randomInit( CArrayXX const* const& p_tik, CPointX const* const& p_tk)\n");
75#endif
76 compute_dik(p_tik, p_tk);
77 param_.sigma2_ = sum( dik_.prod(*p_tik) )/ (*p_tk * param_.dim_)
78 + CPointX(p_tik->cols()).rand(Law::Normal(0, 0.05)).abs();
79#ifdef STK_MIXTURE_VERY_VERBOSE
80 stk_cout << _T("Kmm_sk::randomInit( CArrayXX const* const& p_tik, CPointX const* const& p_tk) done\n");
81 stk_cout << param_.sigma2_ << "\n";
82#endif
83}
#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
Real rand(int i, int j, int k) const
Arrays::SumOp< Lhs, Rhs >::result_type sum(Lhs const &lhs, Rhs const &rhs)
convenience function for summing two arrays
CArrayPoint< Real, UnknownSize, Arrays::by_col_ > CPointX

References _T, STK::KmmBase< Kmm_sk >::compute_dik(), STK::KmmBase< Kmm_sk >::dik_, STK::KmmBase< Kmm_sk >::param_, STK::ExprBase< Derived >::prod(), STK::KmmBase< Kmm_sk >::rand(), stk_cout, and STK::sum().

◆ run()

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

update the variances.

Definition at line 86 of file STK_Kmm_sk.cpp.

87{
88#if STK_Kernel_DEBUG | STK_MIXTURE_VERBOSE
89 stk_cout << _T("Entering Kmm_sk::run( CArrayXX const* const& p_tik, CPointX const* const& p_tk)\n");
90#endif
91 compute_dik(p_tik, p_tk);
92#ifdef STK_Kernel_DEBUG
93 stk_cout<< _T("Stat::sumByCol( dik_.prod(*p_tik) ) =\n") << Stat::sumByCol( dik_.prod(*p_tik) ) << "\n";
94#endif
95 param_.sigma2_ = Stat::sumByCol( p_tik->prod(dik_) ) / (p_tk->prod(param_.dim_));
96#ifdef STK_MIXTURE_VERBOSE
97 stk_cout << _T("Kmm_sk::run( CArrayXX const* const& p_tik, CPointX const* const& p_tk) done\n");
98 stk_cout << _T("sigma2 = ") << param_.sigma2_ << "\n";
99#endif
100 return true;
101}
hidden::FunctorTraits< Derived, SumOp >::Row sumByCol(Derived const &A)

References _T, STK::KmmBase< Kmm_sk >::compute_dik(), STK::KmmBase< Kmm_sk >::dik_, STK::KmmBase< Kmm_sk >::param_, STK::ExprBase< Derived >::prod(), stk_cout, and STK::Stat::sumByCol().


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