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

The diagonal Categorical mixture model Categorical_pjk is the most general diagonal Categorical model and has a probability function of the form. More...

#include <STK_Categorical_pjk.h>

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

Public Types

typedef CategoricalBase< Categorical_pjk< 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_pjk (int nbCluster)
 default constructor
 
 Categorical_pjk (Categorical_pjk const &model)
 copy constructor
 
 ~Categorical_pjk ()
 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 probabilities.
 
int computeNbFreeParameters () const
 
- Public Member Functions inherited from STK::CategoricalBase< Categorical_pjk< 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_pjk< Array > >
typedef IMixtureDensity< Categorical_pjk< Array > > Base
 
- Protected Member Functions inherited from STK::CategoricalBase< Categorical_pjk< 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_pjk< 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_pjk< Array >

The diagonal Categorical mixture model Categorical_pjk is the most general diagonal Categorical model and has a probability 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}^j.
\]

Definition at line 69 of file STK_Categorical_pjk.h.

Member Typedef Documentation

◆ Base

Constructor & Destructor Documentation

◆ Categorical_pjk() [1/2]

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

default constructor

Parameters
nbClusternumber of cluster of the model

Definition at line 80 of file STK_Categorical_pjk.h.

80: Base(nbCluster) {}
CategoricalBase< Categorical_pjk< Array > > Base

◆ Categorical_pjk() [2/2]

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

copy constructor

Parameters
modelmodel to copy

Definition at line 84 of file STK_Categorical_pjk.h.

84: Base(model) {}

◆ ~Categorical_pjk()

destructor

Definition at line 86 of file STK_Categorical_pjk.h.

86{}

Member Function Documentation

◆ computeNbFreeParameters()

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

Definition at line 93 of file STK_Categorical_pjk.h.

94 { return this->nbCluster()*((this->nbModalities_-1).sum());}
PointXi nbModalities_
Array with the number of modalities of each columns of the data set.
Arrays::SumOp< Lhs, Rhs >::result_type sum(Lhs const &lhs, Rhs const &rhs)
convenience function for summing two arrays

References STK::IMixtureDensity< Derived >::nbCluster(), STK::CategoricalBase< Categorical_pjk< Array > >::nbModalities_, and STK::sum().

◆ randomInit()

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

Initialize randomly the parameters of the Categorical mixture.

Definition at line 99 of file STK_Categorical_pjk.h.

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

◆ run()

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

Compute the weighted probabilities.

Definition at line 112 of file STK_Categorical_pjk.h.

113{
114 for (int k = p_tik->beginCols(); k < p_tik->endCols(); ++k)
115 {
116 param_.proba_[k] = 0.;
117 for (int j = p_data()->beginCols(); j < p_data()->endCols(); ++j)
118 {
119 // count the number of modalities weighted by the tik
120 for (int i = p_data()->beginRows(); i < p_data()->endRows(); ++i)
121 { param_.proba_[k](p_data()->elt(i, j), j) += p_tik->elt(i, k);}
122 // normalize the probabilities
123 Real sum = param_.proba_[k].col(j).sum();
124 if (sum) { param_.proba_[k].col(j) /= sum;}
125 }
126 }
127 return true;
128}
double Real
STK fundamental type of Real values.

References STK::ICArray< Derived >::col(), and STK::sum().


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