STK++ 0.9.13
STK::SimulAlgo Class Reference

Implementation of the SimulAlgo learning algorithm. More...

#include <STK_MixtureAlgoLearn.h>

Inheritance diagram for STK::SimulAlgo:
Inheritance graph

Public Member Functions

 SimulAlgo ()
 default constructor
 
 SimulAlgo (SimulAlgo const &algo)
 Copy constructor.
 
virtual ~SimulAlgo ()
 destructor
 
virtual SimulAlgoclone () 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::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 SimulAlgo learning algorithm.

The SimulAlgo algorithm calls alternatively steps:

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

Definition at line 79 of file STK_MixtureAlgoLearn.h.

Constructor & Destructor Documentation

◆ SimulAlgo() [1/2]

STK::SimulAlgo::SimulAlgo ( )
inline

default constructor

Definition at line 83 of file STK_MixtureAlgoLearn.h.

IMixtureAlgoLearn()
default constructor

Referenced by clone().

◆ SimulAlgo() [2/2]

STK::SimulAlgo::SimulAlgo ( SimulAlgo const algo)
inline

Copy constructor.

Parameters
algothe algorithm to copy

Definition at line 86 of file STK_MixtureAlgoLearn.h.

86: IMixtureAlgoLearn(algo) {}

◆ ~SimulAlgo()

virtual STK::SimulAlgo::~SimulAlgo ( )
inlinevirtual

destructor

Definition at line 88 of file STK_MixtureAlgoLearn.h.

88{}

Member Function Documentation

◆ clone()

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

clone pattern

Definition at line 90 of file STK_MixtureAlgoLearn.h.

90{ return new SimulAlgo(*this);}
SimulAlgo()
default constructor

References SimulAlgo().

◆ run()

bool STK::SimulAlgo::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 93 of file STK_MixtureAlgoLearn.cpp.

94{
95#ifdef STK_MIXTURE_VERBOSE
96 stk_cout << _T("-------------------------------\n");
97 stk_cout << _T("Entering SimulAlgo::run() with:\n")
98 << _T("nbIterMax_ = ") << nbIterMax_ << _T("\n")
99 << _T("p_model_->lnLikelihood = ") << p_model_->lnLikelihood() << _T("\n");
100#endif
101#ifdef STK_MIXTURE_VERY_VERBOSE
102 stk_cout << _T("Parameters of the model\n");
104#endif
105 bool result = true;
106 try
107 {
108 int iter;
109 for (iter = 0; iter < nbIterMax_; ++iter)
110 {
111 p_model_->samplingStep(); // simulate missing values
112 p_model_->paramUpdateStep(); // estimate parameters
113 p_model_->storeIntermediateResults(iter+1); // store current parameters
114 }
115#ifdef STK_MIXTURE_VERBOSE
116 stk_cout << _T("In SimulAlgo::run() iterations terminated.\n")
117 << _T("p_model_->lnLikelihood = ") << p_model_->lnLikelihood() << _T("\n");
118#endif
119#ifdef STK_MIXTURE_VERY_VERBOSE
120 stk_cout << _T("Parameters of the model\n");
122#endif
123 }
124 catch (Clust::exceptions const& error)
125 {
128#ifdef STK_MIXTURE_VERBOSE
129 stk_cout << _T("An error occur in SimulAlgo::run(): ") << msg_error_ << _T("\n");
130#endif
131 result = false;
132 }
133 if (result)
134 {
135 // set averaged parameters
137 p_model_->mapStep();
138#ifdef STK_MIXTURE_VERY_VERBOSE
139 stk_cout << _T("\nIn SimulAlgo::run(), setParameters done.\n")
140 << _T("p_model_->lnLikelihood = ") << p_model_->lnLikelihood() << _T("\n");
141#endif
142 }
143 else
145#ifdef STK_MIXTURE_VERY_VERBOSE
146 stk_cout << _T("Terminating SimulAlgo::run()\n");
147 stk_cout << _T("----------------------------\n");
148#endif
149#ifdef STK_MIXTURE_VERY_VERBOSE
150 stk_cout << _T("Parameters of the model\n");
152#endif
153 return result;
154}
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
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 writeParameters(ostream &os) const
write the parameters of the model in the stream os.
virtual void finalizeStep()
Finalize the estimation of the model.
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
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.

References _T, STK::IRunnerBase::error(), STK::Clust::exceptionToString(), STK::IMixtureStatModel::finalizeStep(), STK::IStatModelBase::lnLikelihood(), STK::IMixtureLearner::mapStep(), STK::IRunnerBase::msg_error_, STK::IMixtureAlgoLearn::nbIterMax_, STK::IMixtureAlgoLearn::p_model_, STK::IMixtureLearner::paramUpdateStep(), STK::IMixtureStatModel::releaseIntermediateResults(), STK::IMixtureStatModel::samplingStep(), stk_cout, STK::IMixtureStatModel::storeIntermediateResults(), and STK::IMixtureStatModel::writeParameters().


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