STK++ 0.9.13
STK_DiagGaussianMixtureManager.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_DIAGGAUSSIANMIXTUREMANAGER_H
37#define STK_DIAGGAUSSIANMIXTUREMANAGER_H
38
39#include "../STK_Clust_Util.h"
40#include "../STK_IMixtureManager.h"
41
43
44#define STK_CREATE_MIXTURE(Data, Bridge) \
45 Data* p_data = new Data(idData); \
46 p_handler()->getData(idData, p_data->dataij() ); \
47 registerDataBridge(p_data); \
48 return new Bridge( &(p_data->dataij()), idData, nbCluster);
49
50namespace STK
51{
52
53// forward declaration
54template<class DataHandler> class DiagGaussianMixtureManager;
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} // namespace hidden
84
94template<class DataHandler>
95class DiagGaussianMixtureManager: public IMixtureManager<DiagGaussianMixtureManager<DataHandler> >
96{
97 public:
103
107 using Base::getIdModel;
108 using Base::p_handler;
109
110 // eiagonal Gaussian bridges
116
118 DiagGaussianMixtureManager(DataHandler const& handler): Base(&handler) {}
121
127 {
129 if (idModel == Clust::unknown_mixture_) return;
130 // up-cast... (Yes it's bad....;)...)
131 switch (idModel)
132 {
135 break;
138 break;
141 break;
144 break;
147 break;
148 default: // idModel is not implemented
149 break;
150 }
151 }
157 {
159 if (idModel == Clust::unknown_mixture_) return;
160 // up-cast... (Yes it's bad....;)...)
161 switch (idModel)
162 {
163 // Gaussian models
165 { static_cast<MixtureBridge_sjk*>(p_mixture)->getParameters(param);}
166 break;
168 { static_cast<MixtureBridge_sk*>(p_mixture)->getParameters(param);}
169 break;
171 { static_cast<MixtureBridge_sj*>(p_mixture)->getParameters(param);}
172 break;
174 { static_cast<MixtureBridge_sjsk*>(p_mixture)->getParameters(param);}
175 break;
177 { static_cast<MixtureBridge_s*>(p_mixture)->getParameters(param);}
178 break;
179 default: // idModel is not implemented
180 break;
181 }
182 }
187 void setParametersImpl(IMixture* p_mixture, ArrayXX const& param) const
188 {
190 if (idModel == Clust::unknown_mixture_) return;
191 // up-cast... (Yes it's bad....;)...)
192 switch (idModel)
193 {
194 // Gaussian models
196 { static_cast<MixtureBridge_sjk*>(p_mixture)->setParameters(param);}
197 break;
199 { static_cast<MixtureBridge_sk*>(p_mixture)->setParameters(param);}
200 break;
202 { static_cast<MixtureBridge_sj*>(p_mixture)->setParameters(param);}
203 break;
205 { static_cast<MixtureBridge_sjsk*>(p_mixture)->setParameters(param);}
206 break;
208 { static_cast<MixtureBridge_s*>(p_mixture)->setParameters(param);}
209 break;
210 default: // idModel is not implemented
211 break;
212 }
213 }
219 IMixture* createMixtureImpl(String const& modelName, String const& idData, int nbCluster)
220 { return createMixtureImpl(Clust::stringToMixture(modelName), idData, nbCluster);}
221
222
223 private:
230 {
231 switch (idModel)
232 {
233 // Gaussian models
236 break;
239 break;
242 break;
245 break;
248 break;
249 default:
250 return 0; // 0 if idModel is not implemented
251 break;
252 }
253 return 0; // 0 if idModel is not a STK++ model
254 }
255};
256
257} // namespace STK
258
259#undef STK_CREATE_MIXTURE
260
261#endif /* STK_DIAGGAUSSIANMIXTUREMANAGER_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 IMixt...
void setParametersImpl(IMixture *p_mixture, ArrayXX const &param) const
set the parameters from an IMixture.
Clust::Mixture getIdModel(String const &idData) const
Utility function allowing to find the idModel from the idData.
DiagGaussianBridge< Clust::Gaussian_sj_, Data > MixtureBridge_sj
void getMissingValuesImpl(IMixture *p_mixture, MissingValues &missing) const
get the missing values from an IMixture.
hidden::MixtureManagerTraits< DiagGaussianMixtureManager >::Data Data
hidden::MixtureManagerTraits< DiagGaussianMixtureManager >::MissingValues MissingValues
DiagGaussianMixtureManager(DataHandler const &handler)
Default constructor, need an instance of a DataHandler.
DiagGaussianBridge< Clust::Gaussian_sk_, Data > MixtureBridge_sk
IMixtureManager< DiagGaussianMixtureManager > Base
DiagGaussianBridge< Clust::Gaussian_s_, Data > MixtureBridge_s
hidden::MixtureManagerTraits< DiagGaussianMixtureManager >::DataBridgeType DataBridgeType
IMixture * createMixtureImpl(Clust::Mixture idModel, String const &idData, int nbCluster)
create a concrete mixture and initialize it.
IMixture * createMixtureImpl(String const &modelName, String const &idData, int nbCluster)
create a concrete mixture and initialize it.
hidden::MixtureManagerTraits< DiagGaussianMixtureManager >::MissingIndexes MissingIndexes
DiagGaussianBridge< Clust::Gaussian_sjsk_, Data > MixtureBridge_sjsk
hidden::MixtureManagerTraits< DiagGaussianMixtureManager >::Type Type
DiagGaussianBridge< Clust::Gaussian_sjk_, Data > MixtureBridge_sjk
void getParametersImpl(IMixture *p_mixture, ArrayXX &param) const
get 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< DiagGaussianMixtureManager< 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.