STK++ 0.9.13
STK::XemStrategy Class Reference

A XemStrategy is based on the following paradigm: More...

#include <STK_MixtureStrategy.h>

Inheritance diagram for STK::XemStrategy:
Inheritance graph

Public Member Functions

 XemStrategy (IMixtureComposer *&p_model)
 default constructor.
 
 XemStrategy (XemStrategy const &strategy)
 copy constructor.
 
virtual ~XemStrategy ()
 destructor
 
virtual XemStrategyclone () const
 clone pattern
 
void setParam (XemStrategyParam *p_param)
 set the parameters of the strategy
 
virtual bool run ()
 run the strategy
 
 XemStrategy (IMixtureComposer *&p_model)
 default constructor.
 
 XemStrategy (XemStrategy const &strategy)
 copy constructor.
 
virtual ~XemStrategy ()
 destructor
 
virtual XemStrategyclone () const
 clone pattern
 
void setParam (XemStrategyParam *p_param)
 set the parameters of the strategy
 
virtual bool run ()
 run the strategy
 
- Public Member Functions inherited from STK::IMixtureStrategy
 IMixtureStrategy (IMixtureComposer *&p_model)
 default constructor.
 
 IMixtureStrategy (IMixtureStrategy const &strategy)
 copy constructor
 
virtual ~IMixtureStrategy ()
 destructor
 
int nbTry () const
 
void setNbTry (int nbTry)
 set the number of tries of each strategies.
 
void setMixtureInit (IMixtureInit *p_init)
 set the initialization method to use
 
- Public Member Functions inherited from STK::IRunnerBase
String consterror () const
 get the last error message.
 

Protected Attributes

XemStrategyParamp_param_
 
- Protected Attributes inherited from STK::IMixtureStrategy
int nbTry_
 number of tries of each strategies (1 by default)
 
IMixtureComposer *& p_model_
 reference on the main model
 
IMixtureInitp_init_
 initialization method
 
- 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
 

Additional Inherited Members

- Protected Member Functions inherited from STK::IMixtureStrategy
void storeModel (IMixtureComposer *&p_otherModel)
 store a model in p_model_ if it is better.
 
- 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.
 

Detailed Description

A XemStrategy is based on the following paradigm:

  • perform nbShortRun of the shortAlgo with a small number of iterations and a high tolerance,
  • pick the best model obtained,
  • on this best model perform a long run. This strategy is used in Rmixmod R package.

Definition at line 118 of file STK_MixtureStrategy.h.

Constructor & Destructor Documentation

◆ XemStrategy() [1/4]

STK::XemStrategy::XemStrategy ( IMixtureComposer *&  p_model)
inline

default constructor.

Parameters
p_modela reference pointer on the model to estimate

Definition at line 124 of file STK_MixtureStrategy.h.

124 : IMixtureStrategy(p_model), p_param_()
125 {}
IMixtureStrategy(IMixtureComposer *&p_model)
default constructor.
XemStrategyParam * p_param_

◆ XemStrategy() [2/4]

STK::XemStrategy::XemStrategy ( XemStrategy const strategy)
inline

copy constructor.

Parameters
strategythe strategy to copy

Definition at line 129 of file STK_MixtureStrategy.h.

129 : IMixtureStrategy(strategy), p_param_(0)
130 {}

◆ ~XemStrategy() [1/2]

virtual STK::XemStrategy::~XemStrategy ( )
inlinevirtual

destructor

Definition at line 132 of file STK_MixtureStrategy.h.

132{ if (p_param_) delete p_param_;}

References p_param_.

◆ XemStrategy() [3/4]

STK::XemStrategy::XemStrategy ( IMixtureComposer *&  p_model)
inline

default constructor.

Parameters
p_modela reference pointer on the model to estimate

Definition at line 77 of file STK_XemStrategy.h.

77 : IMixtureStrategy(p_model), p_param_()
78 {}

◆ XemStrategy() [4/4]

STK::XemStrategy::XemStrategy ( XemStrategy const strategy)
inline

copy constructor.

Parameters
strategythe strategy to copy

Definition at line 82 of file STK_XemStrategy.h.

82 : IMixtureStrategy(strategy), p_param_(0)
83 {}

◆ ~XemStrategy() [2/2]

virtual STK::XemStrategy::~XemStrategy ( )
inlinevirtual

destructor

Definition at line 85 of file STK_XemStrategy.h.

85{ if (p_param_) delete p_param_;}

References p_param_.

Member Function Documentation

◆ clone() [1/2]

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

clone pattern

Definition at line 134 of file STK_MixtureStrategy.h.

134{ return new XemStrategy(*this);}
XemStrategy(IMixtureComposer *&p_model)
default constructor.

◆ clone() [2/2]

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

clone pattern

Definition at line 87 of file STK_XemStrategy.h.

87{ return new XemStrategy(*this);}

◆ run() [1/2]

bool STK::XemStrategy::run ( )
virtual

run the strategy

Implements STK::IRunnerBase.

Definition at line 55 of file STK_XemStrategy.cpp.

56{
57#ifdef STK_MIXTURE_VERY_VERBOSE
58 stk_cout << _T("Entering XemStrategy::run() with:\n")
59 << _T("nbTry_ = ") << nbTry_ << _T("\n")
60 << _T("nbShortRun_ = ") << p_param_->nbShortRun_ << _T("\n");
61#endif
62 // the current model is used in the short runs
63 IMixtureComposer* p_currentModel = p_model_->create();
64 IMixtureComposer* p_currentBestModel = p_model_->create();
65 // add some perturbation to the tik and compute the ln-likelihood
66 if (p_model_->state() < 1) { p_model_->randomFuzzyInit();}
67 Real value = p_model_->lnLikelihood();
68 // start estimation
69 try
70 {
71 for (int iTry = 0; iTry < nbTry_; ++iTry)
72 {
73#ifdef STK_MIXTURE_VERY_VERBOSE
74 stk_cout << _T("-------------------------------\n")
75 << _T("try number = ") << iTry << _T("\n");
76#endif
77 // find best of the shortModel and save it in p_currentBestModel
78 for (int iShortRun = 0; iShortRun < p_param_->nbShortRun_; ++iShortRun)
79 {
80 // initialize current model
81 p_init_->setModel(p_currentModel);
82 if (p_init_->run())
83 {
84 // perform short run on the current model
85 p_param_->p_shortAlgo_->setModel(p_currentModel);
87 // if we get a better result, swap it with currentBestModel
88 if( p_currentBestModel->lnLikelihood()<p_currentModel->lnLikelihood())
89 { std::swap(p_currentModel, p_currentBestModel);}
90 } // initialization
91 } // iShortRun
92 // in case nbShortRun_==0
93 // try to initialize bestCurrentModel, otherwise go to a next try
94 if (p_param_->nbShortRun_ == 0)
95 {
96 // initialize current model
97 p_init_->setModel(p_currentBestModel);
98 if (!p_init_->run())
99 { continue; }// model not initialized, we go to the next trial
100 }
101#ifdef STK_MIXTURE_VERBOSE
102 stk_cout << _T("iTry =") << iTry
103 << _T(". In XemStrategy::run(), short run terminated. best model:\n");
104 p_currentBestModel->writeParameters(stk_cout);
105 stk_cout << _T("\n\n");
106#endif
107 // start a long run with the better model
108 p_param_->p_longAlgo_->setModel(p_currentBestModel);
109 if (p_param_->p_longAlgo_->run()) { storeModel(p_currentBestModel); break;}
110#ifdef STK_MIXTURE_VERBOSE
111 stk_cout << "In FullStrategy::run(), Long run Failed.\n";
112#endif
113 } // end iTry
114 delete p_currentBestModel;
115 delete p_currentModel;
116 } catch (Exception const& e)
117 {
118 msg_error_ = e.error();
119 return false;
120 }
121#ifdef STK_MIXTURE_VERBOSE
122 stk_cout << "XemStrategy::run() terminated.\n";
123 stk_cout << "-------------------------------\n";
124#endif
125 if (p_model_->lnLikelihood() <= value)
126 {
128 return false;
129 }
130 return true;
131}
#define STKERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:49
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
void setModel(IMixtureComposer *p_model)
set model
void randomFuzzyInit()
Initialize randomly the posterior probabilities tik of the model, then compute the zi values with map...
virtual IMixtureComposer * create() const =0
create pattern
Clust::modelState state() const
void setModel(IMixtureComposer *p_model)
set a new model
int nbTry_
number of tries of each strategies (1 by default)
void storeModel(IMixtureComposer *&p_otherModel)
store a model in p_model_ if it is better.
IMixtureInit * p_init_
initialization method
IMixtureComposer *& p_model_
reference on the main model
String msg_error_
String with the last error message.
Definition STK_IRunner.h:96
virtual bool run()=0
run the computations.
virtual bool run()
run the strategy
double Real
STK fundamental type of Real values.
IMixtureAlgo * p_shortAlgo_
algorithm to use in short runs
IMixtureAlgo * p_longAlgo_
algorithm to use in long run
int nbShortRun_
number of short run to perform

References _T, STK::IMixtureComposer::create(), STK::IRunnerBase::error(), STK::IStatModelBase::lnLikelihood(), STK::IRunnerBase::msg_error_, STK::XemStrategyParam::nbShortRun_, STK::IMixtureStrategy::nbTry_, STK::IMixtureStrategy::p_init_, STK::XemStrategyParam::p_longAlgo_, STK::IMixtureStrategy::p_model_, p_param_, STK::XemStrategyParam::p_shortAlgo_, STK::IMixtureComposer::randomFuzzyInit(), run(), STK::IRunnerBase::run(), STK::IMixtureAlgo::setModel(), STK::IMixtureInit::setModel(), STK::IMixtureComposer::state(), stk_cout, STKERROR_NO_ARG, and STK::IMixtureStrategy::storeModel().

Referenced by run().

◆ run() [2/2]

virtual bool STK::XemStrategy::run ( )
virtual

run the strategy

Implements STK::IRunnerBase.

◆ setParam() [1/2]

void STK::XemStrategy::setParam ( XemStrategyParam p_param)
inline

set the parameters of the strategy

Parameters
p_paramthe parameters of the Xem strategy

Definition at line 138 of file STK_MixtureStrategy.h.

138{ p_param_ = p_param;}

References p_param_.

◆ setParam() [2/2]

void STK::XemStrategy::setParam ( XemStrategyParam p_param)
inline

set the parameters of the strategy

Parameters
p_paramthe parameters of the Xem strategy

Definition at line 91 of file STK_XemStrategy.h.

91{ p_param_ = p_param;}

References p_param_.

Member Data Documentation

◆ p_param_

XemStrategyParam * STK::XemStrategy::p_param_
protected

Definition at line 144 of file STK_MixtureStrategy.h.

Referenced by run(), setParam(), and ~XemStrategy().


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