STK++ 0.9.13
STK_MixtureComposerFacade.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------*/
2/* Copyright (C) 2004-2015 Serge Iovleff, University 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 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 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: MixAll
27 * created on: 11 Mars 2018
28 * Author: Iovleff, serge.iovleff@stkpp.org
29 **/
30
36#ifndef STK_MIXTURECOMPOSERFACADE_H
37#define STK_MIXTURECOMPOSERFACADE_H
38
39#include "STK_MixtureComposer.h"
48
49namespace STK
50{
51
56template<class DataHandler_>
58{
59 public:
63 DataHandler_ handler_;
68
84
85 // getters
88 { return p_composer_;}
90 DataHandler_ const& handler() const
91 { return handler_;}
93 DataHandler_ const& kerHandler() const
94 { return kerHandler_;}
109 { return kmmManager_;}
110
111 // setters
113 bool setParameters( std::string const& idData, ArrayXX const& param);
115 void setDiagGaussianParameters( std::string const& idData, ArrayXX const& param);
117 void setPoissonParameters( std::string const& idData, ArrayXX const& param);
119 void setGammaParameters( std::string const& idData, ArrayXX const& param);
121 void setCategoricalParameters( std::string const& idData, ArrayXX const& param);
123 void setKmmParameters( std::string const& idData, ArrayXX const& param);
124
126 bool getParameters( std::string const& idData, ArrayXX& param);
128 void getDiagGaussianParameters( std::string const& idData, ArrayXX& param);
130 void getPoissonParameters( std::string const& idData, ArrayXX& param);
132 void getGammaParameters( std::string const& idData, ArrayXX& param);
134 void getCategoricalParameters( std::string const& idData, ArrayXX& param);
136 void getKmmParameters( std::string const& idData, ArrayXX& param);
137
140 void createMixtureComposer(int nbCluster);
143 void createMixtureComposerFixedProp(int nbCluster);
146 void createMixtureSemiLearner(int nbCluster);
149 void createMixtureSemiLearnerFixedProp(int nbCluster);
151 void deleteComposer();
153 void createMixtures();
154
160 template<class Array>
161 void setMixtureParameters( Array const& tik);
169 template<class Array, class RowVector>
170 void setMixtureParameters( Array const& tik, RowVector const& pk);
174 template<class RowVector>
175 void setProportions( RowVector const& pk);
176
177 protected:
186};
187
188/* create a MixtureComposer */
189template<class DataHandler_>
191{ p_composer_ = new MixtureComposer(handler().nbSample(), nbCluster) ;}
192
193/* create a MixtureComposerFixedProp */
194template<class DataHandler_>
196{ p_composer_ = new MixtureComposerFixedProp(handler().nbSample(), nbCluster) ;}
197
198/* create a MixtureComposer */
199template<class DataHandler_>
201{ p_composer_ = new MixtureSemiLearner(handler().nbSample(), nbCluster) ;}
202
203/* create a MixtureComposerFixedProp */
204template<class DataHandler_>
206{ p_composer_ = new MixtureSemiLearnerFixedProp(handler().nbSample(), nbCluster) ;}
207
208/* create a MixtureComposerFixedProp */
209template<class DataHandler_>
211{ if (p_composer_) delete p_composer_; p_composer_ = 0;}
212
213/* create the mixtures in the given learner */
214template<class DataHandler_>
216{
217 p_composer_->createMixture(diagGaussianManager_);
218 p_composer_->createMixture(poissonManager_);
219 p_composer_->createMixture(gammaManager_);
220 p_composer_->createMixture(categoricalManager_);
221 p_composer_->createMixture(kmmManager_);
222}
223
224/* fill param with the parameters */
225template<class DataHandler_>
226bool MixtureComposerFacade<DataHandler_>::getParameters( std::string const& idData, ArrayXX& param)
227{
228 // get idModel from idData
230 if(!handler_.getIdModelName(idData, idModel)) { return false;} // should not happened
231
232 // get mixture id
235 {
236 bool prop;
238 }
239
240 // get mixture class (gamma, Gaussian, Poisson, etc.) and parameters for this class of mixture
242 {
244 getDiagGaussianParameters( idData, param);
245 return true;
246 break;
247 case Clust::Poisson_:
248 getPoissonParameters( idData, param);
249 return true;
250 break;
251 case Clust::Gamma_:
252 getGammaParameters( idData, param);
253 return true;
254 break;
256 getCategoricalParameters( idData, param);
257 return true;
258 break;
259 case Clust::Kmm_:
260 getKmmParameters( idData, param);
261 return true;
262 break;
264 return false;
265 break;
266 default:
267 return false;
268 break;
269 }
270 return false; // avoid compiler warning
271}
272
273/* set model parameters with param */
274template<class DataHandler_>
275bool MixtureComposerFacade<DataHandler_>::setParameters( std::string const& idData, ArrayXX const& param)
276{
277 // get idModel from idData
279 if(!handler_.getIdModelName(idData, idModel)) { return false;}
280 // get mixture id
283 {
284 bool prop;
286 }
287
288 // get mixture class (gamma, Gaussian, Poisson, etc.) and parameters for this class of mixture
290 {
292 setDiagGaussianParameters( idData, param);
293 return true;
294 break;
295 case Clust::Poisson_:
296 setPoissonParameters( idData, param);
297 return true;
298 break;
299 case Clust::Gamma_:
300 setGammaParameters( idData, param);
301 return true;
302 break;
304 setCategoricalParameters( idData, param);
305 return true;
306 break;
307 case Clust::Kmm_:
308 setKmmParameters( idData, param);
309 return true;
310 break;
312 return false;
313 break;
314 default:
315 return false;
316 break;
317 }
318 return true; // avoid compiler warning
319}
320/* get the diagonal Gaussian parameters */
321template<class DataHandler_>
323{ p_composer_->getParameters(diagGaussianManager_,idData, param);}
324/* get the Poisson parameters */
325template<class DataHandler_>
327{ p_composer_->getParameters(poissonManager_,idData, param);}
328/* get the gamma parameters */
329template<class DataHandler_>
331{ p_composer_->getParameters(gammaManager_,idData, param);}
332/* get the Categorical parameters */
333template<class DataHandler_>
335{ p_composer_->getParameters(categoricalManager_,idData, param);}
336/* get the kernel parameters */
337template<class DataHandler_>
339{ p_composer_->getParameters(kmmManager_,idData, param);}
340
341
342// setters
343/* set the diagonal Gaussian parameters */
344template<class DataHandler_>
346{ p_composer_->setParameters(diagGaussianManager_,idData, param);}
347/* set the diagonal Gaussian parameters */
348template<class DataHandler_>
349void MixtureComposerFacade<DataHandler_>::setPoissonParameters( std::string const& idData, ArrayXX const& param)
350{ p_composer_->setParameters(poissonManager_,idData, param);}
351/* set the gamma parameters */
352template<class DataHandler_>
353void MixtureComposerFacade<DataHandler_>::setGammaParameters( std::string const& idData, ArrayXX const& param)
354{ p_composer_->setParameters(gammaManager_,idData, param);}
355/* set the Categorical parameters */
356template<class DataHandler_>
357void MixtureComposerFacade<DataHandler_>::setCategoricalParameters( std::string const& idData, ArrayXX const& param)
358{ p_composer_->setParameters(categoricalManager_,idData, param);}
359/* set the Categorical parameters */
360template<class DataHandler_>
361void MixtureComposerFacade<DataHandler_>::setKmmParameters( std::string const& idData, ArrayXX const& param)
362{ p_composer_->setParameters(kmmManager_,idData, param);}
363
364template<class DataHandler_>
365template<class Array>
367{ p_composer_->setMixtureParameters(tik);}
368
369template<class DataHandler_>
370template<class Array, class RowVector>
371void MixtureComposerFacade<DataHandler_>::setMixtureParameters( Array const& tik, RowVector const& pk)
372{ p_composer_->setMixtureParameters(tik, pk);}
373
374template<class DataHandler_>
375template<class RowVector>
377{ p_composer_->setProportions(pk);}
378
379
380} // namespace STK
381
382#endif /* STK_MIXTURECOMPOSERFACADE_H */
In this file we define the CategoricalMixtureManager class.
In this file we define the DiagGaussianMixtureManager class.
In this file we define the GammaMixtureManager class.
In this file we define the KernelMixtureManager class.
In this file we define the class MixtureComposer.
In this file we define the MixtureSemiLearner class for semi-supervised learning models.
In this file we define the PoissonMixtureManager class.
Base class for Mixture (composed) model.
implementation of the DataHandlerBase class for kernel mixture models.
A mixture manager is a factory class for injection dependency in the STK++ derived class of the Mixtu...
The MixtureComposerFacade allows to interact with a composer for estimating a mixture model with less...
void setDiagGaussianParameters(std::string const &idData, ArrayXX const &param)
set diagonal Gaussian parameters
void getKmmParameters(std::string const &idData, ArrayXX &param)
get Kernel Mixture Model parameters
KernelMixtureManager const & kmmManager() const
Kernel Mixture Manager.
DataHandler_ const & handler() const
void setProportions(RowVector const &pk)
Set proportions of each classes.
IMixtureComposer * p_composer_
pointer on the main p_composer
DiagGaussianMixtureManager< DataHandler_ > const & diagGaussianManager() const
void createMixtureComposerFixedProp(int nbCluster)
create a MixtureComposerFixedProp @nbCluster number of cluster
void createMixtureSemiLearner(int nbCluster)
create a MixtureSemiLearner @nbCluster number of cluster
KernelHandler kerHandler_
handler for kernel mixture models
CategoricalMixtureManager< DataHandler_ > const & categoricalManager() const
categorical mixture models manager
PoissonMixtureManager< DataHandler_ > const & poissonManager() const
GammaMixtureManager< DataHandler_ > const & gammaManager() const
gamma mixture models manager
void getGammaParameters(std::string const &idData, ArrayXX &param)
get gamma parameters
void getPoissonParameters(std::string const &idData, ArrayXX &param)
get Poisson parameters
void createMixtureSemiLearnerFixedProp(int nbCluster)
create a MixtureSemiLearnerFixedProp @nbCluster number of cluster
DataHandler_ handler_
data handler for model based mixture models
void getCategoricalParameters(std::string const &idData, ArrayXX &param)
get categorical parameters
MixtureComposerFacade(IMixtureComposer *p_composer=0)
constructor.
void setKmmParameters(std::string const &idData, ArrayXX const &param)
set Kernel Mixture Model parameters
bool getParameters(std::string const &idData, ArrayXX &param)
get parameters
DiagGaussianMixtureManager< DataHandler_ > diagGaussianManager_
diagonal Gaussian mixture models manager
PoissonMixtureManager< DataHandler_ > poissonManager_
Poisson mixture models manager.
void getDiagGaussianParameters(std::string const &idData, ArrayXX &param)
get diagonal Gaussian parameters
void setPoissonParameters(std::string const &idData, ArrayXX const &param)
set Poisson parameters
bool setParameters(std::string const &idData, ArrayXX const &param)
set parameters of a component
GammaMixtureManager< DataHandler_ > gammaManager_
gamma mixture models manager
void setCategoricalParameters(std::string const &idData, ArrayXX const &param)
set categorical parameters
DataHandler_ const & kerHandler() const
KernelMixtureManager kmmManager_
Kernel Mixture Manager.
void createMixtures()
create all mixtures
void setMixtureParameters(Array const &tik)
set the mixture parameters using an array of posterior probabilities.
void setGammaParameters(std::string const &idData, ArrayXX const &param)
set gamma parameters
CategoricalMixtureManager< DataHandler_ > categoricalManager_
categorical mixture models manager
void createMixtureComposer(int nbCluster)
create a MixtureComposer @nbCluster number of cluster
IMixtureComposer *const & p_composer() const
specialization of the composer for the fixed proportion case.
Main class for handling composed mixture models.
specialization of the composer for the fixed proportion case.
Base class for Learning a Mixture mixed model when some classes are known.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
MixtureClass mixtureToMixtureClass(Mixture const &type)
convert a Mixture to a MixtureClass.
Mixture stringToMixture(String const &type)
Convert a String to a Mixture.
Mixture
list of the mixtures that can be used by the composer
std::basic_string< Char > String
STK fundamental type of a String.
The namespace STK is the main domain space of the Statistical ToolKit project.