58#ifdef STK_MIXTURE_DEBUG
62#ifdef STK_MIXTURE_DEBUG
66#ifdef STK_MIXTURE_VERBOSE
69 <<
_T(
", nbShortRun_ = ") <<
p_param_->nbShortRun_
70 <<
_T(
", p_model_->lnLikelihood() = ") << initialValue
79 for (
int iTry = 0; iTry <
nbTry_; ++iTry)
88#ifdef STK_MIXTURE_VERBOSE
89 stk_cout <<
_T(
"In FullStrategy::run()") <<
_T(
", iTyry =") << iTry
90 <<
_T(
", init step failed\n");
97#ifdef STK_MIXTURE_VERY_VERBOSE
98 stk_cout <<
_T(
"In FullStrategy::run(), entering short run steps\n")
99 <<
_T(
"iTyry =") << iTry <<
_T(
"\n");
102 for (
int iShort=0; iShort <
p_param_->nbShortRun_; ++iShort)
104#ifdef STK_MIXTURE_VERY_VERBOSE
105 stk_cout <<
_T(
"In FullStrategy::run(), iShort =") << iShort <<
_T(
"\n");
112#ifdef STK_MIXTURE_VERBOSE
113 stk_cout <<
_T(
"In FullStrategy::run()") <<
_T(
", iTyry =") << iTry <<
_T(
", iShort =") << iShort
114 <<
_T(
", init step failed\n");
122 std::swap(p_bestShortModel, p_bestModel);
124#ifdef STK_MIXTURE_VERY_VERBOSE
126 <<
_T(
", iTyry =") << iTry <<
_T(
", iShort =") << iShort
127 <<
_T(
", get better value in short run. valueBest =") << valueBest <<
_T(
"\n");
132 if (p_bestModel) {
delete p_bestModel; p_bestModel = 0;}
135 if (!p_bestShortModel) { p_bestShortModel =
p_model_->clone();}
136#ifdef STK_MIXTURE_VERY_VERBOSE
137 stk_cout <<
_T(
"In FullStrategy::run() all short run done") <<
_T(
", iTyry =") << iTry <<
_T(
" terminated.\n")
138 <<
_T(
"p_bestShortModel->lnLikelihood() = ") << p_bestShortModel->lnLikelihood()
143 p_param_->p_longAlgo_->setModel(p_bestShortModel);
148#ifdef STK_MIXTURE_VERBOSE
149 stk_cout <<
_T(
"In FullStrategy::run(): Long Algo failed\n");
152#ifdef STK_MIXTURE_VERY_VERBOSE
153 stk_cout <<
_T(
"In FullStrategy::run() long run") <<
_T(
", iTyry =") << iTry <<
_T(
" terminated.\n")
154 <<
_T(
"p_bestShortModel->lnLikelihood() = ") << p_bestShortModel->lnLikelihood()
158 if(
p_model_->lnLikelihood()<p_bestShortModel->lnLikelihood())
160 std::swap(
p_model_, p_bestShortModel);
163#ifdef STK_MIXTURE_VERBOSE
164 stk_cout <<
_T(
"In FullStrategy::run(), iTry =") << iTry <<
_T(
" failed\n");
167 if (p_bestModel)
delete p_bestModel;
169 if (p_bestShortModel)
delete p_bestShortModel;
170 p_bestShortModel = 0;
175 if (p_bestModel)
delete p_bestModel;
176 if (p_bestShortModel)
delete p_bestShortModel;
180#ifdef STK_MIXTURE_VERBOSE
181 stk_cout <<
"FullStrategy::run() terminated. \n";
185 if (p_bestModel)
delete p_bestModel;
186 if (p_bestShortModel)
delete p_bestShortModel;
187 if (
p_model_->lnLikelihood() <= initialValue)
198#ifdef STK_MIXTURE_VERBOSE
200 stk_cout <<
_T(
"Entering FullStrategy::initStep\n");
208 for (
int iInitRun=0; iInitRun <
p_param_->nbInitRun_; iInitRun++)
212 { p_initModel =
p_model_->create();}
213 p_init_->setModel(p_initModel);
216#ifdef STK_MIXTURE_VERBOSE
217 stk_cout <<
_T(
"FullStrategy::initStep, iInitRun=") << iInitRun
218 <<
_T(
", initialization failed:\n");
227 if( (valueBest < value) &&
isFinite(value))
229 std::swap(p_initModel, p_bestModel);
231#ifdef STK_MIXTURE_VERY_VERBOSE
232 stk_cout <<
_T(
"FullStrategy::initStep, iInitRun =") << iInitRun
233 <<
_T(
", get a better model with value =") << valueBest <<
_T(
"\n");
240 if (!p_bestModel) { p_bestModel =
p_model_->clone();}
241 p_param_->p_shortAlgo_->setModel(p_bestModel);
246#ifdef STK_MIXTURE_VERBOSE
247 stk_cout <<
_T(
"In FullStrategy::initStep() shortAlgo failed:\n");
258 if (!p_bestModel) { p_bestModel =
p_model_->clone();}
261#ifdef STK_MIXTURE_DEBUG_CREATE
262 stk_cout <<
_T(
"FullStrategy::initStep terminated. Deleting p_initModel.\n");
264 delete p_initModel; p_initModel = 0;
265#ifdef STK_MIXTURE_DEBUG_CREATE
266 stk_cout <<
_T(
"FullStrategy::initStep p_initModel deleted.\n");
267 stk_cout <<
_T(
"p_bestModel->writeParameters\n");
271#ifdef STK_MIXTURE_VERBOSE
272 stk_cout <<
_T(
"FullStrategy::initStep done\n");
In this file we define the class implementing the full strategy class.
In this file we define the abstract base class for mixture models.
#define STKERROR_NO_ARG(Where, Error)
In this file we define mixture algorithms.
In this file we define the interface base class for initialization methods.
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
This file include all the other header files of the project Sdk.
Base class for all Exceptions thrown by the STK++ library.
virtual const String error() const
Returns a C-style character string describing the general cause of the current error.
virtual bool run()
run the strategy
FullStrategyParam * p_param_
bool initStep(IMixtureComposer *&p_bestModel)
Perform the Initialization step Initialize nbInitRun_ (should be > 0) model and select the best model...
Base class for Mixture (composed) model.
virtual void writeParameters(ostream &os) const
write the parameters of the model in the stream os.
int nbTry_
number of tries of each strategies (1 by default)
IMixtureInit * p_init_
initialization method
IMixtureComposer *& p_model_
reference on the main model
String msg_error_
String with the last error message.
Real lnLikelihood() const
bool isFinite(Type const &x)
utility method allowing to know if a value is a finite value
@ modelInitialized_
the model is initialized and its parameters are initialized to default values
double Real
STK fundamental type of Real values.
The namespace STK is the main domain space of the Statistical ToolKit project.
Arithmetic properties of STK fundamental types.
IMixtureAlgo * p_longAlgo_
algorithm to use in long run
IMixtureAlgo * p_shortAlgo_
algorithm to use in short runs
virtual ~FullStrategyParam()
destructor