STK++ 0.9.13
STK::IMixtureAlgoPredict Class Reference

Interface base class for predicting algorithms. More...

#include <STK_IMixtureAlgoPredict.h>

Inheritance diagram for STK::IMixtureAlgoPredict:
Inheritance graph

Public Member Functions

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.
 
virtual bool run ()=0
 run the computations.
 

Protected Member Functions

 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

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

Interface base class for predicting algorithms.

Predicting algorithms are decomposed in two stages :

  • A burning stage using SEM algorithm
  • An estimation stage using EM or SemiSEM algorithm If there is no missing values, the algorithm simplify in a posterior allocation stage.

All algorithms are runners applying on a IMixtureComposer model instance given by pointer and have to implement the run method.

Definition at line 57 of file STK_IMixtureAlgoPredict.h.

Constructor & Destructor Documentation

◆ IMixtureAlgoPredict() [1/2]

STK::IMixtureAlgoPredict::IMixtureAlgoPredict ( )
protected

default constructor

Definition at line 42 of file STK_IMixtureAlgoPredict.cpp.

42 : IRunnerBase()
43 , p_model_(0)
44 , nbIterBurn_(0), nbIterLong_(0), epsilon_(0.) {}
int nbIterLong_
maximal number of iterations of the algorithm
int nbIterBurn_
Number of burning iterations of the algorithm.
Real epsilon_
tolerance of the algorithm.
IMixtureComposer * p_model_
pointer on the mixture model
IRunnerBase()
default constructor
Definition STK_IRunner.h:68

◆ IMixtureAlgoPredict() [2/2]

STK::IMixtureAlgoPredict::IMixtureAlgoPredict ( IMixtureAlgoPredict const algo)
protected

Copy constructor.

Parameters
algothe algorithm to copy

Definition at line 48 of file STK_IMixtureAlgoPredict.cpp.

48 : IRunnerBase(algo)
49 , p_model_(algo.p_model_)
50 , nbIterBurn_(algo.nbIterBurn_)
51 , nbIterLong_(algo.nbIterLong_)
52 , epsilon_(algo.epsilon_)
53{}

◆ ~IMixtureAlgoPredict()

STK::IMixtureAlgoPredict::~IMixtureAlgoPredict ( )
virtual

destructor

Definition at line 56 of file STK_IMixtureAlgoPredict.cpp.

56{}

Member Function Documentation

◆ burnStep()

bool STK::IMixtureAlgoPredict::burnStep ( )
protected

Perform burn step using SEM algorithm.

initializeStep();
eStep(); // will compute tik and zi values
finalizeStep();
Returns
true if no error occur, false otherwise

Definition at line 101 of file STK_IMixtureAlgoPredict.cpp.

102{
103#ifdef STK_MIXTURE_VERY_VERBOSE
104 stk_cout << _T("-------------------------------\n");
105 stk_cout << _T("Entering IMixtureAlgoPredict::burnStep()\n");
106#endif
107 try
108 {
110 for (int iter = 0; iter < nbIterLong_; ++iter)
111 {
112 p_model_->sStep(); // simulate labels
113 p_model_->samplingStep(); // simulate missing values
114 p_model_->eStep(); // update tik and lnLikelihood
115 p_model_->storeIntermediateResults(iter+1); // store current parameters
116 }
117 }
118 catch (Clust::exceptions const& error)
119 {
121#ifdef STK_MIXTURE_VERBOSE
122 stk_cout << _T("An error occur in IMixtureAlgoPredict::run(): ") << msg_error_ << _T("\n");
123#endif
124 p_model_->setParametersStep(); // compute current parameters value
125 return false;
126 }
127 p_model_->setParametersStep(); // compute current parameters value
128 return true;
129}
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
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 int sStep()
Simulate zi accordingly to tik and replace tik by zik by calling cStep().
virtual void setParametersStep()
Utility method allowing to signal to a mixture to set its parameters.
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::IMixtureComposer::eStep(), STK::Clust::exceptionToString(), STK::IMixtureComposer::initializeStep(), STK::IRunnerBase::msg_error_, nbIterLong_, p_model_, STK::IMixtureStatModel::samplingStep(), STK::IMixtureStatModel::setParametersStep(), STK::IMixtureComposer::sStep(), stk_cout, and STK::IMixtureStatModel::storeIntermediateResults().

Referenced by STK::EMPredict::run(), and STK::SemiSEMPredict::run().

◆ epsilon()

int STK::IMixtureAlgoPredict::epsilon ( ) const
inline
Returns
the epsilon of the algorithm

Definition at line 76 of file STK_IMixtureAlgoPredict.h.

76{ return epsilon_;}

References epsilon_.

Referenced by setEpsilon().

◆ nbIterBurn()

int STK::IMixtureAlgoPredict::nbIterBurn ( ) const
inline
Returns
the maximal number of iteration of the algorithm

Definition at line 72 of file STK_IMixtureAlgoPredict.h.

72{ return nbIterBurn_; }

References nbIterBurn_.

Referenced by setNbIterBurn().

◆ predictBayesClassifier()

bool STK::IMixtureAlgoPredict::predictBayesClassifier ( )
protected

predict class labels when there is no missing values.

In this case, there is no algorithm to do. Just call:

initializeStep();
eStep(); // will compute tik and zi values
finalizeStep();
Returns
true if no error occur, false otherwise

Definition at line 66 of file STK_IMixtureAlgoPredict.cpp.

67{
68#ifdef STK_MIXTURE_VERY_VERBOSE
69 stk_cout << _T("-------------------------------\n");
70 stk_cout << _T("Entering IMixtureAlgoPredict::predictBayesClassifier()\n");
71#endif
72
73
74 try
75 {
77 p_model_->eStep();
80 }
81 catch (Exception const& error)
82 {
84#ifdef STK_MIXTURE_VERBOSE
85 stk_cout << _T("An error occur in IMixtureAlgoPredict::run():\n") << msg_error_ << _T("\n");
86#endif
87 return false;
88 }
89 catch (Clust::exceptions const& error)
90 {
92#ifdef STK_MIXTURE_VERBOSE
93 stk_cout << _T("An error occur in IMixtureAlgoPredict::run():\n") << msg_error_ << _T("\n");
94#endif
95 return false;
96 }
97 return true;
98}
virtual void mapStep()
Compute zi using the Map estimate.
virtual void finalizeStep()
Finalize the estimation of the model.

References _T, STK::IRunnerBase::error(), STK::IMixtureComposer::eStep(), STK::Clust::exceptionToString(), STK::IMixtureComposer::finalizeStep(), STK::IMixtureComposer::initializeStep(), STK::IMixtureComposer::mapStep(), STK::IRunnerBase::msg_error_, p_model_, and stk_cout.

Referenced by STK::EMPredict::run(), and STK::SemiSEMPredict::run().

◆ setEpsilon()

void STK::IMixtureAlgoPredict::setEpsilon ( Real  epsilon)
inline

set tolerance value

Definition at line 86 of file STK_IMixtureAlgoPredict.h.

References epsilon(), and epsilon_.

◆ setModel()

void STK::IMixtureAlgoPredict::setModel ( IMixtureComposer p_model)

set model

Definition at line 59 of file STK_IMixtureAlgoPredict.cpp.

60{ p_model_ = p_model;}

References p_model_.

◆ setNbIterBurn()

void STK::IMixtureAlgoPredict::setNbIterBurn ( int  nbIterBurn)
inline

set number of burning iterations

Definition at line 82 of file STK_IMixtureAlgoPredict.h.

References nbIterBurn(), and nbIterBurn_.

◆ setNbIterLong() [1/2]

int STK::IMixtureAlgoPredict::setNbIterLong ( ) const
inline
Returns
the maximal number of iteration of the algorithm

Definition at line 74 of file STK_IMixtureAlgoPredict.h.

74{ return nbIterLong_; }

References nbIterLong_.

◆ setNbIterLong() [2/2]

void STK::IMixtureAlgoPredict::setNbIterLong ( int  nbIterLong)
inline

set number of long iterations

Definition at line 84 of file STK_IMixtureAlgoPredict.h.

84{ nbIterLong_ = nbIterLong; }

References nbIterLong_.

Member Data Documentation

◆ epsilon_

Real STK::IMixtureAlgoPredict::epsilon_
protected

tolerance of the algorithm.

Definition at line 96 of file STK_IMixtureAlgoPredict.h.

Referenced by epsilon(), STK::EMPredict::run(), and setEpsilon().

◆ nbIterBurn_

int STK::IMixtureAlgoPredict::nbIterBurn_
protected

Number of burning iterations of the algorithm.

Definition at line 92 of file STK_IMixtureAlgoPredict.h.

Referenced by nbIterBurn(), STK::EMPredict::run(), STK::SemiSEMPredict::run(), and setNbIterBurn().

◆ nbIterLong_

int STK::IMixtureAlgoPredict::nbIterLong_
protected

maximal number of iterations of the algorithm

Definition at line 94 of file STK_IMixtureAlgoPredict.h.

Referenced by burnStep(), STK::EMPredict::run(), STK::SemiSEMPredict::run(), setNbIterLong(), and setNbIterLong().

◆ p_model_

IMixtureComposer* STK::IMixtureAlgoPredict::p_model_
protected

pointer on the mixture model

Definition at line 90 of file STK_IMixtureAlgoPredict.h.

Referenced by burnStep(), predictBayesClassifier(), STK::EMPredict::run(), STK::SemiSEMPredict::run(), and setModel().


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