STK++ 0.9.13
STK::EMPredict Class Reference

Implementation of the EMPredict algorithm. More...

#include <STK_MixtureAlgoPredict.h>

Inheritance diagram for STK::EMPredict:
Inheritance graph

Public Member Functions

 EMPredict ()
 default constructor
 
 EMPredict (EMPredict const &algo)
 Copy constructor.
 
virtual ~EMPredict ()
 destructor
 
virtual EMPredictclone () const
 clone pattern
 
virtual bool run ()
 run the algorithm on the model until the maximal number of iteration or the threshold is reached.
 
- Public Member Functions inherited from STK::IMixtureAlgoPredict
virtual ~IMixtureAlgoPredict ()
 destructor
 
int nbIterBurn () const
 
int setNbIterLong () const
 
int epsilon () const
 
void setModel (IMixtureComposer *p_model)
 set model
 
void setNbIterBurn (int nbIterBurn)
 set number of burning iterations
 
void setNbIterLong (int nbIterLong)
 set number of long iterations
 
void setEpsilon (Real epsilon)
 set tolerance 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::IMixtureAlgoPredict
 IMixtureAlgoPredict ()
 default constructor
 
 IMixtureAlgoPredict (IMixtureAlgoPredict const &algo)
 Copy constructor.
 
bool predictBayesClassifier ()
 predict class labels when there is no missing values.
 
bool burnStep ()
 Perform burn step using SEM algorithm.
 
- 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::IMixtureAlgoPredict
IMixtureComposerp_model_
 pointer on the mixture model
 
int nbIterBurn_
 Number of burning iterations of the algorithm.
 
int nbIterLong_
 maximal number of iterations of the algorithm
 
Real epsilon_
 tolerance of the algorithm.
 
- 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 EMPredict algorithm.

EMPredict algorithm start calling an initializationStep and then calls until convergence steps:

  • imputationStep()
  • eStep() until the maximum number of iterations or the threshold is reached. This is the counterpart of EMSAlgo for prediction.

Definition at line 52 of file STK_MixtureAlgoPredict.h.

Constructor & Destructor Documentation

◆ EMPredict() [1/2]

STK::EMPredict::EMPredict ( )
inline

default constructor

Definition at line 56 of file STK_MixtureAlgoPredict.h.

IMixtureAlgoPredict()
default constructor

Referenced by clone().

◆ EMPredict() [2/2]

STK::EMPredict::EMPredict ( EMPredict const algo)
inline

Copy constructor.

Parameters
algothe algorithm to copy

Definition at line 59 of file STK_MixtureAlgoPredict.h.

59: IMixtureAlgoPredict(algo) {}

◆ ~EMPredict()

virtual STK::EMPredict::~EMPredict ( )
inlinevirtual

destructor

Definition at line 61 of file STK_MixtureAlgoPredict.h.

61{}

Member Function Documentation

◆ clone()

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

clone pattern

Definition at line 63 of file STK_MixtureAlgoPredict.h.

63{ return new EMPredict(*this);}
EMPredict()
default constructor

References EMPredict().

◆ run()

bool STK::EMPredict::run ( )
virtual

run the algorithm on the model until the maximal number of iteration or the threshold is reached.

Returns
true if no error occur, false otherwise.

Implements STK::IRunnerBase.

Definition at line 44 of file STK_MixtureAlgoPredict.cpp.

45{
47#ifdef STK_MIXTURE_VERBOSE
48 stk_cout << _T("-------------------------------\n");
49 stk_cout << _T("Entering EMPredict::run() with:\n")
50 << _T("nbIterBurn_ = ") << nbIterBurn_ << _T("\n")
51 << _T("nbIterLong_ = ") << nbIterLong_ << _T("\n");
52#endif
53 try
54 {
56 if (!burnStep())
57 {
60 return false;
61 }
62 Real currentLnLikelihood = p_model_->lnLikelihood();
63 int iter;
64 for (iter = 0; iter < nbIterLong_; iter++)
65 {
67 p_model_->eStep();
68 Real lnLikelihood = p_model_->lnLikelihood();
69 if ( (lnLikelihood - currentLnLikelihood) < epsilon_) // no abs as the likelihood should increase
70 {
71#ifdef STK_MIXTURE_VERY_VERBOSE
72 stk_cout << _T("Terminating EMPredict::run() with:\n")
73 << _T("iter = ") << iter << _T("\n")
74 << _T("delta = ") << lnLikelihood - currentLnLikelihood << _T("\n");
75#endif
76 break;
77 }
78 currentLnLikelihood = lnLikelihood;
79 }
80#ifdef STK_MIXTURE_VERBOSE
81 stk_cout << _T("In EMPredict::run() iteration ") << iter << _T("terminated.\n")
82 << _T("p_model_->lnLikelihood = ") << p_model_->lnLikelihood() << _T("\n");
83#endif
84 }
85 catch (Clust::exceptions const& error)
86 {
88#ifdef STK_MIXTURE_VERBOSE
89 stk_cout << _T("An error occur in EMPredict::run():\n") << msg_error_ << _T("\n");
90#endif
93 return false;
94 }
95 catch (Exception const& error)
96 {
98#ifdef STK_MIXTURE_VERBOSE
99 stk_cout << _T("An error occur in EMPredict::run():\n") << msg_error_ << _T("\n");
100#endif
101 p_model_->mapStep();
103 return false;
104 }
105 p_model_->mapStep();
107#ifdef STK_MIXTURE_VERY_VERBOSE
108 stk_cout << _T("Terminating EMPredict::run()\n");
109 stk_cout << _T("----------------------------\n");
110#endif
111 return true;
112}
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
bool predictBayesClassifier()
predict class labels when there is no missing values.
int nbIterLong_
maximal number of iterations of the algorithm
bool burnStep()
Perform burn step using SEM algorithm.
int nbIterBurn_
Number of burning iterations of the algorithm.
Real epsilon_
tolerance of the algorithm.
IMixtureComposer * p_model_
pointer on the mixture model
virtual void initializeStep()
Initialize the model before its first use.
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.
int computeNbMissingValues() const
compute the missing values of the model.
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::IMixtureAlgoPredict::burnStep(), STK::IMixtureStatModel::computeNbMissingValues(), STK::IMixtureAlgoPredict::epsilon_, STK::IRunnerBase::error(), STK::IMixtureComposer::eStep(), STK::Clust::exceptionToString(), STK::IMixtureComposer::finalizeStep(), STK::IMixtureStatModel::imputationStep(), STK::IMixtureComposer::initializeStep(), STK::IStatModelBase::lnLikelihood(), STK::IMixtureComposer::mapStep(), STK::IRunnerBase::msg_error_, STK::IMixtureAlgoPredict::nbIterBurn_, STK::IMixtureAlgoPredict::nbIterLong_, STK::IMixtureAlgoPredict::p_model_, STK::IMixtureAlgoPredict::predictBayesClassifier(), and stk_cout.


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