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

The diagonal Categorical mixture model Categorical_pk is a diagonal Categorical model and has a density function of the form. More...

#include <STK_Categorical_pk.h>

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

Public Types

typedef CategoricalBase< Categorical_pk< 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

 Categorical_pk (int nbCluster)
 default constructor
 
 Categorical_pk (Categorical_pk const &model)
 copy constructor
 
 ~Categorical_pk ()
 destructor
 
void randomInit (CArrayXX const *const &p_tik, CPointX const *const &p_tk)
 Initialize randomly the parameters of the Categorical mixture.
 
bool run (CArrayXX const *const &p_tik, CPointX const *const &p_tk)
 Compute the weighted proportions of each class.
 
int computeNbFreeParameters () const
 
- Public Member Functions inherited from STK::CategoricalBase< Categorical_pk< Array > >
PointXi constnbModalities () const
 
Range constmodalities () const
 
Real proba (int k, int j, int l) const
 
CVectorX proba (int k, int j) const
 
void initializeModelImpl ()
 Initialize the model.
 
Real lnComponentProbability (int i, int k) const
 
int impute (int i, int j, Weights const &tk) const
 
int 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 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.
 
- 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

- Protected Types inherited from STK::CategoricalBase< Categorical_pk< Array > >
typedef IMixtureDensity< Categorical_pk< Array > > Base
 
- Protected Member Functions inherited from STK::CategoricalBase< Categorical_pk< Array > >
 CategoricalBase (int nbCluster)
 default constructor
 
 CategoricalBase (CategoricalBase const &model)
 copy constructor
 
 ~CategoricalBase ()
 destructor
 
Array const *constp_data () const
 
- 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::CategoricalBase< Categorical_pk< Array > >
PointXi nbModalities_
 Array with the number of modalities of each columns of the data set.
 
Range modalities_
 range of the modalities
 
Parameters param_
 parameters of the derived mixture model.
 
- Protected Attributes inherited from STK::IMixtureDensity< Derived >
Parameters param_
 parameters of the derived mixture model.
 

Detailed Description

template<class Array>
class STK::Categorical_pk< Array >

The diagonal Categorical mixture model Categorical_pk is a diagonal Categorical model and has a density function of the form.

\[
 P(\mathbf{x}=(l_1,\ldots,l_d)|\theta) = \sum_{k=1}^K p_k \prod_{j=1}^d p_{kl_j}.
\]

Definition at line 69 of file STK_Categorical_pk.h.

Member Typedef Documentation

◆ Base

Constructor & Destructor Documentation

◆ Categorical_pk() [1/2]

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

default constructor

Parameters
nbClusternumber of cluster in the model

Definition at line 79 of file STK_Categorical_pk.h.

79: Base(nbCluster) {}
CategoricalBase< Categorical_pk< Array > > Base

◆ Categorical_pk() [2/2]

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

copy constructor

Parameters
modelThe model to copy

Definition at line 83 of file STK_Categorical_pk.h.

83: Base(model) {}

◆ ~Categorical_pk()

template<class Array >
STK::Categorical_pk< Array >::~Categorical_pk ( )
inline

destructor

Definition at line 85 of file STK_Categorical_pk.h.

85{}

Member Function Documentation

◆ computeNbFreeParameters()

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

Definition at line 93 of file STK_Categorical_pk.h.

94 { return this->nbCluster()*(this->modalities_.size()-1);}
int size() const
get the size of the TRange (the number of elements).
Definition STK_Range.h:303

References STK::CategoricalBase< Categorical_pk< Array > >::modalities_, STK::IMixtureDensity< Derived >::nbCluster(), and STK::TRange< UnknownSize >::size().

◆ randomInit()

template<class Array >
void STK::Categorical_pk< Array >::randomInit ( CArrayXX const *const p_tik,
CPointX const *const p_tk 
)

Initialize randomly the parameters of the Categorical mixture.

Probabilities will be choosen uniformly.

Definition at line 102 of file STK_Categorical_pk.h.

103{
104 for (int k = p_tik->beginCols(); k < p_tik->endCols(); ++k)
105 {
106 param_.proba_[k].randUnif();
107 param_.proba_[k] /= param_.proba_[k].sum();
108 }
109}
Parameters param_
parameters of the derived mixture model.

◆ run()

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

Compute the weighted proportions of each class.

Definition at line 113 of file STK_Categorical_pk.h.

114{
115 for (int k = p_tik->beginCols(); k < p_tik->endCols(); ++k)
116 {
117 param_.proba_[k] = 0.;
118 for (int j = p_data()->beginCols(); j < p_data()->endCols(); ++j)
119 {
120 for (int i = p_tik->beginRows(); i < p_tik->endRows(); ++i)
121 { param_.proba_[k][(*p_data())(i, j)] += (*p_tik)(i, k);}
122 }
123 Real sum = param_.proba_[k].sum();
124 if (sum<=0.) return false;
125 param_.proba_[k] /= sum;
126 }
127 return true;
128}
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::sum().


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