STK++ 0.9.13
STK_IMixtureAlgoPredict.cpp
Go to the documentation of this file.
1/*--------------------------------------------------------------------*/
2/* Copyright (C) 2004-2016 Serge Iovleff, Université Lille 1, Inria
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_Dot_org (see copyright for ...)
23*/
24
25/*
26 * Project: stkpp::Clustering
27 * created on: 16 oct. 2012
28 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 * Originally created by Parmeet bhatia <b..._DOT_p..._AT_gmail_Dot_com>
30 **/
31
38
39namespace STK
40{
41/* default constructor */
43 , p_model_(0)
44 , nbIterBurn_(0), nbIterLong_(0), epsilon_(0.) {}
45
46/* Copy constructor.
47 * @param algo the algorithm to copy */
49 , p_model_(algo.p_model_)
50 , nbIterBurn_(algo.nbIterBurn_)
51 , nbIterLong_(algo.nbIterLong_)
52 , epsilon_(algo.epsilon_)
53{}
54
55/* destructor */
57
58// threshold_ is set to this value in order to get stability on the results
61
62
63/* predict class labels when there is no missing values
64 * @return @c true if no error occur, @c false otherwise
65 */
67{
68#ifdef STK_MIXTURE_VERY_VERBOSE
69 stk_cout << _T("-------------------------------\n");
70 stk_cout << _T("Entering IMixtureAlgoPredict::predictBayesClassifier()\n");
71#endif
72
73
74 try
75 {
77 p_model_->eStep();
80 }
81 catch (Exception const& error)
82 {
84#ifdef STK_MIXTURE_VERBOSE
85 stk_cout << _T("An error occur in IMixtureAlgoPredict::run():\n") << msg_error_ << _T("\n");
86#endif
87 return false;
88 }
89 catch (Clust::exceptions const& error)
90 {
92#ifdef STK_MIXTURE_VERBOSE
93 stk_cout << _T("An error occur in IMixtureAlgoPredict::run():\n") << msg_error_ << _T("\n");
94#endif
95 return false;
96 }
97 return true;
98}
99
100// burn step
102{
103#ifdef STK_MIXTURE_VERY_VERBOSE
104 stk_cout << _T("-------------------------------\n");
105 stk_cout << _T("Entering IMixtureAlgoPredict::burnStep()\n");
106#endif
107 try
108 {
110 for (int iter = 0; iter < nbIterLong_; ++iter)
111 {
112 p_model_->sStep(); // simulate labels
113 p_model_->samplingStep(); // simulate missing values
114 p_model_->eStep(); // update tik and lnLikelihood
115 p_model_->storeIntermediateResults(iter+1); // store current parameters
116 }
117 }
118 catch (Clust::exceptions const& error)
119 {
121#ifdef STK_MIXTURE_VERBOSE
122 stk_cout << _T("An error occur in IMixtureAlgoPredict::run(): ") << msg_error_ << _T("\n");
123#endif
124 p_model_->setParametersStep(); // compute current parameters value
125 return false;
126 }
127 p_model_->setParametersStep(); // compute current parameters value
128 return true;
129}
130
131} // namespace STK
In this file we define the interface base class for mixture predicting algorithms.
In this file we define the abstract base class for mixture models.
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
Sdk class for all library Exceptions.
Interface base class for predicting algorithms.
bool predictBayesClassifier()
predict class labels when there is no missing values.
IMixtureAlgoPredict()
default constructor
virtual ~IMixtureAlgoPredict()
destructor
int nbIterLong_
maximal number of iterations of the algorithm
bool burnStep()
Perform burn step using SEM algorithm.
void setModel(IMixtureComposer *p_model)
set model
IMixtureComposer * p_model_
pointer on the mixture model
Base class for Mixture (composed) model.
virtual void initializeStep()
Initialize the model before its first use.
virtual Real eStep()
compute the zi, the lnLikelihood of the current estimates and the next value of the tik.
virtual void mapStep()
Compute zi using the Map estimate.
virtual int sStep()
Simulate zi accordingly to tik and replace tik by zik by calling cStep().
virtual void finalizeStep()
Finalize the estimation of the model.
virtual void setParametersStep()
Utility method allowing to signal to a mixture to set its parameters.
virtual void storeIntermediateResults(int iteration)
This step can be used to signal to the mixtures that they must store results.
virtual void samplingStep()
Simulation of all the latent variables and/or missing data excluding class labels.
Abstract base class for all classes having a.
Definition STK_IRunner.h:65
String msg_error_
String with the last error message.
Definition STK_IRunner.h:96
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...
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.
The namespace STK is the main domain space of the Statistical ToolKit project.