STK++ 0.9.13
STK::IMixtureStatModel Class Referenceabstract

Interface base class for Mixture (composed) model. More...

#include <STK_IMixtureStatModel.h>

Inheritance diagram for STK::IMixtureStatModel:
Inheritance graph

Public Types

typedef std::vector< IMixture * >::const_iterator ConstMixtIterator
 
typedef std::vector< IMixture * >::iterator MixtIterator
 

Public Member Functions

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 IMixtureStatModelcreate () const =0
 create pattern
 
virtual IMixtureStatModelclone () const =0
 clone pattern
 
virtual void randomInit ()=0
 initialize randomly the parameters of the components of the model
 
virtual Real lnComponentProbability (int i, int k) const =0
 
virtual void initializeStep ()
 Initialize the model before at its first use.
 
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 setParametersStep ()
 Utility method allowing to signal to a mixture to set its parameters.
 
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 finalizeStep ()
 Finalize the estimation of the model.
 
virtual void writeParameters (ostream &os) const
 write the parameters of the model in the stream os.
 
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

 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

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

Interface base class for Mixture (composed) model.

In statistics, a mixture model is a probabilistic model for representing the presence of sub-populations within an overall population, without requiring that an observed data-set should identify the sub-population to which an individual observation belongs. Formally a mixture model corresponds to the mixture distribution that represents the probability distribution of observations in the overall population. However, while problems associated with "mixture distributions" relate to deriving the properties of the overall population from those of the sub-populations, "mixture models" are used to make statistical inferences about the properties of the sub-populations given only observations on the pooled population, without sub-population-identity information.

Some ways of implementing mixture models involve steps that attribute postulated sub-population-identities to individual observations (or weights towards such sub-populations), in which case these can be regarded as types unsupervised learning or clustering procedures. However not all inference procedures involve such steps.

Pure virtual functions to implement in derived class are

virtual IMixtureComposer* create() const = 0;
virtual IMixtureComposer* clone() const = 0;
virtual bool randomInit() =0;
virtual Real lnComponentProbability(int i, int k) const = 0;
Base class for Mixture (composed) model.
virtual IMixtureStatModel * create() const =0
create pattern
virtual Real lnComponentProbability(int i, int k) const =0
virtual IMixtureStatModel * clone() const =0
clone pattern
virtual void randomInit()=0
initialize randomly the parameters of the components of the model
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
double Real
STK fundamental type of Real values.

Virtual functions that can be re-implemented in derived class for a specific behavior are:

virtual void imputationStep();
virtual void samplingStep();
virtual void setParametersStep();
virtual void writeParameters(ostream &os) const
write the parameters of the model in the stream os.
virtual void imputationStep()
Impute the missing values.
virtual void setParametersStep()
Utility method allowing to signal to a mixture to set its parameters.
virtual void releaseIntermediateResults()
This step can be used to signal to the mixtures that they must release the stored results.
virtual void storeIntermediateResults(int iteration)
This step can be used to signal to the mixtures that they must store results.
virtual void samplingStep()
Simulation of all the latent variables and/or missing data excluding class labels.
std::basic_ostream< Char > ostream
ostream for Char
Definition STK_Stream.h:57

Template functions allowing to interact with the composer are

template<class Array>
void setMixtureParameters( Array const& tik);
template<class Array, class RowVector>
void setMixtureParameters( Array const& tik, RowVector const& pk);
template<class RowVector>
void setProportions( RowVector const& pk);
template<class Manager, class Parameters>
void setParameters(IMixtureManager<Manager> const& manager, String const& idData, Parameters const& param);
template<class Manager>
template<class DataHandler>
template<class DataHandler>
void setParameters(IMixtureManager< Manager > const &manager, String const &idData, Parameters const &param)
Utility method allowing to set the parameters to a specific mixture.
void setMixtureParameters(Array const &tik)
set the mixture parameters using an array of posterior probabilities.
CPointX const & pk() const
void setProportions(RowVector const &pk)
Set proportions of each classes.
void createMixture(IMixtureManager< Manager > &manager)
Utility method allowing to create all the mixtures registered in the data handler of a mixture manage...
CArrayXX const & tik() const
void removeMixture(IMixtureManager< Manager > &manager, String const &idData)
Utility method allowing to release completely a mixture with its data set.
Interface base class for all the mixture models that will be processed by the composer.
std::basic_string< Char > String
STK fundamental type of a String.

Template functions allowing to get results from the composer are

template<class Manager, class Parameters>
void getParameters(IMixtureManager<Manager> const& manager, String const& idData, Parameters& param) const;
template<class Manager, class MissingValues>
void getMissingValues(IMixtureManager<Manager> const& manager, String const& idData, MissingValues& missing) const;
void getMissingValues(IMixtureManager< Manager > const &manager, String const &idData, MissingValues &missing) const
Utility method allowing to get the missing values of a specific mixture.
void getParameters(IMixtureManager< Manager > const &manager, String const &idData, Parameters &param) const
Utility method allowing to get the parameters of a specific mixture.
See also
IMixtureComposer, IMixtureLearner, IMixtureManager
Note
the virtual method IMixtureStatModel::initializeStep is called in all the initialization method. Don't forget to called it in the randomInit implementation.

Definition at line 123 of file STK_IMixtureStatModel.h.

Member Typedef Documentation

◆ ConstMixtIterator

Definition at line 136 of file STK_IMixtureStatModel.h.

◆ MixtIterator

Definition at line 137 of file STK_IMixtureStatModel.h.

Constructor & Destructor Documentation

◆ IMixtureStatModel() [1/2]

STK::IMixtureStatModel::IMixtureStatModel ( int  nbSample,
int  nbCluster 
)
protected

Constructor.

Parameters
nbCluster,nbSamplenumber of clusters and samples

Definition at line 45 of file STK_IMixtureStatModel.cpp.

52 , v_mixtures_()
53{}
CArrayXX tik_
The tik probabilities.
CVectorXi zi_
The zi class label.
std::vector< IMixture * > v_mixtures_
vector of pointers to the mixtures components
CPointX pk_
The proportions of each mixtures.
CPointX tk_
The sum of the columns of tik_.
int nbCluster_
number of cluster.
IStatModelBase()
Default constructor.
const int baseIdx
base index of the containers created in STK++.

◆ IMixtureStatModel() [2/2]

STK::IMixtureStatModel::IMixtureStatModel ( IMixtureStatModel const model)
protected

copy constructor.

Parameters
modelthe model to clone

Definition at line 56 of file STK_IMixtureStatModel.cpp.

57 : IStatModelBase(model)
58 , nbCluster_(model.nbCluster_)
59 , pk_(model.pk_), tik_(model.tik_)
60 , tk_(model.tk_), zi_(model.zi_)
61 , v_mixtures_(model.v_mixtures_.size())
62{
63 // clone mixtures
64 for (size_t l = 0; l < v_mixtures_.size(); ++l)
65 {
66 v_mixtures_[l] = model.v_mixtures_[l]->clone();
67 v_mixtures_[l]->setMixtureModel(this);
68 }
69}

References v_mixtures_.

◆ ~IMixtureStatModel()

STK::IMixtureStatModel::~IMixtureStatModel ( )
virtual

destructor

Definition at line 71 of file STK_IMixtureStatModel.cpp.

72{
73 for (MixtIterator it = v_mixtures_.begin() ; it != v_mixtures_.end(); ++it)
74 { delete (*it);}
75}
std::vector< IMixture * >::iterator MixtIterator

References v_mixtures_.

Member Function Documentation

◆ clone()

◆ computeICL()

Real STK::IMixtureStatModel::computeICL ( ) const
Returns
the computed ICL criteria.

Definition at line 104 of file STK_IMixtureStatModel.cpp.

105{
106 Real res = 0.0;
107 for (int j = tik().beginCols(); j< tik().endCols(); ++j)
108 { res += (tik_.col(j) * (tik_.col(j)+1e-15).log()).sum();}
109 // compute result
110 return (- 2. * lnLikelihood() + nbFreeParameter() * lnNbSample() - 2. * res);
111}
hidden::CSlice< Derived, sizeRows_, 1 >::Result col(int j) const
implement the col operator using a reference on the column of the allocator
Arrays::SumOp< Lhs, Rhs >::result_type sum(Lhs const &lhs, Rhs const &rhs)
convenience function for summing two arrays

References STK::ICArray< Derived >::col(), STK::IStatModelBase::lnLikelihood(), STK::IStatModelBase::lnNbSample(), STK::IStatModelBase::nbFreeParameter(), STK::sum(), tik(), and tik_.

Referenced by STK::ICLMixtureCriterion::run().

◆ computeLikelihood()

Real STK::IMixtureStatModel::computeLikelihood ( int  i) const
Returns
the computed likelihood of the i-th sample.
Parameters
iindex of the sample

Definition at line 77 of file STK_IMixtureStatModel.cpp.

78{ return std::exp(computeLnLikelihood(i));}

References computeLnLikelihood().

◆ computeLnLikelihood() [1/2]

Real STK::IMixtureStatModel::computeLnLikelihood ( ) const
Returns
the computed log-likelihood.

Definition at line 95 of file STK_IMixtureStatModel.cpp.

96{
97 Real res = 0.0;
98 for (int i = tik().beginRows(); i< tik().endRows(); ++i)
99 { res += computeLnLikelihood(i);}
100 return res;
101}

References computeLnLikelihood(), and tik().

Referenced by computeLikelihood(), computeLnLikelihood(), STK::IMixtureComposer::finalizeStep(), finalizeStep(), STK::IMixtureComposer::initializeStep(), STK::MixtureLearner::paramUpdateStep(), and releaseMixture().

◆ computeLnLikelihood() [2/2]

Real STK::IMixtureStatModel::computeLnLikelihood ( int  i) const
Returns
the computed log-likelihood of the i-th sample.
Parameters
iindex of the sample

Definition at line 83 of file STK_IMixtureStatModel.cpp.

84{
85 // get maximal value
86 CPointX lnComp(pk_.size());
87 for (int k = pk_.begin(); k< pk_.end(); ++k)
88 { lnComp[k] = std::log(pk_[k]) + lnComponentProbability(i, k);}
89 // compute result
90 Real lnCompMax = lnComp.maxElt();
91 return std::log((lnComp-lnCompMax).exp().sum())+lnCompMax;
92}
CArrayPoint< Real, UnknownSize, Arrays::by_col_ > CPointX

References lnComponentProbability(), pk_, and STK::sum().

◆ computeNbFreeParameters()

int STK::IMixtureStatModel::computeNbFreeParameters ( ) const

compute the number of free parameters of the model.

This method is used in IMixtureComposer::initializeStep in order to give a value to IStatModelBase::nbFreeParameter_. lookup on the mixtures and sum the nbFreeParameter.

Returns
the number of free parameters

Definition at line 162 of file STK_IMixtureStatModel.cpp.

163{
164 int sum = nbCluster_-1; // proportions
165 for (ConstMixtIterator it = v_mixtures_.begin(); it != v_mixtures_.end(); ++it)
166 { sum+= (*it)->nbFreeParameter();}
167 return sum;
168}
std::vector< IMixture * >::const_iterator ConstMixtIterator

References nbCluster_, STK::sum(), and v_mixtures_.

Referenced by STK::MixtureLearner::createLearner(), and STK::IMixtureComposer::initializeStep().

◆ computeNbMissingValues()

int STK::IMixtureStatModel::computeNbMissingValues ( ) const

compute the missing values of the model.

lookup on the mixtures and sum the nbMissingValues.

Returns
the number of missing values

Definition at line 174 of file STK_IMixtureStatModel.cpp.

175{
176 int sum = nbCluster_-1; // proportions
177 for (ConstMixtIterator it = v_mixtures_.begin(); it != v_mixtures_.end(); ++it)
178 { sum+= (*it)->nbMissingValues();}
179 return sum;
180}

References nbCluster_, STK::sum(), and v_mixtures_.

Referenced by STK::EMPredict::run(), STK::SemiSEMPredict::run(), and STK::MixtureComposer::writeParameters().

◆ create()

◆ createMixture() [1/3]

template<class DataHandler >
void STK::IMixtureStatModel::createMixture ( IMixtureManager< DataHandler > &  manager)

Definition at line 348 of file STK_IMixtureStatModel.h.

349{
350 typedef typename DataHandlerBase<DataHandler>::InfoMap InfoMap;
351 typedef typename InfoMap::const_iterator const_iterator;
352 for ( const_iterator it=manager.p_handler()->info().begin(); it!=manager.p_handler()->info().end(); ++it)
353 {
354 IMixture* p_mixture = manager.createMixture(it->first, nbCluster());
355#ifdef STK_MIXTURE_DEBUG
356 if (!p_mixture)
357 { stk_cout << _T("In IMixtureStatModel::createMixture(manager) failed.\n");}
358#endif
359 if (p_mixture) registerMixture(p_mixture);
360 }
361}
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
void registerMixture(IMixture *p_mixture)
register a mixture to the composer.

References _T, nbCluster(), registerMixture(), and stk_cout.

◆ createMixture() [2/3]

template<class Manager >
void STK::IMixtureStatModel::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.

Parameters
managerthe manager with the responsibility of the creation.

◆ createMixture() [3/3]

template<class Manager >
IMixture * STK::IMixtureStatModel::createMixture ( IMixtureManager< Manager > &  manager,
String const idData 
)

Utility method allowing to create a mixture with a given data set and register it.

The Mixture Manager will find the associated model to use with this data set.

Parameters
managerthe manager with the responsibility of the creation.
idDatathe id name of the data to modelize.

Definition at line 370 of file STK_IMixtureStatModel.h.

371{
372 IMixture* p_mixture = manager.createMixture( idData, nbCluster());
373#ifdef STK_MIXTURE_DEBUG
374 if (!p_mixture)
375 { stk_cout << _T("In IMixtureStatModel::createMixture(manager,")<< idData << _T(") failed.\n");}
376#endif
377 if (p_mixture) registerMixture(p_mixture);
378 return p_mixture;
379}

References _T, nbCluster(), registerMixture(), and stk_cout.

◆ finalizeStep()

virtual void STK::IMixtureStatModel::finalizeStep ( )
inlinevirtual

Finalize the estimation of the model.

The default behavior is compute current lnLikelihood.

Reimplemented in STK::IMixtureComposer, STK::MixtureComposer, and STK::MixtureLearner.

Definition at line 247 of file STK_IMixtureStatModel.h.

void setLnLikelihood(Real const &lnLikelihood)
set the log-likelihood of the model

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

Referenced by STK::ImputeAlgo::run(), STK::SimulAlgo::run(), and STK::LearnFacade::run().

◆ getMissingValues()

template<class Manager , class MissingValues >
void STK::IMixtureStatModel::getMissingValues ( IMixtureManager< Manager > const manager,
String const idData,
MissingValues &  missing 
) const

Utility method allowing to get the missing values of a specific mixture.

Parameters
managerthe manager with the responsibility of the parameters
idDatathe Id of the data we want the parameters
missingthe structure which will receive the missing values

Definition at line 474 of file STK_IMixtureStatModel.h.

475{
476 IMixture* p_mixture= getMixture(idData);
477 if (p_mixture) manager.getMissingValues(p_mixture, missing);
478}
IMixture * getMixture(String const &idData) const
Utility lookup function allowing to find a Mixture from its idData.

References getMixture().

◆ getMixture()

IMixture * STK::IMixtureStatModel::getMixture ( String const idData) const

Utility lookup function allowing to find a Mixture from its idData.

Parameters
idDatathe id name of the data
Returns
a pointer on the mixture, NULL if the mixture is not found

Definition at line 117 of file STK_IMixtureStatModel.cpp.

118{
119 for (ConstMixtIterator it = v_mixtures_.begin(); it != v_mixtures_.end(); ++it)
120 { if ((*it)->idData() == idData) return (*it);}
121 return 0;
122}

References v_mixtures_.

Referenced by getMissingValues(), getParameters(), removeMixture(), and setParameters().

◆ getParameters()

template<class Manager , class Parameters >
void STK::IMixtureStatModel::getParameters ( IMixtureManager< Manager > const manager,
String const idData,
Parameters &  param 
) const

Utility method allowing to get the parameters of a specific mixture.

Parameters
managerthe manager with the responsibility of the parameters
idDatathe Id of the data we want the parameters
paramthe structure which will receive the parameters

Definition at line 464 of file STK_IMixtureStatModel.h.

465{ IMixture* p_mixture= getMixture(idData);
466 if (p_mixture) manager.getParameters(p_mixture, param);
467}

References getMixture().

◆ imputationStep()

virtual void STK::IMixtureStatModel::imputationStep ( )
inlinevirtual

Impute the missing values.

Default behavior is "do nothing".

Reimplemented in STK::MixtureComposer, and STK::MixtureLearner.

Definition at line 225 of file STK_IMixtureStatModel.h.

225{}

Referenced by STK::EMAlgo::run(), STK::CEMAlgo::run(), STK::ImputeAlgo::run(), and STK::EMPredict::run().

◆ initializeStep()

void STK::IMixtureStatModel::initializeStep ( )
virtual

Initialize the model before at its first use.

This function can be overloaded in derived class for initialization of the specific model parameters. It should be called prior to any used of the class.

See also
IMixture,MixtureBridge,MixtureLearner

Reimplemented in STK::IMixtureComposer.

Definition at line 188 of file STK_IMixtureStatModel.cpp.

189{
190#ifdef STK_MIXTURE_VERBOSE
191 stk_cout << _T("Entering IMixtureStatModel::initializeStep\n");
192#endif
193 if (v_mixtures_.size() == 0)
195 setLnLikelihood(-Arithmetic<Real>::infinity());
196 // initialize registered mixtures
197 for (MixtIterator it = v_mixtures_.begin(); it != v_mixtures_.end(); ++it)
198 { (*it)->initializeStep();}
199}
#define STKRUNTIME_ERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:138
virtual void initializeStep()
Initialize the model before at its first use.

References _T, initializeStep(), STK::IStatModelBase::setLnLikelihood(), stk_cout, STKRUNTIME_ERROR_NO_ARG, and v_mixtures_.

Referenced by STK::IMixtureComposer::initializeStep(), initializeStep(), STK::MixtureLearner::randomInit(), and STK::LearnFacade::run().

◆ lnComponentProbability()

virtual Real STK::IMixtureStatModel::lnComponentProbability ( int  i,
int  k 
) const
pure virtual
Returns
the value of the probability of the ith sample in the kth class.
Parameters
i,kindexes of the sample and of the class

Implemented in STK::MixtureComposer, and STK::MixtureLearner.

Referenced by computeLnLikelihood(), STK::IMixtureComposer::eStep(), and STK::IMixtureLearner::mapStep().

◆ nbCluster()

◆ pk()

CPointX const & STK::IMixtureStatModel::pk ( ) const
inline
Returns
the proportions of each mixtures

Definition at line 145 of file STK_IMixtureStatModel.h.

145{ return pk_;};

References pk_.

Referenced by STK::IMixtureLearner::setClassLabels(), setMixtureParameters(), setProportions(), STK::MixtureComposer::writeParameters(), and STK::MixtureLearner::writeParameters().

◆ randomInit()

virtual void STK::IMixtureStatModel::randomInit ( )
pure virtual

initialize randomly the parameters of the components of the model

Implemented in STK::MixtureComposer, STK::MixtureLearner, and STK::IMixtureComposer.

◆ registerMixture()

void STK::IMixtureStatModel::registerMixture ( IMixture p_mixture)

register a mixture to the composer.

When a mixture is registered, the composer:

  • assign composer pointer (itself) to the mixture
  • add it to v_mixtures_
  • update the number of variables
    Parameters
    p_mixturea pointer on the mixture

Definition at line 124 of file STK_IMixtureStatModel.cpp.

125{
126#ifdef STK_MIXTURE_VERBOSE
127 stk_cout << _T("In IMixtureStatModel::registerMixture, registering mixture: ")
128 << p_mixture->idData() << _T("\n");
129#endif
130 p_mixture->setMixtureModel(this);
131 v_mixtures_.push_back(p_mixture);
132 // update NbFreeParameters
133 setNbFreeParameter(nbFreeParameter()+p_mixture->nbFreeParameter());
134}
void setNbFreeParameter(int const &nbFreeParameter)
set the number of free parameters of the model

References _T, STK::IRegression< YArray, XArray, Weights >::nbFreeParameter(), STK::IStatModelBase::nbFreeParameter(), STK::IStatModelBase::setNbFreeParameter(), stk_cout, and v_mixtures_.

Referenced by createMixture(), and createMixture().

◆ releaseIntermediateResults()

virtual void STK::IMixtureStatModel::releaseIntermediateResults ( )
inlinevirtual

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 in STK::MixtureComposer, and STK::MixtureLearner.

Definition at line 243 of file STK_IMixtureStatModel.h.

243{}

Referenced by STK::SEMAlgo::run(), STK::SemiSEMAlgo::run(), and STK::SimulAlgo::run().

◆ releaseMixture()

void STK::IMixtureStatModel::releaseMixture ( String const idData)

release a mixture from the composer.

When a mixture is released, the composer remove it from v_mixtures_.

Note
the data set associated with the mixture is still in the manager list of data set if you use a manager in order to register it.
Parameters
idDatathe Id of the mixture to release.

Definition at line 140 of file STK_IMixtureStatModel.cpp.

141{
142 for (MixtIterator it = v_mixtures_.begin(); it != v_mixtures_.end(); ++it)
143 {
144 if ((*it)->idData() == idData)
145 {
146 setNbFreeParameter(nbFreeParameter()-(*it)->nbFreeParameter());
147 // remove mixture
148 delete (*it);
149 v_mixtures_.erase(it);
150 // update log-likelihood
151 if (v_mixtures_.size() == 0)
152 { setLnLikelihood(-Arithmetic<Real>::infinity());}
153 else
155 // and break
156 break;
157 }
158 }
159}

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

Referenced by removeMixture().

◆ removeMixture()

template<class Manager >
void STK::IMixtureStatModel::removeMixture ( IMixtureManager< Manager > &  manager,
String const idData 
)

Utility method allowing to release completely a mixture with its data set.

The MixtureManager will find and release the associated data set.

Parameters
managerthe manager with the responsibility of the release.
idDatathe id name of the data to modelize.

Definition at line 387 of file STK_IMixtureStatModel.h.

388{
389 IMixture* p_mixture = getMixture(idData);
390#ifdef STK_MIXTURE_DEBUG
391 if (!p_mixture)
392 { stk_cout << _T("In IMixtureStatModel::removeMixture(manager,")<< idData << _T(") failed.\n");}
393#endif
394 if (p_mixture)
395 {
396 releaseMixture(idData);
397 manager.releaseDataBridge( idData);
398 }
399}
void releaseMixture(String const &idData)
release a mixture from the composer.

References _T, getMixture(), releaseMixture(), and stk_cout.

◆ samplingStep()

virtual void STK::IMixtureStatModel::samplingStep ( )
inlinevirtual

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

Default behavior is "do nothing".

Reimplemented in STK::MixtureComposer, and STK::MixtureLearner.

Definition at line 229 of file STK_IMixtureStatModel.h.

229{}

Referenced by STK::IMixtureAlgoPredict::burnStep(), STK::SEMAlgo::run(), STK::SemiSEMAlgo::run(), STK::SimulAlgo::run(), and STK::SemiSEMPredict::run().

◆ setMixtureParameters() [1/2]

template<class Array >
void STK::IMixtureStatModel::setMixtureParameters ( Array const tik)

set the mixture parameters using an array of posterior probabilities.

Proportions, numbers in each class and class labels are computed using these posterior probabilities.

Parameters
tikposterior class probabilities

Definition at line 414 of file STK_IMixtureStatModel.h.

415{
416 tik_ = tik;
418 pk_ = tk_ / nbSample();
419 for (int i = tik_.beginCols(); i< tik_.endCols(); ++i)
420 {
421 int k;
422 tik_.row(i).maxElt(k);
423 zi_[i] = k;
424 }
425}
hidden::CSlice< Derived, 1, sizeCols_ >::Result row(int i) const
implement the row operator using a reference on the row of the allocator
hidden::FunctorTraits< Derived, SumOp >::Row sumByCol(Derived const &A)

References STK::IStatModelBase::nbSample(), pk_, STK::ICArray< Derived >::row(), STK::Stat::sumByCol(), tik(), tik_, tk_, and zi_.

Referenced by setMixtureParameters().

◆ setMixtureParameters() [2/2]

template<class Array , class RowVector >
void STK::IMixtureStatModel::setMixtureParameters ( Array const tik,
RowVector const pk 
)

set the mixture parameters giving the posterior probabilities and the proportions.

Numbers in each class and class labels are computed using the posterior probabilities.

Parameters
tikposterior class probabilities
pkprior class proportion

Definition at line 430 of file STK_IMixtureStatModel.h.

431{
432#ifdef STK_MIXTURE_DEBUG
433 if (pk_.size() != tik_.sizeCols())
434 { STKRUNTIME_ERROR_2ARG(IMixtureLearner::setMixtureParameters,pk_.size(),tik_.sizeCols(),Numbers of class in tik and pk differ);}
435#endif
436 tik_ = tik;
437 pk_ = pk;
439 for (int i = tik_.beginCols(); i< tik_.endCols(); ++i)
440 {
441 int k;
442 tik_.row(i).maxElt(k);
443 zi_[i] = k;
444 }
445}
#define STKRUNTIME_ERROR_2ARG(Where, Arg1, Arg2, Error)
Definition STK_Macros.h:120

References pk(), pk_, STK::ICArray< Derived >::row(), setMixtureParameters(), STKRUNTIME_ERROR_2ARG, STK::Stat::sumByCol(), tik(), tik_, tk_, and zi_.

◆ setNbCluster()

void STK::IMixtureStatModel::setNbCluster ( int  nbCluster)
inlineprotected

set the number of cluster of the model

Parameters
nbClusternumber of cluster of the model

Definition at line 326 of file STK_IMixtureStatModel.h.

References nbCluster(), and nbCluster_.

◆ setParameters()

template<class Manager , class Parameters >
void STK::IMixtureStatModel::setParameters ( IMixtureManager< Manager > const manager,
String const idData,
Parameters const param 
)

Utility method allowing to set the parameters to a specific mixture.

Parameters
managerthe manager with the responsibility of the parameters
idDataId of the data we want to set the parameters
paramstructure which contains the parameters

Definition at line 407 of file STK_IMixtureStatModel.h.

408{ IMixture* p_mixture= getMixture(idData);
409 if (p_mixture) manager.setParameters(p_mixture, param);
410}

References getMixture().

◆ setParametersStep()

virtual void STK::IMixtureStatModel::setParametersStep ( )
inlinevirtual

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

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

Reimplemented in STK::MixtureComposer, and STK::MixtureLearner.

Definition at line 233 of file STK_IMixtureStatModel.h.

233{}

Referenced by STK::IMixtureAlgoPredict::burnStep(), STK::SEMAlgo::run(), STK::SemiSEMAlgo::run(), and STK::SemiSEMPredict::run().

◆ setProportions()

template<class RowVector >
void STK::IMixtureStatModel::setProportions ( RowVector const pk)

Set proportions of each classes.

Parameters
pkprior class proportion

Definition at line 449 of file STK_IMixtureStatModel.h.

450{
451#ifdef STK_MIXTURE_DEBUG
452 if (pk_.size() != nbCluster())
453 { STKRUNTIME_ERROR_2ARG(IMixtureLearner::setProportions,pk_.size(),nbCluster(),Numbers of class in pk differs);}
454#endif
455 pk_ = pk;
456}

References nbCluster(), pk(), pk_, setProportions(), and STKRUNTIME_ERROR_2ARG.

Referenced by setProportions().

◆ storeIntermediateResults()

virtual void STK::IMixtureStatModel::storeIntermediateResults ( int  iteration)
inlinevirtual

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 in STK::MixtureComposer, and STK::MixtureLearner.

Definition at line 238 of file STK_IMixtureStatModel.h.

238{}

Referenced by STK::IMixtureAlgoPredict::burnStep(), STK::SEMAlgo::run(), STK::SemiSEMAlgo::run(), STK::SimulAlgo::run(), and STK::SemiSEMPredict::run().

◆ tik()

CArrayXX const & STK::IMixtureStatModel::tik ( ) const
inline
Returns
the tik probabilities

Definition at line 147 of file STK_IMixtureStatModel.h.

147{ return tik_;};

References tik_.

Referenced by computeICL(), computeLnLikelihood(), setMixtureParameters(), and setMixtureParameters().

◆ tk()

CPointX const & STK::IMixtureStatModel::tk ( ) const
inline
Returns
the proportions of individuals

Definition at line 149 of file STK_IMixtureStatModel.h.

149{ return tk_;};

References tk_.

◆ v_mixtures()

std::vector< IMixture * > const & STK::IMixtureStatModel::v_mixtures ( ) const
inline
Returns
a constant reference on the vector of mixture

Definition at line 153 of file STK_IMixtureStatModel.h.

153{ return v_mixtures_;}

References v_mixtures_.

Referenced by STK::MixtureSemiLearner::create(), STK::MixtureSemiLearnerFixedProp::create(), STK::MixtureComposer::createComposer(), and STK::MixtureLearner::createLearner().

◆ writeParameters()

virtual void STK::IMixtureStatModel::writeParameters ( ostream os) const
inlinevirtual

write the parameters of the model in the stream os.

Reimplemented in STK::MixtureComposer, and STK::MixtureLearner.

Definition at line 249 of file STK_IMixtureStatModel.h.

249{};

Referenced by STK::IMixtureComposer::eStep(), STK::IMixtureComposer::initializeStep(), STK::SimulAlgo::run(), and STK::FullStrategy::run().

◆ zi()

CVectorXi const & STK::IMixtureStatModel::zi ( ) const
inline
Returns
the zi class label

Definition at line 151 of file STK_IMixtureStatModel.h.

151{ return zi_;};

References zi_.

Referenced by STK::IMixtureLearner::setClassLabels(), STK::IMixtureLearner::setClassLabels(), and STK::MixtureSemiLearner::setLabels().

Member Data Documentation

◆ nbCluster_

int STK::IMixtureStatModel::nbCluster_
protected

◆ pk_

◆ tik_

◆ tk_

◆ v_mixtures_

◆ zi_


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