STK++ 0.9.13
STK_SimpleStrategy.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/* destructor */
48
49/* run the simple strategy */
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
58 if (p_model_->state() < 1) { p_model_->randomFuzzyInit();}
59 Real value = p_model_->lnLikelihood();
60 try
61 {
63
64 // initialize and run algo. break if success
65 for (int iTry = 0; iTry < nbTry_; ++iTry)
66 {
67 // initialize current model
69 if (!p_init_->run())
70 {
71#ifdef STK_MIXTURE_VERBOSE
72 stk_cout << "SimpleStrategy::run(), Initialization failed.\n";
73#endif
76 } // init step
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 }
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}
108
109
110} // namespace STK
111
112
113
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
SimpleStrategyParam * p_param_
double Real
STK fundamental type of Real values.
The namespace STK is the main domain space of the Statistical ToolKit project.
IMixtureAlgo * p_algo_
number of iterations in the Initialization
virtual ~SimpleStrategyParam()
destructor