55{
56
58#ifdef STK_MIXTURE_DEBUG
60#endif
62#ifdef STK_MIXTURE_DEBUG
64#endif
66#ifdef STK_MIXTURE_VERBOSE
70 <<
_T(
", p_model_->lnLikelihood() = ") << initialValue
72#endif
73 IMixtureComposer *p_bestModel =0, *p_bestShortModel =0;
74
75 try
76 {
77
78
79 for (
int iTry = 0; iTry <
nbTry_; ++iTry)
80 {
81
83 {
85 {
88#ifdef STK_MIXTURE_VERBOSE
89 stk_cout <<
_T(
"In FullStrategy::run()") <<
_T(
", iTyry =") << iTry
90 <<
_T(
", init step failed\n");
92#endif
93 }
94 }
95 else
96 {
97#ifdef STK_MIXTURE_VERY_VERBOSE
98 stk_cout <<
_T(
"In FullStrategy::run(), entering short run steps\n")
99 <<
_T(
"iTyry =") << iTry <<
_T(
"\n");
100#endif
101 Real valueBest = -Arithmetic<Real>::infinity();
103 {
104#ifdef STK_MIXTURE_VERY_VERBOSE
105 stk_cout <<
_T(
"In FullStrategy::run(), iShort =") << iShort <<
_T(
"\n");
106#endif
107
109 {
112#ifdef STK_MIXTURE_VERBOSE
113 stk_cout <<
_T(
"In FullStrategy::run()") <<
_T(
", iTyry =") << iTry <<
_T(
", iShort =") << iShort
114 <<
_T(
", init step failed\n");
116#endif
117 }
118
119 Real value = p_bestModel->lnLikelihood();
120 if( valueBest<value)
121 {
122 std::swap(p_bestShortModel, p_bestModel);
123 valueBest = value;
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");
128#endif
129 }
130 }
131
132 if (p_bestModel) { delete p_bestModel; p_bestModel = 0;}
133 }
134
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()
140#endif
141
142
145 {
148#ifdef STK_MIXTURE_VERBOSE
149 stk_cout <<
_T(
"In FullStrategy::run(): Long Algo failed\n");
150#endif
151 }
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()
156#endif
157
159 {
160 std::swap(
p_model_, p_bestShortModel);
161 break;
162 }
163#ifdef STK_MIXTURE_VERBOSE
164 stk_cout <<
_T(
"In FullStrategy::run(), iTry =") << iTry <<
_T(
" failed\n");
165#endif
166
167 if (p_bestModel) delete p_bestModel;
168 p_bestModel = 0;
169 if (p_bestShortModel) delete p_bestShortModel;
170 p_bestShortModel = 0;
171 }
172 }
173 catch (Exception const& e)
174 {
175 if (p_bestModel) delete p_bestModel;
176 if (p_bestShortModel) delete p_bestShortModel;
178 return false;
179 }
180#ifdef STK_MIXTURE_VERBOSE
181 stk_cout <<
"FullStrategy::run() terminated. \n";
183#endif
184
185 if (p_bestModel) delete p_bestModel;
186 if (p_bestShortModel) delete p_bestShortModel;
188 {
190 return false;
191 }
192 return true;
193}
virtual bool run()
run the strategy
void setState(Clust::modelState state)
set the state of the model : should be used by any strategy
void randomFuzzyInit()
Initialize randomly the posterior probabilities tik of the model, then compute the zi values with map...
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)
Real lnLikelihood() const
@ modelInitialized_
the model is initialized and its parameters are initialized to default values
IMixtureAlgo * p_longAlgo_
algorithm to use in long run
int nbShortRun_
number of short run to perform