STK++ 0.9.13
STK_CategoricalMixtureManager.h File Reference

In this file we define the CategoricalMixtureManager class. More...

Include dependency graph for STK_CategoricalMixtureManager.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  STK::hidden::MixtureManagerTraits< CategoricalMixtureManager< DataHandler_ > >
 Partial specialization for CategoricalMixtureManager. More...
 
class  STK::CategoricalMixtureManager< DataHandler >
 A mixture manager is a factory class for injection dependency in the STK++ derived class of the IMixtureComposer interface class. More...
 

Namespaces

namespace  STK
 The namespace STK is the main domain space of the Statistical ToolKit project.
 
namespace  STK::hidden
 The hidden namespace enclose the classes and methods which are used internally by the STK++ classes.
 

Macros

#define STK_CREATE_MIXTURE(Data, Bridge)
 

Detailed Description

In this file we define the CategoricalMixtureManager class.

Definition in file STK_CategoricalMixtureManager.h.

Macro Definition Documentation

◆ STK_CREATE_MIXTURE

#define STK_CREATE_MIXTURE (   Data,
  Bridge 
)
Value:
Data* p_data = new Data(idData); \
p_handler()->getData(idData, p_data->dataij()); \
registerDataBridge(p_data); \
return new Bridge( &(p_data->dataij()), idData, nbCluster);

Definition at line 43 of file STK_CategoricalMixtureManager.h.

49{
50// forward declaration
51template<class DataHandler> class CategoricalMixtureManager;
52
53namespace hidden
54{
58template <class DataHandler_>
59struct MixtureManagerTraits<CategoricalMixtureManager<DataHandler_> >
60{
62 typedef DataHandler_ DataHandler;
64 typedef Integer Type;
66 typedef std::vector< std::pair<int,int> > MissingIndexes;
68 typedef std::vector< std::pair<std::pair<int,int>, Type > > MissingValues;
69
70 // All data handlers will store and return a specific container for
71 // the data they handle. The DataHandlerTraits class allow us to know the
72 // type of these containers when data is of type Type.
75 typedef typename DataHandlerTraits<DataHandler, Type>::Data Data;
76 // Classes wrapping the Real and Integer containers
78 typedef DataBridge<Data> DataBridgeType;
79};
80
81}
91template<class DataHandler>
92class CategoricalMixtureManager: public IMixtureManager< CategoricalMixtureManager<DataHandler> >
93{
94 public:
95 typedef typename hidden::MixtureManagerTraits< CategoricalMixtureManager >::Type Type;
96 typedef typename hidden::MixtureManagerTraits< CategoricalMixtureManager >::MissingIndexes MissingIndexes;
97 typedef typename hidden::MixtureManagerTraits< CategoricalMixtureManager >::MissingValues MissingValues;
98 typedef typename hidden::MixtureManagerTraits< CategoricalMixtureManager >::Data Data;
99 typedef typename hidden::MixtureManagerTraits< CategoricalMixtureManager >::DataBridgeType DataBridgeType;
100
101 typedef IMixtureManager<CategoricalMixtureManager> Base;
102 using Base::registerDataBridge;
103 using Base::getDataBridge;
104 using Base::getIdModel;
105 using Base::p_handler;
106
107 // Define Categorical bridges
108 typedef CategoricalBridge<Clust::Categorical_pjk_, Data> MixtureBridge_pjk;
109 typedef CategoricalBridge<Clust::Categorical_pk_, Data> MixtureBridge_pk;
110
112 CategoricalMixtureManager(DataHandler const& handler): Base(&handler) {}
114 ~CategoricalMixtureManager() {}
115
120 void getMissingValuesImpl(IMixture* p_mixture, MissingValues& missing) const
121 {
122 Clust::Mixture idModel = getIdModel(p_mixture->idData());
123 if (idModel == Clust::unknown_mixture_) return;
124 // up-cast... (Yes it's bad....;)...)
125 switch (idModel)
126 {
127 case Clust::Categorical_pjk_:
128 { static_cast<MixtureBridge_pjk*>(p_mixture)->getMissingValues(missing);}
129 break;
130 case Clust::Categorical_pk_:
131 { static_cast<MixtureBridge_pk*>(p_mixture)->getMissingValues(missing);}
132 break;
133 default: // idModel is not implemented
134 break;
135 }
136 }
141 void getParametersImpl(IMixture* p_mixture, ArrayXX& param) const
142 {
143 Clust::Mixture idModel = getIdModel(p_mixture->idData());
144 if (idModel == Clust::unknown_mixture_) return;
145 // up-cast... (Yes it's bad....;)...)
146 switch (idModel)
147 {
148 case Clust::Categorical_pjk_:
149 { static_cast<MixtureBridge_pjk*>(p_mixture)->getParameters(param);}
150 break;
151 case Clust::Categorical_pk_:
152 { static_cast<MixtureBridge_pk*>(p_mixture)->getParameters(param);}
153 break;
154 default: // idModel is not implemented
155 break;
156 }
157 }
162 void setParametersImpl(IMixture* p_mixture, ArrayXX const& param) const
163 {
164 Clust::Mixture idModel = getIdModel(p_mixture->idData());
165 if (idModel == Clust::unknown_mixture_) return;
166 // up-cast... (Yes it's bad....;)...)
167 switch (idModel)
168 {
169 case Clust::Categorical_pjk_:
170 { static_cast<MixtureBridge_pjk*>(p_mixture)->setParameters(param);}
171 break;
172 case Clust::Categorical_pk_:
173 { static_cast<MixtureBridge_pk*>(p_mixture)->setParameters(param);}
174 break;
175 default: // idModel is not implemented
176 break;
177 }
178 }
184 IMixture* createMixtureImpl(String const& modelName, String const& idData, int nbCluster)
185 {
186 Clust::Mixture idModel = Clust::stringToMixture(modelName);
187 return createMixtureImpl(idModel, idData, nbCluster);
188 }
189
190 private:
196 IMixture* createMixtureImpl(Clust::Mixture idModel, String const& idData, int nbCluster)
197 {
198 switch (idModel)
199 {
200 case Clust::Categorical_pjk_:
201 { STK_CREATE_MIXTURE(DataBridgeType, MixtureBridge_pjk)}
202 break;
203 case Clust::Categorical_pk_:
204 { STK_CREATE_MIXTURE(DataBridgeType, MixtureBridge_pk)}
205 break;
206 default:
207 return 0; // 0 if idModel is not implemented
208 break;
209 }
210 return 0; // 0 if idModel is not a STK++ model
211 }
212};
213
214} // namespace STK
215
216#undef STK_CREATE_MIXTURE
217
218#endif /* STK_CATEGORICALMIXTUREMANAGER_H */
#define STK_CREATE_MIXTURE(Data, Bridge)
int Integer
STK fundamental type of integer values.