STK++ 0.9.13
STK_XemStrategy.cpp
Go to the documentation of this file.
1/*--------------------------------------------------------------------*/
2/* Copyright (C) 2004-2016 Serge Iovleff
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program; if not, write to the
16 Free Software Foundation, Inc.,
17 59 Temple Place,
18 Suite 330,
19 Boston, MA 02111-1307
20 USA
21
22 Contact : S..._DOT_I..._AT_stkpp.org (see copyright for ...)
23*/
24
25/*
26 * Project: stkpp::Clustering
27 * created on: 3 sept. 2013
28 * Author: iovleff, serge.iovleff@stkpp.org
29 **/
30
35#include <Sdk.h>
36
41
42namespace STK
43{
44
45
46/* destructor */
52
53
54/* run the xem strategy */
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
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
79 {
80 // initialize current model
82 if (p_init_->run())
83 {
84 // perform short run on the current model
87 // if we get a better result, swap it with currentBestModel
88 if( p_currentBestModel->lnLikelihood()<p_currentModel->lnLikelihood())
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
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
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}
132
133
134} // namespace STK
135
136
137
In this file we define the abstract base class for mixture models.
#define STKERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:49
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.
Sdk class for all library Exceptions.
void setModel(IMixtureComposer *p_model)
set model
Base class for Mixture (composed) 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
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
virtual bool run()
run the strategy
XemStrategyParam * p_param_
double Real
STK fundamental type of Real values.
The namespace STK is the main domain space of the Statistical ToolKit project.
virtual ~XemStrategyParam()
destructor
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