STK++ 0.9.13
|
Base class for Mixture (composed) model. More...
#include <STK_IMixtureComposer.h>
Public Member Functions | |
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 IMixtureComposer * | create () const =0 |
create pattern | |
virtual IMixtureComposer * | clone () const =0 |
clone pattern | |
virtual void | randomInit ()=0 |
initialize randomly the parameters of the components of the model | |
virtual void | paramUpdateStep ()=0 |
Compute the proportions and the model parameters given the current tik mixture parameters. | |
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 | finalizeStep () |
Finalize the estimation of the model. | |
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(). | |
![]() | |
virtual | ~IMixtureStatModel () |
destructor | |
int | nbCluster () const |
CPointX const & | pk () const |
CArrayXX const & | tik () const |
CPointX const & | tk () const |
CVectorXi const & | zi () const |
std::vector< IMixture * > const & | v_mixtures () const |
Real | computeLnLikelihood (int i) const |
Real | computeLikelihood (int i) const |
Real | computeLnLikelihood () const |
Real | computeICL () const |
IMixture * | getMixture (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 Real | lnComponentProbability (int i, int k) const =0 |
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 | 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 ¶m) |
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 > | |
IMixture * | createMixture (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 ¶m) 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) |
![]() | |
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 | |
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_ | |
![]() | |
IMixtureStatModel (int nbSample, int nbCluster) | |
Constructor. | |
IMixtureStatModel (IMixtureStatModel const &model) | |
copy constructor. | |
void | setNbCluster (int nbCluster) |
set the number of cluster of the model | |
![]() | |
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 | |
Clust::modelState | state_ |
state of the model | |
CPointX | lnComp_ |
Auxiliary array used in the eStep. | |
Additional Inherited Members | |
![]() | |
typedef std::vector< IMixture * >::const_iterator | ConstMixtIterator |
typedef std::vector< IMixture * >::iterator | MixtIterator |
![]() | |
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 | |
Base class for Mixture (composed) model.
In this interface we assume there is an underline generative model that will be estimated using either an EM, SEM or CEM algorithm. All mixture parameters are created using the method
in the constructor. They can be accessed from the mixtures using constant accessors.
The pure virtual function to implement in derived class are
The public virtual function that can be re-implemented in derived class for a specific behavior are:
IMixtureComposer::initializeStep
is called in all the initialization method. Don't forget to called it in the randomInit implementation. Definition at line 85 of file STK_IMixtureComposer.h.
Constructor.
nbCluster,nbSample | number of clusters and samples |
Definition at line 49 of file STK_IMixtureComposer.cpp.
|
protected |
copy constructor.
model | the model to clone |
Definition at line 58 of file STK_IMixtureComposer.cpp.
|
virtual |
|
pure virtual |
clone pattern
Implements STK::IMixtureStatModel.
Implemented in STK::MixtureComposer, STK::MixtureComposerFixedProp, STK::MixtureSemiLearner, and STK::MixtureSemiLearnerFixedProp.
Referenced by STK::FullStrategy::initStep(), and STK::FullStrategy::run().
|
pure virtual |
create pattern
Implements STK::IMixtureStatModel.
Implemented in STK::MixtureComposer, STK::MixtureComposerFixedProp, STK::MixtureSemiLearner, and STK::MixtureSemiLearnerFixedProp.
Referenced by STK::FullStrategy::initStep(), STK::SimpleStrategy::run(), and STK::XemStrategy::run().
|
virtual |
Replace tik by zik.
Reimplemented in STK::MixtureSemiLearner.
Definition at line 149 of file STK_IMixtureComposer.cpp.
References _T, cStep(), STK::ExprBase< Derived >::minElt(), stk_cout, STK::Stat::sum(), STK::IMixtureStatModel::tik_, and STK::IMixtureStatModel::tk_.
Referenced by cStep(), STK::MixtureSemiLearner::cStep(), randomZi(), STK::CEMAlgo::run(), and sStep().
Replace tik by zik.
i | index of the the individual |
Definition at line 219 of file STK_IMixtureComposer.cpp.
References STK::ICArray< Derived >::row(), STK::IMixtureStatModel::tik_, and STK::IMixtureStatModel::zi_.
|
virtual |
compute the zi, the lnLikelihood of the current estimates and the next value of the tik.
Reimplemented in STK::MixtureSemiLearner.
Definition at line 180 of file STK_IMixtureComposer.cpp.
References _T, eStep(), STK::isFinite(), STK::ExprBase< Derived >::minElt(), STK::IStatModelBase::setLnLikelihood(), stk_cout, STK::sum(), STK::Stat::sumByCol(), STK::IMixtureStatModel::tik_, STK::IMixtureStatModel::tk_, and STK::ArrayBase< Derived >::transpose().
Referenced by STK::IMixtureAlgoPredict::burnStep(), eStep(), STK::MixtureSemiLearner::eStep(), STK::IMixtureAlgoPredict::predictBayesClassifier(), randomClassInit(), randomFuzzyInit(), STK::MixtureComposer::randomInit(), STK::EMAlgo::run(), STK::CEMAlgo::run(), STK::SEMAlgo::run(), STK::SemiSEMAlgo::run(), STK::EMPredict::run(), and STK::SemiSEMPredict::run().
compute one zi and the next value of the tik for i fixed
i | the individual |
Definition at line 223 of file STK_IMixtureComposer.cpp.
References _T, STK::Clust::eStepFail_, STK::ExprBase< Derived >::isInfinite(), lnComp_, STK::IMixtureStatModel::lnComponentProbability(), STK::max(), STK::ExprBase< Derived >::maxElt(), STK::IMixtureStatModel::pk_, STK::ICArray< Derived >::row(), stk_cout, STK::sum(), STK::IMixtureStatModel::tik_, STK::IMixtureStatModel::tk_, STK::ArrayBase< Derived >::transpose(), STK::IMixtureStatModel::writeParameters(), and STK::IMixtureStatModel::zi_.
|
virtual |
Finalize the estimation of the model.
Compute obtained lnLikelihood and set state to finalized.
Reimplemented from STK::IMixtureStatModel.
Reimplemented in STK::MixtureComposer.
Definition at line 281 of file STK_IMixtureComposer.cpp.
References STK::IMixtureStatModel::computeLnLikelihood(), STK::Clust::modelFinalized_, STK::IStatModelBase::setLnLikelihood(), and setState().
Referenced by STK::IMixtureAlgoPredict::predictBayesClassifier(), STK::EMPredict::run(), STK::SemiSEMPredict::run(), and STK::StrategyFacade::run().
|
protectedvirtual |
Create the mixture model parameters pk_ and tik_.
Default implementation is to set pk_ and tik_ arrays to 1/K value.
Reimplemented in STK::MixtureSemiLearner.
Definition at line 290 of file STK_IMixtureComposer.cpp.
References _T, STK::IMixtureStatModel::nbCluster_, STK::IMixtureStatModel::pk_, stk_cout, STK::sumByCol(), STK::IMixtureStatModel::tik_, and STK::IMixtureStatModel::tk_.
Referenced by initializeStep().
|
virtual |
Initialize the model before its first use.
Initialize the values of the mixture parameters pk_
and @© tik_ using virtual method initializeMixtureParameters()
and compute tk_
and zk_
using the virtual methods mapStep()
and pStep()
.
Reimplemented from STK::IMixtureStatModel.
Definition at line 74 of file STK_IMixtureComposer.cpp.
References _T, STK::IMixtureStatModel::computeLnLikelihood(), STK::IMixtureStatModel::computeNbFreeParameters(), initializeMixtureParameters(), STK::IMixtureStatModel::initializeStep(), mapStep(), STK::Clust::modelInitialized_, pStep(), STK::IStatModelBase::setLnLikelihood(), STK::IStatModelBase::setNbFreeParameter(), setState(), stk_cout, STK::Stat::sumByCol(), STK::IMixtureStatModel::tik_, STK::IMixtureStatModel::tk_, and STK::IMixtureStatModel::writeParameters().
Referenced by STK::IMixtureAlgoPredict::burnStep(), STK::MixtureComposer::createComposer(), STK::IMixtureAlgoPredict::predictBayesClassifier(), randomClassInit(), randomFuzzyInit(), STK::MixtureComposer::randomInit(), STK::EMPredict::run(), STK::SemiSEMPredict::run(), STK::RandomInit::run(), STK::ClassInit::run(), and STK::FuzzyInit::run().
|
virtual |
Compute zi using the Map estimate.
Reimplemented in STK::MixtureSemiLearner.
Definition at line 205 of file STK_IMixtureComposer.cpp.
References mapStep(), and STK::IMixtureStatModel::zi_.
Referenced by initializeStep(), mapStep(), STK::MixtureSemiLearner::mapStep(), STK::IMixtureAlgoPredict::predictBayesClassifier(), randomFuzzyInit(), STK::MixtureComposer::randomInit(), STK::EMPredict::run(), and STK::SemiSEMPredict::run().
Compute zi using the Map estimate for i fixed.
Definition at line 259 of file STK_IMixtureComposer.cpp.
References STK::ICArray< Derived >::row(), STK::IMixtureStatModel::tik_, and STK::IMixtureStatModel::zi_.
|
pure virtual |
Compute the proportions and the model parameters given the current tik mixture parameters.
Implemented in STK::MixtureComposer.
Definition at line 269 of file STK_IMixtureComposer.cpp.
References pStep().
Referenced by randomClassInit(), randomFuzzyInit(), STK::EMAlgo::run(), STK::CEMAlgo::run(), STK::SEMAlgo::run(), and STK::SemiSEMAlgo::run().
|
virtual |
Compute proportions using the ML estimates, default implementation.
Set as virtual in case we impose fixed proportions in derived Composer.
Reimplemented in STK::MixtureComposerFixedProp, and STK::MixtureSemiLearnerFixedProp.
Definition at line 275 of file STK_IMixtureComposer.cpp.
References STK::Stat::meanByCol(), STK::IMixtureStatModel::pk_, and STK::IMixtureStatModel::tik_.
Referenced by initializeStep(), paramUpdateStep(), STK::EMAlgo::run(), STK::CEMAlgo::run(), STK::SEMAlgo::run(), and STK::SemiSEMAlgo::run().
void STK::IMixtureComposer::randomClassInit | ( | ) |
Initialize randomly the labels zi of the model.
Initialize the model parameters using initializeStep() if it has not been already called. Simulate the zi, compute tik using eStep(), update the parameters using paramUpdateStep() and terminate using eStep().
Definition at line 105 of file STK_IMixtureComposer.cpp.
References _T, eStep(), initializeStep(), STK::Clust::modelInitialized_, STK::Clust::modelParamInitialized_, paramUpdateStep(), STK::Clust::randomClassInitFail_, randomZi(), setState(), state(), and stk_cout.
Referenced by STK::ClassInit::run().
void STK::IMixtureComposer::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().
Definition at line 126 of file STK_IMixtureComposer.cpp.
References _T, eStep(), initializeStep(), mapStep(), STK::Clust::modelInitialized_, STK::Clust::modelParamInitialized_, paramUpdateStep(), STK::Clust::randomFuzzyInitFail_, randomTik(), setState(), state(), and stk_cout.
Referenced by STK::FuzzyInit::run(), STK::FullStrategy::run(), STK::SimpleStrategy::run(), and STK::XemStrategy::run().
initialize randomly the parameters of the components of the model
Implements STK::IMixtureStatModel.
Implemented in STK::MixtureComposer.
Referenced by STK::RandomInit::run().
|
protectedvirtual |
generate random tik_
Reimplemented in STK::MixtureSemiLearner.
Definition at line 301 of file STK_IMixtureComposer.cpp.
References STK::ExprBase< Derived >::minElt(), STK::IMixtureStatModel::pk_, STK::ArrayBase< Derived >::randUnif(), STK::ICArray< Derived >::row(), STK::IMixtureStatModel::tik_, and STK::IMixtureStatModel::tk_.
Referenced by randomFuzzyInit(), and STK::MixtureComposer::randomInit().
|
protectedvirtual |
generate random zi_
Reimplemented in STK::MixtureSemiLearner.
Definition at line 317 of file STK_IMixtureComposer.cpp.
References cStep(), STK::IMixtureStatModel::pk_, STK::ArrayBase< Derived >::rand(), and STK::IMixtureStatModel::zi_.
Referenced by randomClassInit().
|
inline |
set the state of the model : should be used by any strategy
Definition at line 105 of file STK_IMixtureComposer.h.
References state(), and state_.
Referenced by finalizeStep(), initializeStep(), randomClassInit(), randomFuzzyInit(), STK::MixtureComposer::randomInit(), and STK::FullStrategy::run().
|
virtual |
Simulate zi accordingly to tik and replace tik by zik by calling cStep().
Reimplemented in STK::MixtureSemiLearner.
Definition at line 167 of file STK_IMixtureComposer.cpp.
References _T, cStep(), sStep(), stk_cout, and STK::IMixtureStatModel::zi_.
Referenced by STK::IMixtureAlgoPredict::burnStep(), STK::SEMAlgo::run(), sStep(), and STK::MixtureSemiLearner::sStep().
Simulate zi accordingly to tik.
i | index of the the individual |
Definition at line 214 of file STK_IMixtureComposer.cpp.
References STK::Law::Categorical::rand(), STK::ICArray< Derived >::row(), STK::IMixtureStatModel::tik_, and STK::IMixtureStatModel::zi_.
|
inline |
Definition at line 102 of file STK_IMixtureComposer.h.
References state_.
Referenced by randomClassInit(), randomFuzzyInit(), STK::MixtureComposer::randomInit(), STK::SimpleStrategy::run(), STK::XemStrategy::run(), and setState().
|
private |
Auxiliary array used in the eStep.
Definition at line 194 of file STK_IMixtureComposer.h.
Referenced by eStep().
|
private |
state of the model
Definition at line 191 of file STK_IMixtureComposer.h.
Referenced by setState(), and state().