STK++ 0.9.13
STK::ImputeAlgo Class Reference

Implementation of the ImputeAlgo learning algorithm. More...

#include <STK_MixtureAlgoLearn.h>

Inheritance diagram for STK::ImputeAlgo:
Inheritance graph

Public Member Functions

 ImputeAlgo ()
 default constructor
 
 ImputeAlgo (ImputeAlgo const &algo)
 Copy constructor.
 
virtual ~ImputeAlgo ()
 destructor
 
virtual ImputeAlgoclone () const
 clone pattern
 
virtual bool run ()
 run the algorithm on the model calling the eStep and mStep 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::IMixtureAlgoLearn
virtual ~IMixtureAlgoLearn ()
 destructor
 
int nbIterMax () const
 
int epsilon () const
 
void setModel (IMixtureLearner *p_model)
 set model
 
void setNbIterMax (int nbIterMax)
 set maximal number of 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::IMixtureAlgoLearn
 IMixtureAlgoLearn ()
 default constructor
 
 IMixtureAlgoLearn (IMixtureAlgoLearn 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::IMixtureAlgoLearn
IMixtureLearnerp_model_
 pointer on the mixture model
 
int nbIterMax_
 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 ImputeAlgo learning algorithm.

The Impute algorithm call alternatively the steps:

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

Definition at line 51 of file STK_MixtureAlgoLearn.h.

Constructor & Destructor Documentation

◆ ImputeAlgo() [1/2]

STK::ImputeAlgo::ImputeAlgo ( )
inline

default constructor

Definition at line 55 of file STK_MixtureAlgoLearn.h.

IMixtureAlgoLearn()
default constructor

Referenced by clone().

◆ ImputeAlgo() [2/2]

STK::ImputeAlgo::ImputeAlgo ( ImputeAlgo const algo)
inline

Copy constructor.

Parameters
algothe algorithm to copy

Definition at line 58 of file STK_MixtureAlgoLearn.h.

58: IMixtureAlgoLearn(algo) {}

◆ ~ImputeAlgo()

virtual STK::ImputeAlgo::~ImputeAlgo ( )
inlinevirtual

destructor

Definition at line 60 of file STK_MixtureAlgoLearn.h.

60{}

Member Function Documentation

◆ clone()

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

clone pattern

Definition at line 62 of file STK_MixtureAlgoLearn.h.

62{ return new ImputeAlgo(*this);}
ImputeAlgo()
default constructor

References ImputeAlgo().

◆ run()

bool STK::ImputeAlgo::run ( )
virtual

run the algorithm on the model calling the eStep and mStep 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_MixtureAlgoLearn.cpp.

45{
46#ifdef STK_MIXTURE_VERY_VERBOSE
47 stk_cout << _T("--------------------------------\n");
48 stk_cout << _T("Entering ImputeAlgo::run() with:\n")
49 << _T("nbIterMax_ = ") << nbIterMax_ << _T("\n")
50 << _T("epsilon_ = ") << epsilon_ << _T("\n");
51#endif
52
53 try
54 {
55 Real currentLnLikelihood = p_model_->lnLikelihood();
56 int iter;
57 for (iter = 0; iter < nbIterMax_; iter++)
58 {
61 Real lnLikelihood = p_model_->lnLikelihood();
62 // no abs as the likelihood should increase
63 if ( (lnLikelihood - currentLnLikelihood) < epsilon_)
64 {
65#ifdef STK_MIXTURE_VERY_VERBOSE
66 stk_cout << _T("Terminating ImputeAlgo::run() with:\n")
67 << _T("iter = ") << iter << _T("\n")
68 << _T("delta = ") << lnLikelihood - currentLnLikelihood << _T("\n");
69#endif
70 break;
71 }
72 currentLnLikelihood = lnLikelihood;
73 }
74 // finalize and compute posterior probabilities and predicted values
77#ifdef STK_MIXTURE_VERBOSE
78 stk_cout << _T("In ImputeAlgo::run() iteration ") << iter << _T("terminated.\n")
79 << _T("p_model_->lnLikelihood = ") << p_model_->lnLikelihood() << _T("\n");
80#endif
81 }
82 catch (Clust::exceptions const& error)
83 {
85#ifdef STK_MIXTURE_VERBOSE
86 stk_cout << _T("An error occur in ImputeAlgo::run():\n") << msg_error_ << _T("\n");
87#endif
88 return false;
89 }
90 return true;
91}
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
Real epsilon_
tolerance of the algorithm.
IMixtureLearner * p_model_
pointer on the mixture model
int nbIterMax_
maximal number of iterations of the algorithm
virtual void paramUpdateStep()=0
Compute the model parameters given the current mixture parameters and imputation/simulation of the mi...
virtual void mapStep()
Compute ziPred using the Map estimate.
virtual void imputationStep()
Impute the missing values.
virtual void finalizeStep()
Finalize the estimation of the model.
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::IMixtureAlgoLearn::epsilon_, STK::IRunnerBase::error(), STK::Clust::exceptionToString(), STK::IMixtureStatModel::finalizeStep(), STK::IMixtureStatModel::imputationStep(), STK::IStatModelBase::lnLikelihood(), STK::IMixtureLearner::mapStep(), STK::IRunnerBase::msg_error_, STK::IMixtureAlgoLearn::nbIterMax_, STK::IMixtureAlgoLearn::p_model_, STK::IMixtureLearner::paramUpdateStep(), and stk_cout.


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