STK++ 0.9.13
STK::SemiSEMAlgo Class Reference

Implementation of the SemiSEM algorithm. More...

#include <STK_MixtureAlgo.h>

Inheritance diagram for STK::SemiSEMAlgo:
Inheritance graph

Public Member Functions

 SemiSEMAlgo ()
 default constructor
 
 SemiSEMAlgo (SemiSEMAlgo const &algo)
 Copy constructor.
 
virtual ~SemiSEMAlgo ()
 destructor
 
virtual SemiSEMAlgoclone () 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 SemiSEM algorithm.

The SemiSEM algorithm calls alternatively the steps:

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

Definition at line 140 of file STK_MixtureAlgo.h.

Constructor & Destructor Documentation

◆ SemiSEMAlgo() [1/2]

STK::SemiSEMAlgo::SemiSEMAlgo ( )
inline

default constructor

Definition at line 144 of file STK_MixtureAlgo.h.

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

Referenced by clone().

◆ SemiSEMAlgo() [2/2]

STK::SemiSEMAlgo::SemiSEMAlgo ( SemiSEMAlgo const algo)
inline

Copy constructor.

Parameters
algothe algorithm to copy

Definition at line 147 of file STK_MixtureAlgo.h.

147: IMixtureAlgo(algo) {}

◆ ~SemiSEMAlgo()

virtual STK::SemiSEMAlgo::~SemiSEMAlgo ( )
inlinevirtual

destructor

Definition at line 149 of file STK_MixtureAlgo.h.

149{}

Member Function Documentation

◆ clone()

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

clone pattern

Definition at line 151 of file STK_MixtureAlgo.h.

151{ return new SemiSEMAlgo(*this);}
SemiSEMAlgo()
default constructor

References SemiSEMAlgo().

◆ run()

bool STK::SemiSEMAlgo::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 231 of file STK_MixtureAlgo.cpp.

232{
233#ifdef STK_MIXTURE_VERY_VERBOSE
234 stk_cout << _T("---------------------------------\n");
235 stk_cout << _T("Entering SemiSEMAlgo::run() with:\n")
236 << _T("nbIterMax_ = ") << nbIterMax_ << _T("\n")
237 << _T("p_model_->lnLikelihood = ") << p_model_->lnLikelihood() << _T("\n");
238#endif
239 bool result = true;
240 try
241 {
242 int iter;
243 for (iter = 0; iter < nbIterMax_; ++iter)
244 {
246 p_model_->pStep();
248 Real nb = p_model_->eStep();
249 if (nb<threshold_)
250 {
251 msg_error_ = STKERROR_1ARG(SemiSEMAlgo::run,nb,Not enough individuals after eStep\n);
252#ifdef STK_MIXTURE_VERBOSE
253 stk_cout << _T("An exception occur in SemiSEMAlgo::run(): ") << msg_error_ << _T("\n");
254#endif
255 result = false;
256 break;
257 }
258 p_model_->storeIntermediateResults(iter+1); // store current parameters
259 }
260#ifdef STK_MIXTURE_VERBOSE
261 stk_cout << _T("In SemiSEMAlgo::run() iteration ") << iter << _T("terminated.\n")
262 << _T("p_model_->lnLikelihood = ") << p_model_->lnLikelihood() << _T("\n");
263#endif
264 }
265 catch (Clust::exceptions const& error)
266 {
268#ifdef STK_MIXTURE_VERBOSE
269 stk_cout << _T("An exception occur in SemiSEMAlgo::run(): ") << msg_error_ << _T("\n");
270#endif
271 result = false;
272 }
273 // set averaged parameters
274 if (result)
275 {
277#ifdef STK_MIXTURE_VERY_VERBOSE
278 stk_cout << _T("\nIn SemiSEMAlgo::run(), setParameters done.\n")
279 << _T("p_model_->lnLikelihood = ") << p_model_->lnLikelihood() << _T("\n");
280#endif
281 }
282 else // no result
284#ifdef STK_MIXTURE_VERY_VERBOSE
285 stk_cout << _T("Terminating SemiSEMAlgo::run()\n");
286 stk_cout << _T("------------------------------\n");
287#endif
288 return result;
289}
#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 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_cout, STKERROR_1ARG, STK::IMixtureStatModel::storeIntermediateResults(), and STK::IMixtureAlgo::threshold_.

Referenced by run().


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