STK++ 0.9.13
STK::SEMAlgo Class Reference

Implementation of the SEM algorithm. More...

#include <STK_MixtureAlgo.h>

Inheritance diagram for STK::SEMAlgo:
Inheritance graph

Public Member Functions

 SEMAlgo ()
 default constructor
 
 SEMAlgo (SEMAlgo const &algo)
 Copy constructor.
 
virtual ~SEMAlgo ()
 destructor
 
virtual SEMAlgoclone () const
 clone pattern
 
virtual bool run ()
 run the algorithm on the model calling sStep, mStep and eStep of the model until the maximal number of iteration is reached.
 
- Public Member Functions inherited from STK::IMixtureAlgo
virtual ~IMixtureAlgo ()
 destructor
 
int nbIterMax () const
 
int epsilon () const
 
Real threshold () const
 
void setModel (IMixtureComposer *p_model)
 set model
 
void setNbIterMax (int nbIterMax)
 set maximal number of iterations
 
void setEpsilon (Real epsilon)
 set tolerance value
 
void setThreshold (Real threshold)
 set threshold value
 
- Public Member Functions inherited from STK::IRunnerBase
String consterror () const
 get the last error message.
 

Additional Inherited Members

- Protected Member Functions inherited from STK::IMixtureAlgo
 IMixtureAlgo ()
 default constructor
 
 IMixtureAlgo (IMixtureAlgo const &algo)
 Copy constructor.
 
- Protected Member Functions inherited from STK::IRunnerBase
 IRunnerBase ()
 default constructor
 
 IRunnerBase (IRunnerBase const &runner)
 copy constructor
 
virtual ~IRunnerBase ()
 destructor
 
virtual void update ()
 update the runner.
 
- Protected Attributes inherited from STK::IMixtureAlgo
IMixtureComposerp_model_
 pointer on the mixture model
 
int nbIterMax_
 number of iterations of the algorithm
 
Real epsilon_
 tolerance of the algorithm.
 
Real threshold_
 Minimal number of individuals.
 
- Protected Attributes inherited from STK::IRunnerBase
String msg_error_
 String with the last error message.
 
bool hasRun_
 true if run has been used, false otherwise
 

Detailed Description

Implementation of the SEM algorithm.

The SEM algorithm calls alternatively the steps:

  • sStep()
  • samplingStep()
  • pStep()
  • paramUpdateStep()
  • eStep()
  • storeIntermediateResults(iter) until the maximum number of iterations is reached.

Definition at line 111 of file STK_MixtureAlgo.h.

Constructor & Destructor Documentation

◆ SEMAlgo() [1/2]

STK::SEMAlgo::SEMAlgo ( )
inline

default constructor

Definition at line 115 of file STK_MixtureAlgo.h.

115: IMixtureAlgo() {}
IMixtureAlgo()
default constructor

Referenced by clone().

◆ SEMAlgo() [2/2]

STK::SEMAlgo::SEMAlgo ( SEMAlgo const algo)
inline

Copy constructor.

Parameters
algothe algorithm to copy

Definition at line 118 of file STK_MixtureAlgo.h.

118: IMixtureAlgo(algo) {}

◆ ~SEMAlgo()

virtual STK::SEMAlgo::~SEMAlgo ( )
inlinevirtual

destructor

Definition at line 120 of file STK_MixtureAlgo.h.

120{}

Member Function Documentation

◆ clone()

virtual SEMAlgo * STK::SEMAlgo::clone ( ) const
inlinevirtual

clone pattern

Definition at line 122 of file STK_MixtureAlgo.h.

122{ return new SEMAlgo(*this);}
SEMAlgo()
default constructor

References SEMAlgo().

◆ run()

bool STK::SEMAlgo::run ( )
virtual

run the algorithm on the model calling sStep, mStep and eStep of the model until the maximal number of iteration is reached.

Returns
true if no error occur, false otherwise.

Implements STK::IRunnerBase.

Definition at line 161 of file STK_MixtureAlgo.cpp.

162{
163#ifdef STK_MIXTURE_VERY_VERBOSE
164 stk_cout << _T("-----------------------------\n");
165 stk_cout << _T("Entering SEMAlgo::run() with:\n")
166 << _T("nbIterMax_ = ") << nbIterMax_ << _T("\n")
167 << _T("p_model_->lnLikelihood = ") << p_model_->lnLikelihood() << _T("\n");
168#endif
169 bool result = true;
170 try
171 {
172 int iter;
173 for (iter = 0; iter < nbIterMax_; ++iter)
174 {
175 Real nb = p_model_->sStep(); // simulate labels
176 if (nb<threshold_)
177 {
178 msg_error_ = STKERROR_1ARG(SEMAlgo::run,nb,Not enough individuals after sStep\n);
179#ifdef STK_MIXTURE_VERBOSE
180 stk_cout << _T("An error occur in SEMAlgo::run():\n") << msg_error_ << _T("\n");
181#endif
182 result = false;
183 break;
184 }
185 p_model_->samplingStep(); // simulate missing values
186 p_model_->pStep(); // estimate proportions
187 p_model_->paramUpdateStep(); // estimate parameters
188 nb = p_model_->eStep(); // update tik and lnLikelihood
189 if (nb<threshold_)
190 {
191 msg_error_ = STKERROR_1ARG(SEMAlgo::run,nb,Not enough individuals after eStep\n);
192#ifdef STK_MIXTURE_VERBOSE
193 stk_cout << _T("An error occur in SEMAlgo::run():\n") << msg_error_ << _T("\n");
194#endif
195 return false;
196 break;
197 }
198 p_model_->storeIntermediateResults(iter+1); // store current parameters
199 }
200#ifdef STK_MIXTURE_VERBOSE
201 stk_cout << _T("In SEMAlgo::run() iterations terminated.\n")
202 << _T("p_model_->lnLikelihood = ") << p_model_->lnLikelihood() << _T("\n");
203#endif
204 }
205 catch (Clust::exceptions const& error)
206 {
208#ifdef STK_MIXTURE_VERBOSE
209 stk_cout << _T("An error occur in SEMAlgo::run(): ") << msg_error_ << _T("\n");
210#endif
211 result = false;
212 }
213 if (result)
214 {
215 // set averaged parameters
217#ifdef STK_MIXTURE_VERY_VERBOSE
218 stk_cout << _T("\nIn SEMAlgo::run(), setParameters done.\n")
219 << _T("p_model_->lnLikelihood = ") << p_model_->lnLikelihood() << _T("\n");
220#endif
221 }
222 else
224#ifdef STK_MIXTURE_VERY_VERBOSE
225 stk_cout << _T("Terminating SEMAlgo::run()\n");
226 stk_cout << _T("--------------------------\n");
227#endif
228 return result;
229}
#define STKERROR_1ARG(Where, Arg, Error)
Definition STK_Macros.h:61
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
int nbIterMax_
number of iterations of the algorithm
IMixtureComposer * p_model_
pointer on the mixture model
Real threshold_
Minimal number of individuals.
virtual void pStep()
Compute proportions using the ML estimates, default implementation.
virtual Real eStep()
compute the zi, the lnLikelihood of the current estimates and the next value of the tik.
virtual int sStep()
Simulate zi accordingly to tik and replace tik by zik by calling cStep().
virtual void paramUpdateStep()=0
Compute the proportions and the model parameters given the current tik mixture parameters.
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.
String msg_error_
String with the last error message.
Definition STK_IRunner.h:96
String const & error() const
get the last error message.
Definition STK_IRunner.h:82
virtual bool run()
run the algorithm on the model calling sStep, mStep and eStep of the model until the maximal number o...
String exceptionToString(exceptions const &type)
convert a Clust::exceptions to a String.
exceptions
Specific exceptions allowing to handle the erroros that can occur in the estimation process.
double Real
STK fundamental type of Real values.

References _T, STK::IRunnerBase::error(), STK::IMixtureComposer::eStep(), STK::Clust::exceptionToString(), STK::IStatModelBase::lnLikelihood(), STK::IRunnerBase::msg_error_, STK::IMixtureAlgo::nbIterMax_, STK::IMixtureAlgo::p_model_, STK::IMixtureComposer::paramUpdateStep(), STK::IMixtureComposer::pStep(), STK::IMixtureStatModel::releaseIntermediateResults(), run(), STK::IMixtureStatModel::samplingStep(), STK::IMixtureStatModel::setParametersStep(), STK::IMixtureComposer::sStep(), stk_cout, STKERROR_1ARG, STK::IMixtureStatModel::storeIntermediateResults(), and STK::IMixtureAlgo::threshold_.

Referenced by run().


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