STK++ 0.9.13
STK_GammaMixtureManager.h
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: 15 mars 2014
28 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
36#ifndef STK_GAMMAMIXTUREMANAGER_H
37#define STK_GAMMAMIXTUREMANAGER_H
38
39#include "../STK_IMixtureManager.h"
40#include "../STK_Clust_Util.h"
41
42#include "STK_GammaBridge.h"
43
44#define STK_CREATE_MIXTURE(Data, Bridge) \
45 Data* p_data = new Data(idData); \
46 registerDataBridge(p_data); \
47 p_handler()->getData(idData, p_data->dataij() ); \
48 return new Bridge( &(p_data->dataij()), idData, nbCluster);
49
50namespace STK
51{
52
53// forward declaration
54template<class DataHandler> class GammaMixtureManager;
55
56namespace hidden
57{
60template <class DataHandler_>
62{
64 typedef DataHandler_ DataHandler;
66 typedef Real Type;
68 typedef std::vector< std::pair<int,int> > MissingIndexes;
70 typedef std::vector< std::pair<std::pair<int,int>, Type > > MissingValues;
71
72 // All data handlers will store and return a specific container for
73 // the data they handle. The DataHandlerTraits class allow us to know the
74 // type of these containers when data is of type Type.
78 // Classes wrapping the Real and Integer containers
81};
82
83}
93template<class DataHandler>
94class GammaMixtureManager: public IMixtureManager<GammaMixtureManager<DataHandler> >
95{
96 public:
102
106 using Base::getIdModel;
107 using Base::p_handler;
108
109 // All Gamma bridges
122
124 GammaMixtureManager(DataHandler const& handler): Base(&handler) {}
127
133 {
135 if (idModel == Clust::unknown_mixture_) return;
136 // up-cast... (Yes it's bad....;)...)
137 switch (idModel)
138 {
141 break;
144 break;
147 break;
150 break;
153 break;
156 break;
159 break;
162 break;
165 break;
168 break;
171 break;
174 break;
175 default: // idModel is not implemented
176 break;
177 }
178 }
184 {
186 if (idModel == Clust::unknown_mixture_) return;
187 // up-cast... (Yes it's bad....;)...)
188 switch (idModel)
189 {
191 { static_cast<MixtureBridge_ajk_bjk*>(p_mixture)->getParameters(param);}
192 break;
194 { static_cast<MixtureBridge_ajk_bk*>(p_mixture)->getParameters(param);}
195 break;
197 { static_cast<MixtureBridge_ajk_bj*>(p_mixture)->getParameters(param);}
198 break;
200 { static_cast<MixtureBridge_ajk_b*>(p_mixture)->getParameters(param);}
201 break;
203 { static_cast<MixtureBridge_ak_bjk*>(p_mixture)->getParameters(param);}
204 break;
206 { static_cast<MixtureBridge_ak_bk*>(p_mixture)->getParameters(param);}
207 break;
209 { static_cast<MixtureBridge_ak_bj*>(p_mixture)->getParameters(param);}
210 break;
212 { static_cast<MixtureBridge_ak_b*>(p_mixture)->getParameters(param);}
213 break;
215 { static_cast<MixtureBridge_aj_bjk*>(p_mixture)->getParameters(param);}
216 break;
218 { static_cast<MixtureBridge_aj_bk*>(p_mixture)->getParameters(param);}
219 break;
221 { static_cast<MixtureBridge_a_bjk*>(p_mixture)->getParameters(param);}
222 break;
224 { static_cast<MixtureBridge_a_bk*>(p_mixture)->getParameters(param);}
225 break;
226 default: // idModel is not implemented
227 break;
228 }
229 }
234 void setParametersImpl(IMixture* p_mixture, ArrayXX const& param) const
235 {
237 if (idModel == Clust::unknown_mixture_) return;
238 // up-cast... (Yes it's bad....;)...)
239 switch (idModel)
240 {
242 { static_cast<MixtureBridge_ajk_bjk*>(p_mixture)->setParameters(param);}
243 break;
245 { static_cast<MixtureBridge_ajk_bk*>(p_mixture)->setParameters(param);}
246 break;
248 { static_cast<MixtureBridge_ajk_bj*>(p_mixture)->setParameters(param);}
249 break;
251 { static_cast<MixtureBridge_ajk_b*>(p_mixture)->setParameters(param);}
252 break;
254 { static_cast<MixtureBridge_ak_bjk*>(p_mixture)->setParameters(param);}
255 break;
257 { static_cast<MixtureBridge_ak_bk*>(p_mixture)->setParameters(param);}
258 break;
260 { static_cast<MixtureBridge_ak_bj*>(p_mixture)->setParameters(param);}
261 break;
263 { static_cast<MixtureBridge_ak_b*>(p_mixture)->setParameters(param);}
264 break;
266 { static_cast<MixtureBridge_aj_bjk*>(p_mixture)->setParameters(param);}
267 break;
269 { static_cast<MixtureBridge_aj_bk*>(p_mixture)->setParameters(param);}
270 break;
272 { static_cast<MixtureBridge_a_bjk*>(p_mixture)->setParameters(param);}
273 break;
275 { static_cast<MixtureBridge_a_bk*>(p_mixture)->setParameters(param);}
276 break;
277 default: // idModel is not implemented
278 break;
279 }
280 }
281
287 IMixture* createMixtureImpl(String const& modelName, String const& idData, int nbCluster)
288 {
290 return createMixtureImpl(idModel, idData, nbCluster);
291 }
292
293 private:
300 {
301 switch (idModel)
302 {
303 // gamma models
306 break;
309 break;
312 break;
315 break;
318 break;
321 break;
324 break;
327 break;
330 break;
335 break;
338 default:
339 return 0; // 0 if idModel is not implemented
340 break;
341 }
342 return 0; // 0 if idModel is not a STK++ model
343 }
344};
345
346} // namespace STK
347
348#undef STK_CREATE_MIXTURE
349
350#endif /* STK_GAMMAMIXTUREMANAGER_H */
#define STK_CREATE_MIXTURE(Data, Bridge)
In this file we define the bridge classes between the diagonal Gaussian mixtures and the composer.
A mixture manager is a factory class for injection dependency in the STK++ derived class of the Mixtu...
GammaMixtureManager(DataHandler const &handler)
Default constructor, need an instance of a DataHandler.
hidden::MixtureManagerTraits< GammaMixtureManager >::Type Type
IMixture * createMixtureImpl(String const &modelName, String const &idData, int nbCluster)
create a concrete mixture and initialize it.
GammaBridge< Clust::Gamma_a_bk_, Data > MixtureBridge_a_bk
GammaBridge< Clust::Gamma_ajk_bk_, Data > MixtureBridge_ajk_bk
void getParametersImpl(IMixture *p_mixture, ArrayXX &param) const
get the parameters from an IMixture.
GammaBridge< Clust::Gamma_ak_bk_, Data > MixtureBridge_ak_bk
Clust::Mixture getIdModel(String const &idData) const
Utility function allowing to find the idModel from the idData.
GammaBridge< Clust::Gamma_ajk_bj_, Data > MixtureBridge_ajk_bj
GammaBridge< Clust::Gamma_aj_bjk_, Data > MixtureBridge_aj_bjk
IMixtureManager< GammaMixtureManager > Base
GammaBridge< Clust::Gamma_ak_b_, Data > MixtureBridge_ak_b
GammaBridge< Clust::Gamma_a_bjk_, Data > MixtureBridge_a_bjk
hidden::MixtureManagerTraits< GammaMixtureManager >::MissingValues MissingValues
GammaBridge< Clust::Gamma_ajk_bjk_, Data > MixtureBridge_ajk_bjk
GammaBridge< Clust::Gamma_ak_bj_, Data > MixtureBridge_ak_bj
hidden::MixtureManagerTraits< GammaMixtureManager >::MissingIndexes MissingIndexes
void getMissingValuesImpl(IMixture *p_mixture, MissingValues &missing) const
get the missing values from an IMixture.
GammaBridge< Clust::Gamma_ak_bjk_, Data > MixtureBridge_ak_bjk
hidden::MixtureManagerTraits< GammaMixtureManager >::Data Data
hidden::MixtureManagerTraits< GammaMixtureManager >::DataBridgeType DataBridgeType
IMixture * createMixtureImpl(Clust::Mixture idModel, String const &idData, int nbCluster)
create a concrete mixture and initialize it.
GammaBridge< Clust::Gamma_aj_bk_, Data > MixtureBridge_aj_bk
GammaBridge< Clust::Gamma_ajk_b_, Data > MixtureBridge_ajk_b
void setParametersImpl(IMixture *p_mixture, ArrayXX const &param) const
set the parameters from an IMixture.
Interface base class for mixture managers.
void getMissingValues(IMixture *p_mixture, MissingValues &missing) const
get the missing values
Clust::Mixture getIdModel(String const &idData) const
Utility function allowing to find the idModel from the idData.
hidden::MixtureManagerTraits< GammaMixtureManager< DataHandler > >::DataHandler DataHandler
void registerDataBridge(IDataBridge *p_data)
register a data bridge to the IMixtureManager.
void setParameters(IMixture *p_mixture, ArrayXX const &data) const
set the parameters from an IMixture.
DataHandler const *const p_handler() const
IDataBridge * getDataBridge(String const &idData) const
Utility lookup function allowing to find a DataBridge from its idData.
void getParameters(IMixture *p_mixture, ArrayXX &data) const
get the parameters from an IMixture.
Interface base class for all the mixture models that will be processed by the composer.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
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.
double Real
STK fundamental type of Real values.
The namespace STK is the main domain space of the Statistical ToolKit project.
The DataHandlerTraits will give the type of container furnished by the concrete implementations of th...
DataHandlerTraits< DataHandler, Type >::Data Data
type of the data set
std::vector< std::pair< int, int > > MissingIndexes
Type of the array storing missing values indexes.
std::vector< std::pair< std::pair< int, int >, Type > > MissingValues
Type of the array storing missing values.
Main class for the mixture managers traits policy.