STK++ 0.9.13
STK::IMixtureLearner Class Referenceabstract

Base class for Learner of a Mixture mixed model. More...

#include <STK_IMixtureLearner.h>

Inheritance diagram for STK::IMixtureLearner:
Inheritance graph

Public Member Functions

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.
 
virtual void paramUpdateStep ()=0
 Compute the model parameters given the current mixture parameters and imputation/simulation of the missing values.
 
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 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

 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

CVectorXi ziPred_
 The predicted class label.
 
Clust::modelState state_
 state of the model
 

Additional Inherited Members

- Public Types inherited from STK::IMixtureStatModel
typedef std::vector< IMixture * >::const_iterator ConstMixtIterator
 
typedef std::vector< IMixture * >::iterator MixtIterator
 
- 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

Base class for Learner of a Mixture mixed model.

In this interface we assume there is an underline generative model that will be estimated using a MCMC algorithm.

The pure virtual function to implement in derived class are

virtual void paramUpdateStep() = 0;
virtual void paramUpdateStep()=0
Compute the model parameters given the current mixture parameters and imputation/simulation of the mi...
See also
IMixtureComposer

Definition at line 56 of file STK_IMixtureLearner.h.

Constructor & Destructor Documentation

◆ IMixtureLearner() [1/2]

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

Constructor.

Parameters
nbCluster,nbSamplenumber of clusters and samples

Definition at line 43 of file STK_IMixtureLearner.cpp.

45 , ziPred_(tik_.rows())
47{}
CVectorXi ziPred_
The predicted class label.
Clust::modelState state_
state of the model
CArrayXX tik_
The tik probabilities.
IMixtureStatModel(int nbSample, int nbCluster)
Constructor.
@ modelCreated_
the model has been created but is not initialized

◆ IMixtureLearner() [2/2]

STK::IMixtureLearner::IMixtureLearner ( IMixtureLearner const model)
protected

copy constructor.

Parameters
modelthe model to clone

Definition at line 51 of file STK_IMixtureLearner.cpp.

52 : IMixtureStatModel(model), state_(model.state_)
53{}

◆ ~IMixtureLearner()

STK::IMixtureLearner::~IMixtureLearner ( )
virtual

destructor

Definition at line 55 of file STK_IMixtureLearner.cpp.

55{}

Member Function Documentation

◆ mapStep()

void STK::IMixtureLearner::mapStep ( )
virtual

Compute ziPred using the Map estimate.

Definition at line 58 of file STK_IMixtureLearner.cpp.

59{
60 CPointX lnComp_(tik_.cols());
61 int kmax;
62 Real max;
63 for (int i=tik_.beginRows(); i < tik_.endRows(); i++)
64 {
65 // get maximal element of ln(x_i,\theta_k) + ln(p_k)
66 for (int k=tik_.beginCols(); k< tik_.endCols(); k++)
67 { lnComp_[k] = std::log(pk_[k])+lnComponentProbability(i,k);}
68 if (lnComp_.isInfinite().any()) { throw(Clust::mapStepFail_);}
69 max = lnComp_.maxElt(kmax);
70 // set ziPred_
71 ziPred_[i] = kmax;
72 // return max + sum_k p_k exp{lnCom_k - lnComp_kmax}
73 Real sum = (tik_.row(i) = (lnComp_ - max).exp()).sum();
74 tik_.row(i) /= sum;
75 }
76}
hidden::CSlice< Derived, 1, sizeCols_ >::Result row(int i) const
implement the row operator using a reference on the row of the allocator
virtual Real lnComponentProbability(int i, int k) const =0
CPointX pk_
The proportions of each mixtures.
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.
hidden::SliceVisitorSelector< Derived, hidden::MaxVisitor, Arrays::by_col_ >::type_result max(Derived const &A)
If A is a row-vector or a column-vector then the function will return the usual maximal value of the ...
CArrayPoint< Real, UnknownSize, Arrays::by_col_ > CPointX

References STK::ExprBase< Derived >::isInfinite(), STK::IMixtureStatModel::lnComponentProbability(), STK::Clust::mapStepFail_, STK::max(), STK::ExprBase< Derived >::maxElt(), STK::IMixtureStatModel::pk_, STK::ICArray< Derived >::row(), STK::sum(), STK::IMixtureStatModel::tik_, and ziPred_.

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

◆ paramUpdateStep()

virtual void STK::IMixtureLearner::paramUpdateStep ( )
pure virtual

Compute the model parameters given the current mixture parameters and imputation/simulation of the missing values.

Implemented in STK::MixtureLearner.

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

◆ setClassLabels() [1/2]

template<class ColVector >
void STK::IMixtureLearner::setClassLabels ( ColVector const zi)

set the mixture parameters using the given class labels.

Posterior probabilities, numbers in each class and proportions are computed using the class labels.

Parameters
ziclass labels

Definition at line 113 of file STK_IMixtureLearner.h.

114{
115 zi_ = zi;
116 tik_ = 0.;
117 for (int i=tik_.beginRows(); i < tik_.endRows(); i++)
118 { tik_(i, zi_[i]) = 1.;}
119 // count the number of individuals in each class
121 pk_ = tk_/nbSample();
122}
CVectorXi const & zi() const
CVectorXi zi_
The zi class label.
CPointX tk_
The sum of the columns of tik_.
hidden::FunctorTraits< Derived, SumOp >::Row sumByCol(Derived const &A)

References STK::IStatModelBase::nbSample(), STK::IMixtureStatModel::pk_, STK::Stat::sumByCol(), STK::IMixtureStatModel::tik_, STK::IMixtureStatModel::tk_, STK::IMixtureStatModel::zi(), and STK::IMixtureStatModel::zi_.

◆ setClassLabels() [2/2]

template<class ColVector , class RowVector >
void STK::IMixtureLearner::setClassLabels ( ColVector const zi,
RowVector const pk 
)

set the mixture parameters using the class labels and giving the proportions.

Parameters
ziclass labels
pkproportions of each class

Definition at line 129 of file STK_IMixtureLearner.h.

130{
131 pk_ = pk;
132 zi_ = zi;
133 tik_ = 0.;
134 for (int i=tik_.beginRows(); i < tik_.endRows(); i++)
135 { tik_(i, zi_[i]) = 1.;}
136 // count the number of individuals in each class
138}
CPointX const & pk() const

References STK::IMixtureStatModel::pk(), STK::IMixtureStatModel::pk_, STK::Stat::sumByCol(), STK::IMixtureStatModel::tik_, STK::IMixtureStatModel::tk_, STK::IMixtureStatModel::zi(), and STK::IMixtureStatModel::zi_.

◆ setState()

void STK::IMixtureLearner::setState ( Clust::modelState  state)
inline

set the state of the model : should be used by any strategy

Definition at line 77 of file STK_IMixtureLearner.h.

77{ state_ = state;}
Clust::modelState state() const

References state(), and state_.

Referenced by STK::MixtureLearner::randomInit().

◆ state()

Clust::modelState STK::IMixtureLearner::state ( ) const
inline
Returns
the state of the model

Definition at line 75 of file STK_IMixtureLearner.h.

75{ return state_;}

References state_.

Referenced by STK::MixtureLearner::randomInit(), and setState().

◆ ziPred()

CVectorXi const & STK::IMixtureLearner::ziPred ( ) const
inline
Returns
the predicted class label

Definition at line 73 of file STK_IMixtureLearner.h.

73{ return ziPred_;};

References ziPred_.

Member Data Documentation

◆ state_

Clust::modelState STK::IMixtureLearner::state_
private

state of the model

Definition at line 105 of file STK_IMixtureLearner.h.

Referenced by setState(), and state().

◆ ziPred_

CVectorXi STK::IMixtureLearner::ziPred_
private

The predicted class label.

Definition at line 103 of file STK_IMixtureLearner.h.

Referenced by mapStep(), and ziPred().


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