STK++ 0.9.13
STK_CategoricalMixtureManager.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_CATEGORICALMIXTUREMANAGER_H
37#define STK_CATEGORICALMIXTUREMANAGER_H
38
39#include "../STK_Clust_Util.h"
40#include "../STK_IMixtureManager.h"
42
43#define STK_CREATE_MIXTURE(Data, Bridge) \
44 Data* p_data = new Data(idData); \
45 p_handler()->getData(idData, p_data->dataij()); \
46 registerDataBridge(p_data); \
47 return new Bridge( &(p_data->dataij()), idData, nbCluster);
48
49namespace STK
50{
51// forward declaration
52template<class DataHandler> class CategoricalMixtureManager;
53
54namespace hidden
55{
59template <class DataHandler_>
61{
63 typedef DataHandler_ DataHandler;
65 typedef Integer Type;
67 typedef std::vector< std::pair<int,int> > MissingIndexes;
69 typedef std::vector< std::pair<std::pair<int,int>, Type > > MissingValues;
70
71 // All data handlers will store and return a specific container for
72 // the data they handle. The DataHandlerTraits class allow us to know the
73 // type of these containers when data is of type Type.
77 // Classes wrapping the Real and Integer containers
80};
81
82}
92template<class DataHandler>
93class CategoricalMixtureManager: public IMixtureManager< CategoricalMixtureManager<DataHandler> >
94{
95 public:
101
105 using Base::getIdModel;
106 using Base::p_handler;
107
108 // Define Categorical bridges
111
113 CategoricalMixtureManager(DataHandler const& handler): Base(&handler) {}
116
122 {
124 if (idModel == Clust::unknown_mixture_) return;
125 // up-cast... (Yes it's bad....;)...)
126 switch (idModel)
127 {
130 break;
133 break;
134 default: // idModel is not implemented
135 break;
136 }
137 }
143 {
145 if (idModel == Clust::unknown_mixture_) return;
146 // up-cast... (Yes it's bad....;)...)
147 switch (idModel)
148 {
150 { static_cast<MixtureBridge_pjk*>(p_mixture)->getParameters(param);}
151 break;
153 { static_cast<MixtureBridge_pk*>(p_mixture)->getParameters(param);}
154 break;
155 default: // idModel is not implemented
156 break;
157 }
158 }
163 void setParametersImpl(IMixture* p_mixture, ArrayXX const& param) const
164 {
166 if (idModel == Clust::unknown_mixture_) return;
167 // up-cast... (Yes it's bad....;)...)
168 switch (idModel)
169 {
171 { static_cast<MixtureBridge_pjk*>(p_mixture)->setParameters(param);}
172 break;
174 { static_cast<MixtureBridge_pk*>(p_mixture)->setParameters(param);}
175 break;
176 default: // idModel is not implemented
177 break;
178 }
179 }
185 IMixture* createMixtureImpl(String const& modelName, String const& idData, int nbCluster)
186 {
188 return createMixtureImpl(idModel, idData, nbCluster);
189 }
190
191 private:
198 {
199 switch (idModel)
200 {
203 break;
206 break;
207 default:
208 return 0; // 0 if idModel is not implemented
209 break;
210 }
211 return 0; // 0 if idModel is not a STK++ model
212 }
213};
214
215} // namespace STK
216
217#undef STK_CREATE_MIXTURE
218
219#endif /* STK_CATEGORICALMIXTUREMANAGER_H */
In this file we define the bridge classes between the categorical mixtures and the composer.
#define STK_CREATE_MIXTURE(Data, Bridge)
A mixture manager is a factory class for injection dependency in the STK++ derived class of the IMixt...
hidden::MixtureManagerTraits< CategoricalMixtureManager >::DataBridgeType DataBridgeType
Clust::Mixture getIdModel(String const &idData) const
Utility function allowing to find the idModel from the idData.
void setParametersImpl(IMixture *p_mixture, ArrayXX const &param) const
set the parameters to an IMixture.
IMixture * createMixtureImpl(Clust::Mixture idModel, String const &idData, int nbCluster)
create a concrete mixture and initialize it.
void getParametersImpl(IMixture *p_mixture, ArrayXX &param) const
get the parameters from an IMixture.
hidden::MixtureManagerTraits< CategoricalMixtureManager >::MissingIndexes MissingIndexes
CategoricalBridge< Clust::Categorical_pjk_, Data > MixtureBridge_pjk
hidden::MixtureManagerTraits< CategoricalMixtureManager >::MissingValues MissingValues
IMixtureManager< CategoricalMixtureManager > Base
hidden::MixtureManagerTraits< CategoricalMixtureManager >::Type Type
hidden::MixtureManagerTraits< CategoricalMixtureManager >::Data Data
CategoricalBridge< Clust::Categorical_pk_, Data > MixtureBridge_pk
CategoricalMixtureManager(DataHandler const &handler)
Default constructor, need an instance of a DataHandler.
IMixture * createMixtureImpl(String const &modelName, String const &idData, int nbCluster)
create a concrete mixture and initialize it.
void getMissingValuesImpl(IMixture *p_mixture, MissingValues &missing) const
get the missing values 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< CategoricalMixtureManager< 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.
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< int, int > > MissingIndexes
Type of the array storing missing values indexes.
DataHandlerTraits< DataHandler, Type >::Data Data
type of the data set
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.