STK++ 0.9.13
STK::CEMAlgo Class Reference

Implementation of the SEM algorithm. More...

#include <STK_MixtureAlgo.h>

Inheritance diagram for STK::CEMAlgo:
Inheritance graph

Public Member Functions

 CEMAlgo ()
 default constructor
 
 CEMAlgo (CEMAlgo const &algo)
 Copy constructor.
 
virtual ~CEMAlgo ()
 destructor
 
virtual CEMAlgoclone () const
 clone pattern
 
virtual bool run ()
 run the algorithm on the model calling cStep, mStep and eStep of the model until the maximal number of iteration is reached or the variation of the lnLikelihood is less than epsilon.
 
- 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 CEM algorithm calls alternatively the steps:

  • cStep()
  • paramUpdateStep()
  • eStep() until the maximum number of iterations is reached or the variation of the ln-likelihood is less than the tolerance.

Definition at line 80 of file STK_MixtureAlgo.h.

Constructor & Destructor Documentation

◆ CEMAlgo() [1/2]

STK::CEMAlgo::CEMAlgo ( )
inline

default constructor

Definition at line 84 of file STK_MixtureAlgo.h.

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

Referenced by clone().

◆ CEMAlgo() [2/2]

STK::CEMAlgo::CEMAlgo ( CEMAlgo const algo)
inline

Copy constructor.

Parameters
algothe algorithm to copy

Definition at line 87 of file STK_MixtureAlgo.h.

87: IMixtureAlgo(algo) {}

◆ ~CEMAlgo()

virtual STK::CEMAlgo::~CEMAlgo ( )
inlinevirtual

destructor

Definition at line 89 of file STK_MixtureAlgo.h.

89{}

Member Function Documentation

◆ clone()

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

clone pattern

Definition at line 91 of file STK_MixtureAlgo.h.

91{ return new CEMAlgo(*this);}
CEMAlgo()
default constructor

References CEMAlgo().

◆ run()

bool STK::CEMAlgo::run ( )
virtual

run the algorithm on the model calling cStep, mStep and eStep of the model until the maximal number of iteration is reached or the variation of the lnLikelihood is less than epsilon.

Returns
true if no error occur, false otherwise

Implements STK::IRunnerBase.

Definition at line 44 of file STK_MixtureAlgo.cpp.

45{
46#ifdef STK_MIXTURE_VERY_VERBOSE
47 stk_cout << _T("Entering CEMAlgo::run() with:\n")
48 << _T("nbIterMax_ = ") << nbIterMax_
49 << _T(", epsilon_ = ") << epsilon_ << _T("\n");
50#endif
51 try
52 {
53 Real currentLnLikelihood = p_model_->lnLikelihood();
54 int iter;
55 for (iter = 0; iter < nbIterMax_; iter++)
56 {
58 {
59 msg_error_ = STKERROR_NO_ARG(CEMAlgo::run,No more individuals after cStep\n);
60#ifdef STK_MIXTURE_VERBOSE
61 stk_cout << _T("An error occur in CEMAlgo::run():\n") << msg_error_ << _T("\n");
62#endif
63 return false;
64 }
66 p_model_->pStep();
68 Real nb = p_model_->eStep();
69 if (nb<threshold_)
70 {
71 msg_error_ = STKERROR_1ARG(CEMAlgo::run,nb,Not enough individuals after eStep\n);
72#ifdef STK_MIXTURE_VERBOSE
73 stk_cout << _T("An error occur in CEMAlgo::run():\n") << msg_error_ << _T("\n");
74#endif
75 return false;
76 }
77 Real lnLikelihood = p_model_->lnLikelihood();
78 if (std::abs(lnLikelihood - currentLnLikelihood) < epsilon_)
79 {
80#ifdef STK_MIXTURE_VERY_VERBOSE
81 stk_cout << _T("Terminating CEMAlgo::run() with:\n")
82 << _T("iter = ") << iter << _T("\n")
83 << _T("delta = ") << lnLikelihood - currentLnLikelihood << _T("\n");
84#endif
85 break;
86 }
87 currentLnLikelihood = lnLikelihood;
88 }
89#ifdef STK_MIXTURE_VERBOSE
90 stk_cout << _T("In EMAlgo::run() iteration ") << iter << _T("terminated.\n")
91 << _T("p_model_->lnLikelihood = ") << p_model_->lnLikelihood() << _T("\n");
92#endif
93 }
94 catch (Clust::exceptions const& error)
95 {
97#ifdef STK_MIXTURE_VERBOSE
98 stk_cout << _T("An error occur in CEMAlgo::run():\n") << msg_error_ << _T("\n");
99#endif
100 return false;
101 }
102 return true;
103}
#define STKERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:49
#define STKERROR_1ARG(Where, Arg, Error)
Definition STK_Macros.h:61
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
virtual bool run()
run the algorithm on the model calling cStep, mStep and eStep of the model until the maximal number o...
int nbIterMax_
number of iterations of the algorithm
IMixtureComposer * p_model_
pointer on the mixture model
Real epsilon_
tolerance of the algorithm.
Real threshold_
Minimal number of individuals.
virtual int cStep()
Replace tik by zik.
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 imputationStep()
Impute the missing values.
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
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::IMixtureComposer::cStep(), STK::IMixtureAlgo::epsilon_, STK::IRunnerBase::error(), STK::IMixtureComposer::eStep(), STK::Clust::exceptionToString(), STK::IMixtureStatModel::imputationStep(), STK::IStatModelBase::lnLikelihood(), STK::IRunnerBase::msg_error_, STK::IMixtureAlgo::nbIterMax_, STK::IMixtureAlgo::p_model_, STK::IMixtureComposer::paramUpdateStep(), STK::IMixtureComposer::pStep(), run(), stk_cout, STKERROR_1ARG, STKERROR_NO_ARG, and STK::IMixtureAlgo::threshold_.

Referenced by run().


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