STK++ 0.9.13
STK::MixtureComposer Class Reference

Main class for handling composed mixture models. More...

#include <STK_MixtureComposer.h>

Inheritance diagram for STK::MixtureComposer:
Inheritance graph

Public Types

typedef std::vector< IMixture * >::const_iterator ConstMixtIterator
 
typedef std::vector< IMixture * >::iterator MixtIterator
 
- Public Types inherited from STK::IMixtureStatModel
typedef std::vector< IMixture * >::const_iterator ConstMixtIterator
 
typedef std::vector< IMixture * >::iterator MixtIterator
 

Public Member Functions

 MixtureComposer (int nbSample, int nbCluster)
 Constructor.
 
 MixtureComposer (MixtureComposer const &composer)
 copy constructor.
 
virtual ~MixtureComposer ()
 The registered mixtures will be deleted there.
 
virtual MixtureComposercreate () const
 Create a composer, but reinitialize the mixtures parameters.
 
virtual MixtureComposerclone () const
 Create a clone of the current model, with mixtures parameters preserved.
 
virtual Real lnComponentProbability (int i, int k) const
 
virtual void writeParameters (ostream &os) const
 write the parameters of the model in the stream os.
 
virtual void randomInit ()
 initialize randomly the parameters of the components of the model
 
virtual void paramUpdateStep ()
 Compute the proportions and the model parameters given the current tik mixture parameters.
 
virtual void imputationStep ()
 Impute the missing values.
 
virtual void samplingStep ()
 Simulation of all the latent variables and/or missing data excluding class labels.
 
virtual void storeIntermediateResults (int iteration)
 This step can be used to signal to the mixtures that they must store results.
 
virtual void releaseIntermediateResults ()
 This step can be used to signal to the mixtures that they must release the stored results.
 
virtual void setParametersStep ()
 Utility method allowing to signal to a mixture to set its parameters.
 
virtual void finalizeStep ()
 This step can be used by developer to finalize any thing.
 
- Public Member Functions inherited from STK::IMixtureComposer
virtual ~IMixtureComposer ()
 destructor
 
Clust::modelState state () const
 
void setState (Clust::modelState state)
 set the state of the model : should be used by any strategy
 
virtual int cStep ()
 Replace tik by zik.
 
virtual int sStep ()
 Simulate zi accordingly to tik and replace tik by zik by calling cStep().
 
virtual Real eStep ()
 compute the zi, the lnLikelihood of the current estimates and the next value of the tik.
 
virtual void mapStep ()
 Compute zi using the Map estimate.
 
virtual void pStep ()
 Compute proportions using the ML estimates, default implementation.
 
virtual void initializeStep ()
 Initialize the model before its first use.
 
void randomClassInit ()
 Initialize randomly the labels zi of the model.
 
void randomFuzzyInit ()
 Initialize randomly the posterior probabilities tik of the model, then compute the zi values with mapStep, compute the initial parameter values using paramUpdateStep, and compute the tik using eStep().
 
- Public Member Functions inherited from STK::IMixtureStatModel
virtual ~IMixtureStatModel ()
 destructor
 
int nbCluster () const
 
CPointX constpk () const
 
CArrayXX consttik () const
 
CPointX consttk () const
 
CVectorXi constzi () const
 
std::vector< IMixture * > constv_mixtures () const
 
Real computeLnLikelihood (int i) const
 
Real computeLikelihood (int i) const
 
Real computeLnLikelihood () const
 
Real computeICL () const
 
IMixturegetMixture (String const &idData) const
 Utility lookup function allowing to find a Mixture from its idData.
 
void registerMixture (IMixture *p_mixture)
 register a mixture to the composer.
 
void releaseMixture (String const &idData)
 release a mixture from the composer.
 
int computeNbFreeParameters () const
 compute the number of free parameters of the model.
 
int computeNbMissingValues () const
 compute the missing values of the model.
 
template<class Array >
void setMixtureParameters (Array const &tik)
 set the mixture parameters using an array of posterior probabilities.
 
template<class Array , class RowVector >
void setMixtureParameters (Array const &tik, RowVector const &pk)
 set the mixture parameters giving the posterior probabilities and the proportions.
 
template<class RowVector >
void setProportions (RowVector const &pk)
 Set proportions of each classes.
 
template<class Manager , class Parameters >
void setParameters (IMixtureManager< Manager > const &manager, String const &idData, Parameters const &param)
 Utility method allowing to set the parameters to a specific mixture.
 
template<class Manager >
void createMixture (IMixtureManager< Manager > &manager)
 Utility method allowing to create all the mixtures registered in the data handler of a mixture manager and to register them.
 
template<class Manager >
IMixturecreateMixture (IMixtureManager< Manager > &manager, String const &idData)
 Utility method allowing to create a mixture with a given data set and register it.
 
template<class Manager >
void removeMixture (IMixtureManager< Manager > &manager, String const &idData)
 Utility method allowing to release completely a mixture with its data set.
 
template<class Manager , class Parameters >
void getParameters (IMixtureManager< Manager > const &manager, String const &idData, Parameters &param) const
 Utility method allowing to get the parameters of a specific mixture.
 
template<class Manager , class MissingValues >
void getMissingValues (IMixtureManager< Manager > const &manager, String const &idData, MissingValues &missing) const
 Utility method allowing to get the missing values of a specific mixture.
 
template<class DataHandler >
void createMixture (IMixtureManager< DataHandler > &manager)
 
- Public Member Functions inherited from STK::IStatModelBase
int nbSample () const
 
Real lnNbSample () const
 
int nbVariable () const
 
Real lnLikelihood () const
 
Real likelihood () const
 
int nbFreeParameter () const
 
Real computeBIC () const
 
Real computeAIC () const
 
Real computeML () const
 

Protected Member Functions

void createComposer (std::vector< IMixture * > const &v_mixtures_)
 Create the composer using existing data handler and mixtures.
 
- Protected Member Functions inherited from STK::IMixtureComposer
 IMixtureComposer (int nbSample, int nbCluster)
 Constructor.
 
 IMixtureComposer (IMixtureComposer const &model)
 copy constructor.
 
void sStep (int i)
 Simulate zi accordingly to tik.
 
void cStep (int i)
 Replace tik by zik.
 
Real eStep (int i)
 compute one zi and the next value of the tik for i fixed
 
void mapStep (int i)
 Compute zi using the Map estimate for i fixed.
 
virtual void initializeMixtureParameters ()
 Create the mixture model parameters pk_ and tik_.
 
virtual int randomTik ()
 generate random tik_
 
virtual int randomZi ()
 generate random zi_
 
- Protected Member Functions inherited from STK::IMixtureStatModel
 IMixtureStatModel (int nbSample, int nbCluster)
 Constructor.
 
 IMixtureStatModel (IMixtureStatModel const &model)
 copy constructor.
 
void setNbCluster (int nbCluster)
 set the number of cluster of the model
 
- Protected Member Functions inherited from STK::IStatModelBase
 IStatModelBase ()
 Default constructor.
 
 IStatModelBase (int nbSample)
 Constructor with specified dimension.
 
 IStatModelBase (int nbSample, int nbVariable)
 Constructor with specified dimension.
 
 IStatModelBase (IStatModelBase const &model)
 Copy constructor.
 
 ~IStatModelBase ()
 destructor
 
void setNbFreeParameter (int const &nbFreeParameter)
 set the number of free parameters of the model
 
void setNbSample (int const &nbSample)
 set the number of samples of the model
 
void setNbVariable (int const &nbVariable)
 set the number of variables of the model
 
void setLnLikelihood (Real const &lnLikelihood)
 set the log-likelihood of the model
 
void initialize (int nbSample, int nbVariable)
 set the dimensions of the parameters of the model
 

Protected Attributes

Real meanlnLikelihood_
 averaged lnLikelihood values.
 
- Protected Attributes inherited from STK::IMixtureStatModel
int nbCluster_
 number of cluster.
 
CPointX pk_
 The proportions of each mixtures.
 
CArrayXX tik_
 The tik probabilities.
 
CPointX tk_
 The sum of the columns of tik_.
 
CVectorXi zi_
 The zi class label.
 
std::vector< IMixture * > v_mixtures_
 vector of pointers to the mixtures components
 

Detailed Description

Main class for handling composed mixture models.

A composed mixture model on some composed space $  \mathbb{X} = \subset \mathcal{X}^1\times \ldots  \times \mathcal{X}^L $ is a density of the form

\[
    f(\mathbf{x}|\boldsymbol{\theta})
    = \sum_{k=1}^K p_k \prod_{l=1}^L f^l(\mathbf{x}^l;\boldsymbol{\lambda}^l_k,\boldsymbol{\alpha}^l)
    \quad \mathbf{x} \in \mathbb{X}.
\]

The $ p_k > 0$ with $ \sum_{k=1}^K p_k =1$ are the mixing proportions. The density f is called the component of the model. The parameters $\boldsymbol{\lambda}^l_k, \, k=1,\ldots K $ are the cluster specific parameters and the parameters $ \boldsymbol{\alpha}^l $ are the shared parameters.

The MixtureComposer class is a final class implementing the features requested by the interface class IMixtureComposer.

It uses injection dependency in order to create/release mixture and get/set parameters of a mixture. The class responsible of the injection is derived from an STK::IMixtureManager.

See also
IMixtureComposer, IMixtureManager, PoissonMixtureManager, DiagGaussianMixtureManager, GammaMixtureManager, CategoricalMixtureManager

Definition at line 69 of file STK_MixtureComposer.h.

Member Typedef Documentation

◆ ConstMixtIterator

Definition at line 72 of file STK_MixtureComposer.h.

◆ MixtIterator

Definition at line 73 of file STK_MixtureComposer.h.

Constructor & Destructor Documentation

◆ MixtureComposer() [1/2]

STK::MixtureComposer::MixtureComposer ( int  nbSample,
int  nbCluster 
)

Constructor.

Parameters
nbCluster,nbSamplenumber of clusters and samples.

Definition at line 45 of file STK_MixtureComposer.cpp.

IMixtureComposer(int nbSample, int nbCluster)
Constructor.
void setNbFreeParameter(int const &nbFreeParameter)
set the number of free parameters of the model
Real meanlnLikelihood_
averaged lnLikelihood values.

References STK::IMixtureStatModel::nbCluster(), and STK::IStatModelBase::setNbFreeParameter().

◆ MixtureComposer() [2/2]

STK::MixtureComposer::MixtureComposer ( MixtureComposer const composer)

copy constructor.

Parameters
composerthe composer to copy

Definition at line 53 of file STK_MixtureComposer.cpp.

54 : IMixtureComposer(composer)
55 , meanlnLikelihood_(composer.meanlnLikelihood_)
56{}

◆ ~MixtureComposer()

STK::MixtureComposer::~MixtureComposer ( )
virtual

The registered mixtures will be deleted there.

Definition at line 59 of file STK_MixtureComposer.cpp.

59{}

Member Function Documentation

◆ clone()

MixtureComposer * STK::MixtureComposer::clone ( ) const
virtual

Create a clone of the current model, with mixtures parameters preserved.

Implements STK::IMixtureComposer.

Reimplemented in STK::MixtureComposerFixedProp, STK::MixtureSemiLearner, and STK::MixtureSemiLearnerFixedProp.

Definition at line 62 of file STK_MixtureComposer.cpp.

63{ return new MixtureComposer(*this);}
MixtureComposer(int nbSample, int nbCluster)
Constructor.

◆ create()

MixtureComposer * STK::MixtureComposer::create ( ) const
virtual

Create a composer, but reinitialize the mixtures parameters.

Implements STK::IMixtureComposer.

Reimplemented in STK::MixtureComposerFixedProp, STK::MixtureSemiLearner, and STK::MixtureSemiLearnerFixedProp.

Definition at line 65 of file STK_MixtureComposer.cpp.

66{
67 // set dimensions
68 MixtureComposer* p_composer = new MixtureComposer(nbSample(), nbCluster());
69 p_composer->createComposer( v_mixtures_);
70 return p_composer;
71}
std::vector< IMixture * > v_mixtures_
vector of pointers to the mixtures components

References createComposer(), STK::IMixtureStatModel::nbCluster(), STK::IStatModelBase::nbSample(), and STK::IMixtureStatModel::v_mixtures_.

◆ createComposer()

void STK::MixtureComposer::createComposer ( std::vector< IMixture * > const v_mixtures_)
protected

Create the composer using existing data handler and mixtures.

This method is essentially used by the create() method and can be reused in derived classes.

See also
MixtureComposerFixedProp

Definition at line 190 of file STK_MixtureComposer.cpp.

191{
192 v_mixtures_.resize( v_mixtures.size());
193 for (size_t l = 0; l < v_mixtures_.size(); ++l)
194 {
195 v_mixtures_[l] = v_mixtures[l]->create();
196 v_mixtures_[l]->setMixtureModel(this);
197 }
199}
virtual void initializeStep()
Initialize the model before its first use.
std::vector< IMixture * > const & v_mixtures() const

References STK::IMixtureComposer::initializeStep(), STK::IMixtureStatModel::v_mixtures(), and STK::IMixtureStatModel::v_mixtures_.

Referenced by create(), STK::MixtureComposerFixedProp::create(), STK::MixtureSemiLearner::create(), and STK::MixtureSemiLearnerFixedProp::create().

◆ finalizeStep()

void STK::MixtureComposer::finalizeStep ( )
virtual

This step can be used by developer to finalize any thing.

It will be called only once after we finish running the estimation algorithm.

Reimplemented from STK::IMixtureComposer.

Definition at line 181 of file STK_MixtureComposer.cpp.

182{
183 for (MixtIterator it = v_mixtures_.begin(); it != v_mixtures_.end(); ++it)
184 { (*it)->finalizeStep();}
185}
std::vector< IMixture * >::iterator MixtIterator

References STK::IRegression< YArray, XArray, Weights >::finalizeStep(), and STK::IMixtureStatModel::v_mixtures_.

◆ imputationStep()

void STK::MixtureComposer::imputationStep ( )
virtual

Impute the missing values.

Reimplemented from STK::IMixtureStatModel.

Definition at line 134 of file STK_MixtureComposer.cpp.

135{
136 for (MixtIterator it = v_mixtures_.begin(); it != v_mixtures_.end(); ++it)
137 { (*it)->imputationStep();}
138}

References STK::IMixtureStatModel::v_mixtures_.

◆ lnComponentProbability()

Real STK::MixtureComposer::lnComponentProbability ( int  i,
int  k 
) const
virtual
Returns
the value of the probability of the i-th sample in the k-th component.
Parameters
i,kindexes of the sample and components

Implements STK::IMixtureStatModel.

Definition at line 73 of file STK_MixtureComposer.cpp.

74{
75 Real sum=0.0;
76 for (ConstMixtIterator it = v_mixtures_.begin() ; it != v_mixtures_.end(); ++it)
77 { sum += (*it)->lnComponentProbability(i,k);}
78 return sum;
79}
std::vector< IMixture * >::const_iterator ConstMixtIterator
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(), and STK::IMixtureStatModel::v_mixtures_.

Referenced by STK::MixtureSemiLearner::eStep().

◆ paramUpdateStep()

void STK::MixtureComposer::paramUpdateStep ( )
virtual

Compute the proportions and the model parameters given the current tik mixture parameters.

Implements STK::IMixtureComposer.

Definition at line 81 of file STK_MixtureComposer.cpp.

82{
83#ifdef STK_MIXTURE_VERY_VERBOSE
84 stk_cout << _T("Entering MixtureComposer::paramUpdateStep()\n");
85#endif
86 for (MixtIterator it = v_mixtures_.begin() ; it != v_mixtures_.end(); ++it)
87 { (*it)->paramUpdateStep();}
88#ifdef STK_MIXTURE_VERY_VERBOSE
89 stk_cout << _T("MixtureComposer::paramUpdateStep() done\n");
90#endif
91}
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.

References _T, stk_cout, and STK::IMixtureStatModel::v_mixtures_.

◆ randomInit()

void STK::MixtureComposer::randomInit ( )
virtual

initialize randomly the parameters of the components of the model

Implements STK::IMixtureComposer.

Definition at line 110 of file STK_MixtureComposer.cpp.

111{
112#ifdef STK_MIXTURE_VERBOSE
113 stk_cout << _T("Entering MixtureComposer::RandomInit()\n");
114#endif
115 // in case the mixture is not initialized
117 // create random tik
119 // compute zi
120 mapStep();
121 // set random values to the parameters of the model
122 for (MixtIterator it = v_mixtures_.begin(); it != v_mixtures_.end(); ++it)
123 { (*it)->randomInit();}
124 // perform eStep
125 eStep();
126 // update state of the model
128#ifdef STK_MIXTURE_VERBOSE
129 stk_cout << _T("MixtureComposer::RandomInit() done\n");
130#endif
131}
void setState(Clust::modelState state)
set the state of the model : should be used by any strategy
virtual Real eStep()
compute the zi, the lnLikelihood of the current estimates and the next value of the tik.
virtual void mapStep()
Compute zi using the Map estimate.
Clust::modelState state() const
virtual int randomTik()
generate random tik_
@ modelInitialized_
the model is initialized and its parameters are initialized to default values
@ modelParamInitialized_
The parameters of the model have been initialized.

References _T, STK::IMixtureComposer::eStep(), STK::IMixtureComposer::initializeStep(), STK::IMixtureComposer::mapStep(), STK::Clust::modelInitialized_, STK::Clust::modelParamInitialized_, STK::Clust::randomParamInitFail_, STK::IMixtureComposer::randomTik(), STK::IMixtureComposer::setState(), STK::IMixtureComposer::state(), stk_cout, and STK::IMixtureStatModel::v_mixtures_.

◆ releaseIntermediateResults()

void STK::MixtureComposer::releaseIntermediateResults ( )
virtual

This step can be used to signal to the mixtures that they must release the stored results.

This is usually called if the estimation process failed.

Reimplemented from STK::IMixtureStatModel.

Definition at line 164 of file STK_MixtureComposer.cpp.

165{
166 for (MixtIterator it = v_mixtures_.begin(); it != v_mixtures_.end(); ++it)
167 { (*it)->releaseIntermediateResults();}
169}

References meanlnLikelihood_, and STK::IMixtureStatModel::v_mixtures_.

◆ samplingStep()

void STK::MixtureComposer::samplingStep ( )
virtual

Simulation of all the latent variables and/or missing data excluding class labels.

Reimplemented from STK::IMixtureStatModel.

Definition at line 143 of file STK_MixtureComposer.cpp.

144{
145#ifdef STK_MIXTURE_VERY_VERBOSE
146 stk_cout << _T("Entering MixtureComposer::samplingStep()\n");
147#endif
148
149 for (MixtIterator it = v_mixtures_.begin(); it != v_mixtures_.end(); ++it)
150 { (*it)->samplingStep();}
151#ifdef STK_MIXTURE_VERY_VERBOSE
152 stk_cout << _T("MixtureComposer::samplingStep() done\n");
153#endif
154}

References _T, stk_cout, and STK::IMixtureStatModel::v_mixtures_.

◆ setParametersStep()

void STK::MixtureComposer::setParametersStep ( )
virtual

Utility method allowing to signal to a mixture to set its parameters.

It will be called once enough intermediate results have been stored.

Reimplemented from STK::IMixtureStatModel.

Definition at line 172 of file STK_MixtureComposer.cpp.

173{
174 for (MixtIterator it = v_mixtures_.begin(); it != v_mixtures_.end(); ++it)
175 { (*it)->setParametersStep();}
178}
void setLnLikelihood(Real const &lnLikelihood)
set the log-likelihood of the model

References meanlnLikelihood_, STK::IStatModelBase::setLnLikelihood(), and STK::IMixtureStatModel::v_mixtures_.

◆ storeIntermediateResults()

void STK::MixtureComposer::storeIntermediateResults ( int  iteration)
virtual

This step can be used to signal to the mixtures that they must store results.

This is usually called after a burn-in phase. The composer store the current value of the log-Likelihood.

Reimplemented from STK::IMixtureStatModel.

Definition at line 157 of file STK_MixtureComposer.cpp.

158{
159 for (MixtIterator it = v_mixtures_.begin(); it != v_mixtures_.end(); ++it)
160 { (*it)->storeIntermediateResults(iteration);}
162}

References STK::IStatModelBase::lnLikelihood(), meanlnLikelihood_, and STK::IMixtureStatModel::v_mixtures_.

◆ writeParameters()

void STK::MixtureComposer::writeParameters ( ostream os) const
virtual

write the parameters of the model in the stream os.

Reimplemented from STK::IMixtureStatModel.

Definition at line 93 of file STK_MixtureComposer.cpp.

94{
95 os << _T("nbSample = ") << nbSample() << std::endl;
96 os << _T("nbCluster = ") << nbCluster() << std::endl;
97 os << _T("nbFreeParameter = ") << nbFreeParameter() << std::endl;
98 os << _T("nbMissingValues = ") << computeNbMissingValues() << std::endl;
99 os << _T("lnLikelihood = ") << lnLikelihood() << std::endl;
100 os << _T("v_mixtures_.size() = ") << v_mixtures_.size() << std::endl;
101 os << _T("proportions = ") << pk();
102
103 for (ConstMixtIterator it = v_mixtures_.begin(); it != v_mixtures_.end(); ++it)
104 {
105 os << _T("\nParameters of the mixture: ") << (*it)->idData() << _T("\n");
106 (*it)->writeParameters(os);
107 }
108}
int computeNbMissingValues() const
compute the missing values of the model.
CPointX const & pk() const

References _T, STK::IMixtureStatModel::computeNbMissingValues(), STK::IStatModelBase::lnLikelihood(), STK::IMixtureStatModel::nbCluster(), STK::IStatModelBase::nbFreeParameter(), STK::IStatModelBase::nbSample(), STK::IMixtureStatModel::pk(), and STK::IMixtureStatModel::v_mixtures_.

Member Data Documentation

◆ meanlnLikelihood_

Real STK::MixtureComposer::meanlnLikelihood_
protected

averaged lnLikelihood values.

Will be used by the storeIntermediateResults method.

Definition at line 138 of file STK_MixtureComposer.h.

Referenced by releaseIntermediateResults(), setParametersStep(), and storeIntermediateResults().


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