STK++ 0.9.13
STK::MixtureLearner Class Reference

Main class for learning mixture models. More...

#include <STK_MixtureLearner.h>

Inheritance diagram for STK::MixtureLearner:
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

 MixtureLearner (int nbSample, int nbCluster)
 Constructor.
 
 MixtureLearner (MixtureLearner const &composer)
 copy constructor.
 
virtual ~MixtureLearner ()
 The registered mixtures will be deleted there.
 
virtual MixtureLearnercreate () const
 Create a composer, but reinitialize the mixtures parameters.
 
virtual MixtureLearnerclone () 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 model parameters given the current imputed/simulated missing values.
 
virtual void imputationStep ()
 Impute the data missing values.
 
virtual void samplingStep ()
 Simulation of all the data missing values.
 
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::IMixtureLearner
virtual ~IMixtureLearner ()
 destructor
 
CVectorXi constziPred () const
 
Clust::modelState state () const
 
void setState (Clust::modelState state)
 set the state of the model : should be used by any strategy
 
virtual void mapStep ()
 Compute ziPred using the Map estimate.
 
template<class ColVector >
void setClassLabels (ColVector const &zi)
 set the mixture parameters using the given class labels.
 
template<class ColVector , class RowVector >
void setClassLabels (ColVector const &zi, RowVector const &pk)
 set the mixture parameters using the class labels and giving the proportions.
 
- 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.
 
virtual void initializeStep ()
 Initialize the model before at its first use.
 
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 createLearner (std::vector< IMixture * > const &v_mixtures_)
 Create the composer using existing data handler and mixtures.
 
- Protected Member Functions inherited from STK::IMixtureLearner
 IMixtureLearner (int nbSample, int nbCluster)
 Constructor.
 
 IMixtureLearner (IMixtureLearner const &model)
 copy constructor.
 
- 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
 

Private Attributes

Real meanlnLikelihood_
 averaged lnLikelihood values.
 

Additional Inherited Members

- 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 learning 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 MixtureLearner class is a final class implementing the features requested by the interface class IMixtureLearner.

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
IMixtureLearner, IMixtureManager

Definition at line 70 of file STK_MixtureLearner.h.

Member Typedef Documentation

◆ ConstMixtIterator

Definition at line 73 of file STK_MixtureLearner.h.

◆ MixtIterator

Definition at line 74 of file STK_MixtureLearner.h.

Constructor & Destructor Documentation

◆ MixtureLearner() [1/2]

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

Constructor.

Parameters
nbCluster,nbSamplenumber of clusters and samples.

Definition at line 46 of file STK_MixtureLearner.cpp.

IMixtureLearner(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().

◆ MixtureLearner() [2/2]

STK::MixtureLearner::MixtureLearner ( MixtureLearner const composer)

copy constructor.

Parameters
composerthe composer to copy

Definition at line 54 of file STK_MixtureLearner.cpp.

55 : IMixtureLearner(learner)
56 , meanlnLikelihood_(learner.meanlnLikelihood_)
57{}

◆ ~MixtureLearner()

STK::MixtureLearner::~MixtureLearner ( )
virtual

The registered mixtures will be deleted there.

Definition at line 59 of file STK_MixtureLearner.cpp.

59{}

Member Function Documentation

◆ clone()

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

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

Implements STK::IMixtureStatModel.

Definition at line 62 of file STK_MixtureLearner.cpp.

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

◆ create()

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

Create a composer, but reinitialize the mixtures parameters.

Implements STK::IMixtureStatModel.

Definition at line 65 of file STK_MixtureLearner.cpp.

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

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

◆ createLearner()

void STK::MixtureLearner::createLearner ( 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
MixtureLearnerFixedProp

Definition at line 167 of file STK_MixtureLearner.cpp.

168{
169 initialize(nbSample(), 0);
170 v_mixtures_.resize( v_mixtures.size());
171 for (size_t l = 0; l < v_mixtures_.size(); ++l)
172 {
173 v_mixtures_[l] = v_mixtures[l]->create();
174 v_mixtures_[l]->setMixtureModel(this);
176 }
177 // compute number of free parameters
179}
std::vector< IMixture * > const & v_mixtures() const
int computeNbFreeParameters() const
compute the number of free parameters of the model.
virtual bool initializeStep()
perform any computation needed before the call of the regression method.
void initialize(int nbSample, int nbVariable)
set the dimensions of the parameters of the model

References STK::IMixtureStatModel::computeNbFreeParameters(), STK::IStatModelBase::initialize(), STK::IRegression< YArray, XArray, Weights >::initializeStep(), STK::IStatModelBase::nbSample(), STK::IStatModelBase::setNbFreeParameter(), STK::IMixtureStatModel::v_mixtures(), and STK::IMixtureStatModel::v_mixtures_.

Referenced by create().

◆ finalizeStep()

void STK::MixtureLearner::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::IMixtureStatModel.

Definition at line 158 of file STK_MixtureLearner.cpp.

159{
160 for (MixtIterator it = v_mixtures_.begin(); it != v_mixtures_.end(); ++it)
161 { (*it)->finalizeStep();}
162}
std::vector< IMixture * >::iterator MixtIterator

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

◆ imputationStep()

void STK::MixtureLearner::imputationStep ( )
virtual

Impute the data missing values.

Reimplemented from STK::IMixtureStatModel.

Definition at line 118 of file STK_MixtureLearner.cpp.

119{
120 for (MixtIterator it = v_mixtures_.begin(); it != v_mixtures_.end(); ++it)
121 { (*it)->imputationStep();}
122}

References STK::IMixtureStatModel::v_mixtures_.

◆ lnComponentProbability()

Real STK::MixtureLearner::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 of the class

Implements STK::IMixtureStatModel.

Definition at line 73 of file STK_MixtureLearner.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_.

◆ paramUpdateStep()

void STK::MixtureLearner::paramUpdateStep ( )
virtual

Compute the model parameters given the current imputed/simulated missing values.

This method updates then the lnLikelihood_ of the model.

Implements STK::IMixtureLearner.

Definition at line 81 of file STK_MixtureLearner.cpp.

82{
83 for (MixtIterator it = v_mixtures_.begin() ; it != v_mixtures_.end(); ++it)
84 { (*it)->paramUpdateStep();}
86}
void setLnLikelihood(Real const &lnLikelihood)
set the log-likelihood of the model

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

◆ randomInit()

void STK::MixtureLearner::randomInit ( )
virtual

initialize randomly the parameters of the components of the model

Implements STK::IMixtureStatModel.

Definition at line 103 of file STK_MixtureLearner.cpp.

104{
105#ifdef STK_MIXTURE_VERBOSE
106 stk_cout << _T("Entering MixtureLearner::RandomInit()\n");
107#endif
108 if (state() < 2) { initializeStep();}
109 for (MixtIterator it = v_mixtures_.begin(); it != v_mixtures_.end(); ++it)
110 { (*it)->randomInit();}
112#ifdef STK_MIXTURE_VERBOSE
113 stk_cout << _T("MixtureLearner::RandomInit() done\n");
114#endif
115}
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
void setState(Clust::modelState state)
set the state of the model : should be used by any strategy
Clust::modelState state() const
virtual void initializeStep()
Initialize the model before at its first use.
@ modelParamInitialized_
The parameters of the model have been initialized.

References _T, STK::IMixtureStatModel::initializeStep(), STK::Clust::modelParamInitialized_, STK::IMixtureLearner::setState(), STK::IMixtureLearner::state(), stk_cout, and STK::IMixtureStatModel::v_mixtures_.

◆ releaseIntermediateResults()

void STK::MixtureLearner::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 141 of file STK_MixtureLearner.cpp.

142{
143 for (MixtIterator it = v_mixtures_.begin(); it != v_mixtures_.end(); ++it)
144 { (*it)->releaseIntermediateResults();}
146}

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

◆ samplingStep()

void STK::MixtureLearner::samplingStep ( )
virtual

Simulation of all the data missing values.

Reimplemented from STK::IMixtureStatModel.

Definition at line 127 of file STK_MixtureLearner.cpp.

128{
129 for (MixtIterator it = v_mixtures_.begin(); it != v_mixtures_.end(); ++it)
130 { (*it)->samplingStep();}
131}

References STK::IMixtureStatModel::v_mixtures_.

◆ setParametersStep()

void STK::MixtureLearner::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 149 of file STK_MixtureLearner.cpp.

150{
151 for (MixtIterator it = v_mixtures_.begin(); it != v_mixtures_.end(); ++it)
152 { (*it)->setParametersStep();}
155}

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

◆ storeIntermediateResults()

void STK::MixtureLearner::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 134 of file STK_MixtureLearner.cpp.

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

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

◆ writeParameters()

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

write the parameters of the model in the stream os.

Reimplemented from STK::IMixtureStatModel.

Definition at line 88 of file STK_MixtureLearner.cpp.

89{
90 os << _T("Learner nbSample = ") << nbSample() << std::endl;
91 os << _T("Learner nbCluster = ") << nbCluster() << std::endl;
92 os << _T("Learner nbFreeParameter = ") << nbFreeParameter() << std::endl;
93 os << _T("Learner lnLikelihood = ") << lnLikelihood() << std::endl;
94 os << _T("Learner proportions = ") << pk();
95
96 for (ConstMixtIterator it = v_mixtures_.begin(); it != v_mixtures_.end(); ++it)
97 {
98 os << _T("\nParameters of the mixture: ") << (*it)->idData() << _T("\n");
99 (*it)->writeParameters(os);
100 }
101}
CPointX const & pk() const

References _T, 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::MixtureLearner::meanlnLikelihood_
private

averaged lnLikelihood values.

Will be used by the storeIntermediateResults method.

Definition at line 137 of file STK_MixtureLearner.h.

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


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