STK++ 0.9.13
STK_PoissonMixtureManager.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_POISSONMIXTUREMANAGER_H
37#define STK_POISSONMIXTUREMANAGER_H
38
39#include "../STK_Clust_Util.h"
40#include "../STK_IMixtureManager.h"
41
42#include "STK_PoissonBridge.h"
43
44
45#define STK_CREATE_MIXTURE(Data, Bridge) \
46 Data* p_data = new Data(idData); \
47 p_handler()->getData(idData, p_data->dataij() ); \
48 registerDataBridge(p_data); \
49 return new Bridge( &(p_data->dataij()), idData, nbCluster);
50
51namespace STK
52{
53
54// forward declaration
55template<class DataHandler> class PoissonMixtureManager;
56
57namespace hidden
58{
62template <class DataHandler_>
64{
66 typedef DataHandler_ DataHandler;
68 typedef Integer Type;
70 typedef std::vector< std::pair<int,int> > MissingIndexes;
72 typedef std::vector< std::pair<std::pair<int,int>, Type > > MissingValues;
73
74 // All data handlers will store and return a specific container for
75 // the data they handle. The DataHandlerTraits class allow us to know the
76 // type of these containers when data is of type Type.
80 // Classes wrapping the Real and Integer containers
83};
84
85} // namespace hidden
86
96template<class DataHandler>
97class PoissonMixtureManager: public IMixtureManager< PoissonMixtureManager<DataHandler> >
98{
99 public:
105
108 using Base::getIdModel;
110 using Base::p_handler;
111
112 // All Poisson bridges
116
118 PoissonMixtureManager(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;
142 default: // idModel is not implemented
143 break;
144 }
145 }
151 {
153 if (idModel == Clust::unknown_mixture_) return;
154 // up-cast... (Yes it's bad....;)...)
155 switch (idModel)
156 {
158 { static_cast<MixtureBridge_ljk*>(p_mixture)->getParameters(param);}
159 break;
161 { static_cast<MixtureBridge_lk*>(p_mixture)->getParameters(param);}
162 break;
164 { static_cast<MixtureBridge_ljlk*>(p_mixture)->getParameters(param);}
165 break;
166 default: // idModel is not implemented
167 break;
168 }
169 }
174 void setParametersImpl(IMixture* p_mixture, ArrayXX const& param) const
175 {
177 if (idModel == Clust::unknown_mixture_) return;
178 // up-cast... (Yes it's bad....;)...)
179 switch (idModel)
180 {
182 { static_cast<MixtureBridge_ljk*>(p_mixture)->setParameters(param);}
183 break;
185 { static_cast<MixtureBridge_lk*>(p_mixture)->setParameters(param);}
186 break;
188 { static_cast<MixtureBridge_ljlk*>(p_mixture)->setParameters(param);}
189 break;
190 default: // idModel is not implemented
191 break;
192 }
193 }
199 IMixture* createMixtureImpl(String const& modelName, String const& idData, int nbCluster)
200 {
202 return createMixtureImpl(idModel, idData, nbCluster);
203 }
204
205 private:
212 {
214 p_handler()->getData(idData, p_dataBridge->dataij() );
216 switch (idModel)
217 {
219 {
220 MixtureBridge_ljk* p_mixt = new MixtureBridge_ljk( &(p_dataBridge->dataij()), idData, nbCluster);
221 return p_mixt;
222 }
223 break;
225 { return new MixtureBridge_lk( &(p_dataBridge->dataij()), idData, nbCluster);}
226 break;
228 { return new MixtureBridge_ljlk( &(p_dataBridge->dataij()), idData, nbCluster);}
229 break;
230 default:
231 return 0; // 0 if idModel is not implemented
232 break;
233 }
234 return 0; // 0 if idModel is not a STK++ model
235 }
236};
237
238} // namespace STK
239
240#undef STK_CREATE_MIXTURE
241
242#endif /* STK_POISSONMIXTUREMANAGER_H */
In this file we define the bridge class between the Poisson mixture models and the composer.
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< PoissonMixtureManager< 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...
A mixture manager is a factory class for injection dependency in the STK++ derived class of the Mixtu...
hidden::MixtureManagerTraits< PoissonMixtureManager >::MissingValues MissingValues
Clust::Mixture getIdModel(String const &idData) const
Utility function allowing to find the idModel from the idData.
PoissonBridge< Clust::Poisson_ljlk_, Data > MixtureBridge_ljlk
void getMissingValuesImpl(IMixture *p_mixture, MissingValues &missing) const
get the missing values from an IMixture.
void registerDataBridge(IDataBridge *p_data)
register a data bridge to the IMixtureManager.
hidden::MixtureManagerTraits< PoissonMixtureManager >::Data Data
PoissonMixtureManager(DataHandler const &handler)
Default constructor, need an instance of a DataHandler.
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.
DataHandler const *const p_handler() const
PoissonBridge< Clust::Poisson_ljk_, Data > MixtureBridge_ljk
hidden::MixtureManagerTraits< PoissonMixtureManager >::Type Type
PoissonBridge< Clust::Poisson_lk_, Data > MixtureBridge_lk
hidden::MixtureManagerTraits< PoissonMixtureManager >::DataBridgeType DataBridgeType
void setParametersImpl(IMixture *p_mixture, ArrayXX const &param) const
set the parameters to an IMixture.
IMixtureManager< PoissonMixtureManager > Base
hidden::MixtureManagerTraits< PoissonMixtureManager >::MissingIndexes MissingIndexes
void getParametersImpl(IMixture *p_mixture, ArrayXX &param) const
get the parameters from an IMixture.
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.
The DataHandlerTraits will give the type of container furnished by the concrete implementations of th...
std::vector< std::pair< std::pair< int, int >, Type > > MissingValues
Type of the array storing missing values.
std::vector< std::pair< int, int > > MissingIndexes
Type of the array storing missing values indexes.
DataHandlerTraits< DataHandler, Type >::Data Data
type of the data set
Main class for the mixture managers traits policy.