STK++ 0.9.13
STK_DiagGaussianMixtureManager.h File Reference

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

Include dependency graph for STK_DiagGaussianMixtureManager.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< DiagGaussianMixtureManager< DataHandler_ > >
 Specialization for Clust::Categorical_ mixtures. More...
 
class  STK::DiagGaussianMixtureManager< DataHandler >
 A mixture manager is a factory class for injection dependency in the STK++ derived class of the IMixtureComposer 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 DiagGaussianMixtureManager class.

Definition in file STK_DiagGaussianMixtureManager.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 44 of file STK_DiagGaussianMixtureManager.h.

50{
51
52// forward declaration
53template<class DataHandler> class DiagGaussianMixtureManager;
54
55namespace hidden
56{
59template <class DataHandler_>
60struct MixtureManagerTraits<DiagGaussianMixtureManager<DataHandler_> >
61{
63 typedef DataHandler_ DataHandler;
65 typedef Real 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.
76 typedef typename DataHandlerTraits<DataHandler, Type>::Data Data;
77 // Classes wrapping the Real and Integer containers
79 typedef DataBridge<Data> DataBridgeType;
80};
81
82} // namespace hidden
83
93template<class DataHandler>
94class DiagGaussianMixtureManager: public IMixtureManager<DiagGaussianMixtureManager<DataHandler> >
95{
96 public:
97 typedef typename hidden::MixtureManagerTraits< DiagGaussianMixtureManager >::Type Type;
98 typedef typename hidden::MixtureManagerTraits< DiagGaussianMixtureManager >::MissingIndexes MissingIndexes;
99 typedef typename hidden::MixtureManagerTraits< DiagGaussianMixtureManager >::MissingValues MissingValues;
100 typedef typename hidden::MixtureManagerTraits< DiagGaussianMixtureManager >::Data Data;
101 typedef typename hidden::MixtureManagerTraits< DiagGaussianMixtureManager >::DataBridgeType DataBridgeType;
102
103 typedef IMixtureManager< DiagGaussianMixtureManager > Base;
104 using Base::registerDataBridge;
105 using Base::getDataBridge;
106 using Base::getIdModel;
107 using Base::p_handler;
108
109 // eiagonal Gaussian bridges
110 typedef DiagGaussianBridge<Clust::Gaussian_sjk_, Data> MixtureBridge_sjk;
111 typedef DiagGaussianBridge<Clust::Gaussian_sk_, Data> MixtureBridge_sk;
112 typedef DiagGaussianBridge<Clust::Gaussian_sj_, Data> MixtureBridge_sj;
113 typedef DiagGaussianBridge<Clust::Gaussian_sjsk_, Data> MixtureBridge_sjsk;
114 typedef DiagGaussianBridge<Clust::Gaussian_s_, Data> MixtureBridge_s;
115
117 DiagGaussianMixtureManager(DataHandler const& handler): Base(&handler) {}
119 ~DiagGaussianMixtureManager() {}
120
125 void getMissingValuesImpl(IMixture* p_mixture, MissingValues& missing) const
126 {
127 Clust::Mixture idModel = getIdModel(p_mixture->idData());
128 if (idModel == Clust::unknown_mixture_) return;
129 // up-cast... (Yes it's bad....;)...)
130 switch (idModel)
131 {
132 case Clust::Gaussian_sjk_:
133 { static_cast<MixtureBridge_sjk*>(p_mixture)->getMissingValues(missing);}
134 break;
135 case Clust::Gaussian_sk_:
136 { static_cast<MixtureBridge_sk*>(p_mixture)->getMissingValues(missing);}
137 break;
138 case Clust::Gaussian_sj_:
139 { static_cast<MixtureBridge_sj*>(p_mixture)->getMissingValues(missing);}
140 break;
141 case Clust::Gaussian_sjsk_:
142 { static_cast<MixtureBridge_sjsk*>(p_mixture)->getMissingValues(missing);}
143 break;
144 case Clust::Gaussian_s_:
145 { static_cast<MixtureBridge_s*>(p_mixture)->getMissingValues(missing);}
146 break;
147 default: // idModel is not implemented
148 break;
149 }
150 }
155 void getParametersImpl(IMixture* p_mixture, ArrayXX& param) const
156 {
157 Clust::Mixture idModel = getIdModel(p_mixture->idData());
158 if (idModel == Clust::unknown_mixture_) return;
159 // up-cast... (Yes it's bad....;)...)
160 switch (idModel)
161 {
162 // Gaussian models
163 case Clust::Gaussian_sjk_:
164 { static_cast<MixtureBridge_sjk*>(p_mixture)->getParameters(param);}
165 break;
166 case Clust::Gaussian_sk_:
167 { static_cast<MixtureBridge_sk*>(p_mixture)->getParameters(param);}
168 break;
169 case Clust::Gaussian_sj_:
170 { static_cast<MixtureBridge_sj*>(p_mixture)->getParameters(param);}
171 break;
172 case Clust::Gaussian_sjsk_:
173 { static_cast<MixtureBridge_sjsk*>(p_mixture)->getParameters(param);}
174 break;
175 case Clust::Gaussian_s_:
176 { static_cast<MixtureBridge_s*>(p_mixture)->getParameters(param);}
177 break;
178 default: // idModel is not implemented
179 break;
180 }
181 }
186 void setParametersImpl(IMixture* p_mixture, ArrayXX const& param) const
187 {
188 Clust::Mixture idModel = getIdModel(p_mixture->idData());
189 if (idModel == Clust::unknown_mixture_) return;
190 // up-cast... (Yes it's bad....;)...)
191 switch (idModel)
192 {
193 // Gaussian models
194 case Clust::Gaussian_sjk_:
195 { static_cast<MixtureBridge_sjk*>(p_mixture)->setParameters(param);}
196 break;
197 case Clust::Gaussian_sk_:
198 { static_cast<MixtureBridge_sk*>(p_mixture)->setParameters(param);}
199 break;
200 case Clust::Gaussian_sj_:
201 { static_cast<MixtureBridge_sj*>(p_mixture)->setParameters(param);}
202 break;
203 case Clust::Gaussian_sjsk_:
204 { static_cast<MixtureBridge_sjsk*>(p_mixture)->setParameters(param);}
205 break;
206 case Clust::Gaussian_s_:
207 { static_cast<MixtureBridge_s*>(p_mixture)->setParameters(param);}
208 break;
209 default: // idModel is not implemented
210 break;
211 }
212 }
218 IMixture* createMixtureImpl(String const& modelName, String const& idData, int nbCluster)
219 { return createMixtureImpl(Clust::stringToMixture(modelName), idData, nbCluster);}
220
221
222 private:
228 IMixture* createMixtureImpl(Clust::Mixture idModel, String const& idData, int nbCluster)
229 {
230 switch (idModel)
231 {
232 // Gaussian models
233 case Clust::Gaussian_sjk_:
234 { STK_CREATE_MIXTURE(DataBridgeType, MixtureBridge_sjk)}
235 break;
236 case Clust::Gaussian_sk_:
237 { STK_CREATE_MIXTURE(DataBridgeType, MixtureBridge_sk)}
238 break;
239 case Clust::Gaussian_sj_:
240 { STK_CREATE_MIXTURE(DataBridgeType, MixtureBridge_sj)}
241 break;
242 case Clust::Gaussian_sjsk_:
243 { STK_CREATE_MIXTURE(DataBridgeType, MixtureBridge_sjsk)}
244 break;
245 case Clust::Gaussian_s_:
246 { STK_CREATE_MIXTURE(DataBridgeType, MixtureBridge_s)}
247 break;
248 default:
249 return 0; // 0 if idModel is not implemented
250 break;
251 }
252 return 0; // 0 if idModel is not a STK++ model
253 }
254};
255
256} // namespace STK
257
258#undef STK_CREATE_MIXTURE
259
260#endif /* STK_DIAGGAUSSIANMIXTUREMANAGER_H */
#define STK_CREATE_MIXTURE(Data, Bridge)
double Real
STK fundamental type of Real values.