STK++ 0.9.13
STK::SimpleStrategy Class Reference

A SimpleStrategy is just nbTry long run. More...

#include <STK_MixtureStrategy.h>

Inheritance diagram for STK::SimpleStrategy:
Inheritance graph

Public Member Functions

 SimpleStrategy (IMixtureComposer *&p_model)
 default constructor.
 
 SimpleStrategy (SimpleStrategy const &strategy)
 copy constructor.
 
virtual ~SimpleStrategy ()
 destructor
 
virtual SimpleStrategyclone () const
 clone pattern
 
void setParam (SimpleStrategyParam *p_param)
 set the parameters of the strategy
 
virtual bool run ()
 run the strategy
 
 SimpleStrategy (IMixtureComposer *&p_model)
 default constructor.
 
 SimpleStrategy (SimpleStrategy const &strategy)
 copy constructor.
 
virtual ~SimpleStrategy ()
 destructor
 
virtual SimpleStrategyclone () const
 clone pattern
 
void setParam (SimpleStrategyParam *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

SimpleStrategyParamp_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 SimpleStrategy is just nbTry long run.

Definition at line 64 of file STK_MixtureStrategy.h.

Constructor & Destructor Documentation

◆ SimpleStrategy() [1/4]

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

default constructor.

Parameters
p_modela reference pointer on the model to estimate

Definition at line 70 of file STK_MixtureStrategy.h.

70 : IMixtureStrategy(p_model), p_param_(0)
71 {}
IMixtureStrategy(IMixtureComposer *&p_model)
default constructor.
SimpleStrategyParam * p_param_

◆ SimpleStrategy() [2/4]

STK::SimpleStrategy::SimpleStrategy ( SimpleStrategy const strategy)
inline

copy constructor.

Parameters
strategythe strategy to copy

Definition at line 75 of file STK_MixtureStrategy.h.

75 : IMixtureStrategy(strategy), p_param_(0)
76 {}

◆ ~SimpleStrategy() [1/2]

virtual STK::SimpleStrategy::~SimpleStrategy ( )
inlinevirtual

destructor

Definition at line 79 of file STK_MixtureStrategy.h.

79{ if (p_param_) delete p_param_;}

References p_param_.

◆ SimpleStrategy() [3/4]

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

default constructor.

Parameters
p_modela reference pointer on the model to estimate

Definition at line 69 of file STK_SimpleStrategy.h.

69 : IMixtureStrategy(p_model), p_param_(0)
70 {}

◆ SimpleStrategy() [4/4]

STK::SimpleStrategy::SimpleStrategy ( SimpleStrategy const strategy)
inline

copy constructor.

Parameters
strategythe strategy to copy

Definition at line 74 of file STK_SimpleStrategy.h.

74 : IMixtureStrategy(strategy), p_param_(0)
75 {}

◆ ~SimpleStrategy() [2/2]

virtual STK::SimpleStrategy::~SimpleStrategy ( )
inlinevirtual

destructor

Definition at line 78 of file STK_SimpleStrategy.h.

78{ if (p_param_) delete p_param_;}

References p_param_.

Member Function Documentation

◆ clone() [1/2]

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

clone pattern

Definition at line 81 of file STK_MixtureStrategy.h.

81{ return new SimpleStrategy(*this);}
SimpleStrategy(IMixtureComposer *&p_model)
default constructor.

◆ clone() [2/2]

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

clone pattern

Definition at line 80 of file STK_SimpleStrategy.h.

80{ return new SimpleStrategy(*this);}

◆ run() [1/2]

bool STK::SimpleStrategy::run ( )
virtual

run the strategy

Implements STK::IRunnerBase.

Definition at line 50 of file STK_SimpleStrategy.cpp.

51{
52#ifdef STK_MIXTURE_VERBOSE
53 stk_cout << _T("-----------------------------------------------\n");
54 stk_cout << _T("Entering SimpleStrategy::run() with: ")
55 << _T("nbTry_ = ") << nbTry_ << _T("\n");
56#endif
57 IMixtureComposer* p_currentModel = 0;
58 if (p_model_->state() < 1) { p_model_->randomFuzzyInit();}
59 Real value = p_model_->lnLikelihood();
60 try
61 {
62 p_currentModel = p_model_->create();
63
64 // initialize and run algo. break if success
65 for (int iTry = 0; iTry < nbTry_; ++iTry)
66 {
67 // initialize current model
68 p_init_->setModel(p_currentModel);
69 if (!p_init_->run())
70 {
71#ifdef STK_MIXTURE_VERBOSE
72 stk_cout << "SimpleStrategy::run(), Initialization failed.\n";
73#endif
74 msg_error_ += STKERROR_NO_ARG(SimpleStrategy::run,Initialization failed\n);
76 } // init step
77 p_param_->p_algo_->setModel(p_currentModel);
78 // initial
79 if (!p_param_->p_algo_->run())
80 {
81#ifdef STK_MIXTURE_VERBOSE
82 stk_cout << "SimpleStrategy::run(), Long run failed.\n";
83#endif
86 }
87 else { break;} // we get a result
88 } // iTry
89 }
90 catch (Exception const& e)
91 {
92 msg_error_ = e.error();
93 return false;
94 }
95 storeModel(p_currentModel);
96 delete p_currentModel;
97#ifdef STK_MIXTURE_VERBOSE
98 stk_cout << "SimpleStrategy::run() terminated. \n";
99 stk_cout << "-----------------------------------------------\n";
100#endif
101 if (p_model_->lnLikelihood() <= value)
102 {
104 return false;
105 }
106 return true;
107}
#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.
String const & error() const
get the last error message.
Definition STK_IRunner.h:82
virtual bool run()
run the strategy
double Real
STK fundamental type of Real values.
IMixtureAlgo * p_algo_
number of iterations in the Initialization

References _T, STK::IMixtureComposer::create(), STK::IRunnerBase::error(), STK::IStatModelBase::lnLikelihood(), STK::IRunnerBase::msg_error_, STK::IMixtureStrategy::nbTry_, STK::SimpleStrategyParam::p_algo_, STK::IMixtureStrategy::p_init_, STK::IMixtureStrategy::p_model_, p_param_, 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::SimpleStrategy::run ( )
virtual

run the strategy

Implements STK::IRunnerBase.

◆ setParam() [1/2]

void STK::SimpleStrategy::setParam ( SimpleStrategyParam p_param)
inline

set the parameters of the strategy

Parameters
p_paramthe parameters of the strategy

Definition at line 84 of file STK_MixtureStrategy.h.

84{ p_param_ = p_param;}

References p_param_.

◆ setParam() [2/2]

void STK::SimpleStrategy::setParam ( SimpleStrategyParam p_param)
inline

set the parameters of the strategy

Parameters
p_paramthe parameters of the strategy

Definition at line 83 of file STK_SimpleStrategy.h.

83{ p_param_ = p_param;}

References p_param_.

Member Data Documentation

◆ p_param_

SimpleStrategyParam * STK::SimpleStrategy::p_param_
protected

Definition at line 90 of file STK_MixtureStrategy.h.

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


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