STK++ 0.9.13
STK_MixtureInit.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: 24 août 2013
28 * Author: iovleff, serge.iovleff@stkpp.org
29 **/
30
35#include <Sdk.h>
36
40
41#if STK_MIXTURE_DEBUG | STK_MIXTURE_VERBOSE | STK_MIXTURE_VERY_VERBOSE
43#endif
44
45namespace STK
46{
47
51
52/* launch the algorithm of the initialization step */
63
64/* call the randomClassInit() model initialization.
65 * @return @c true if no error occur, @c false otherwise*/
67{
68#ifdef STK_MIXTURE_VERY_VERBOSE
69 stk_cout << _T("--------------------------\n")
70 << _T("Entering RandomInit::run()\n")
71 << _T("nbTry = ") << nbTry_ << _T("\n");
72#endif
73 bool result = false;
74 int iTry;
75 for (iTry= 0; iTry < nbTry_; ++iTry)
76 {
77 try
78 {
81 if (runInitAlgo()) { result = true; break;}
82#ifdef STK_MIXTURE_VERBOSE
83 stk_cout << _T("In RandomInit::run(), try number") << iTry << " runInitAlgo() failed.\n";
84#endif
87 }
88 catch (Clust::exceptions const& error)
89 {
92#ifdef STK_MIXTURE_VERBOSE
93 stk_cout << _T("In RandomInit::run(), try number") << iTry << " generate an exception.\n";
94 stk_cout << _T("In RandomInit::run(), error") << msg_error_ << _T("\n");
95#endif
96 }
97 catch (Exception const& error)
98 {
101#ifdef STK_MIXTURE_VERBOSE
102 stk_cout << _T("In RandomInit::run(), try number") << iTry << " generate an exception.\n";
103 stk_cout << _T("In RandomInit::run(), error") << msg_error_ << _T("\n");
104#endif
105 }
106 } // iTry
107#ifdef STK_MIXTURE_VERY_VERBOSE
108 stk_cout << _T("RandomInit::run() done\n")
109 << _T("----------------------\n");
110#endif
111 return result;
112}
113
114/* call the randomClassInit() model initialization.
115 * @return @c true if no error occur, @c false otherwise*/
117{
118#ifdef STK_MIXTURE_VERY_VERBOSE
119 stk_cout << _T("-------------------------\n")
120 << _T("Entering ClassInit::run()\n")
121 << _T("nbTry = ") << nbTry_ << _T("\n");
122#endif
123 bool result = false;
124 int iTry;
125 for (iTry= 0; iTry < nbTry_; ++iTry)
126 {
127 try
128 {
131 if (runInitAlgo()) { result = true; break;}
132#ifdef STK_MIXTURE_VERBOSE
133 stk_cout << _T("In ClassInit::run(), try number: ") << iTry << _T(" runInitAlgo() failed.\n");
134 stk_cout << _T("What: ") << p_initAlgo_->error() << _T("\n");
135#endif
138 }
139 catch (Clust::exceptions const& error)
140 {
143#ifdef STK_MIXTURE_VERBOSE
144 stk_cout << _T("In ClassInit::run(), try number") << iTry << " generate an exception.\n";
145 stk_cout << _T("In ClassInit::run(), error") << msg_error_ << _T("\n");
146#endif
147 }
148 catch (Exception const& error)
149 {
150 String msg = error.error();
152#ifdef STK_MIXTURE_VERBOSE
153 stk_cout << _T("In ClassInit::run(), try number") << iTry << " generate an exception.\n";
154 stk_cout << _T("In ClassInit::run(), error") << msg_error_ << _T("\n");
155#endif
156 }
157 }
158#ifdef STK_MIXTURE_VERY_VERBOSE
159 stk_cout << _T("Exiting ClassInit::run()\n")
160 << _T("------------------------\n");
161#endif
162 return result;
163}
164
165/* call the randomClassInit() model initialization.
166 * @return @c true if no error occur, @c false otherwise*/
168{
169#ifdef STK_MIXTURE_VERY_VERBOSE
170 stk_cout << _T("-------------------------\n")
171 << _T("Entering FuzzyInit::run()\n")
172 << _T("nbTry = ") << nbTry_ << _T("\n");
173#endif
174 bool result = false;
175 int iTry;
176 for (iTry= 0; iTry < nbTry_; ++iTry)
177 {
178 try
179 {
182 if (runInitAlgo()) { result = true; break;}
183#ifdef STK_MIXTURE_VERBOSE
184 stk_cout << _T("In FuzzyInit::run(), try number") << iTry << " runInitAlgo() failed.\n";
185#endif
188 }
189 catch (Clust::exceptions const& error)
190 {
193#ifdef STK_MIXTURE_VERBOSE
194 stk_cout << _T("In FuzzyInit::run(), try number") << iTry << _T(" generate an exception.\n");
195 stk_cout << _T("In FuzzyInit::run(), error") << msg_error_ << _T("\n");
196#endif
197 }
198 catch (Exception const& error)
199 {
200 String msg = error.error();
202#ifdef STK_MIXTURE_VERBOSE
203 stk_cout << _T("In FuzzyInit::run(), try number") << iTry << " generate an exception.\n";
204 stk_cout << _T("In FuzzyInit::run(), error") << msg_error_ << _T("\n");
205#endif
206 }
207 } // iTry
208#ifdef STK_MIXTURE_VERBOSE
209 stk_cout << _T("Exiting FuzzyInit::run()\n")
210 << _T("------------------------\n");
211#endif
212 return result;
213}
214
215} // namespace STK
This file define methods for displaying Arrays and Expressions.
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.
virtual bool run()
run the initialization by calling the randomClassInit method of the model.
Sdk class for all library Exceptions.
virtual bool run()
run the algorithm on the model calling E step and M step.
void setModel(IMixtureComposer *p_model)
set model
virtual void initializeStep()
Initialize the model before its first use.
void randomFuzzyInit()
Initialize randomly the posterior probabilities tik of the model, then compute the zi values with map...
void randomClassInit()
Initialize randomly the labels zi of the model.
virtual void randomInit()=0
initialize randomly the parameters of the components of the model
IMixtureComposer * p_model_
pointer on the mixture model
IMixtureAlgo * p_initAlgo_
algorithm to use in the initialization
virtual ~IMixtureInit()
destructor
IMixtureAlgo const *const p_initAlgo() const
set a the number of try
bool runInitAlgo()
launch the initialization algorithm.
int nbTry_
number of retry in initialization
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 initialization by calling the randomInit method of the model.
String exceptionToString(exceptions const &type)
convert a Clust::exceptions to a String.
exceptions
Specific exceptions allowing to handle the erroros that can occur in the estimation process.
std::basic_string< Char > String
STK fundamental type of a String.
The namespace STK is the main domain space of the Statistical ToolKit project.