STK++ 0.9.13
STK_PoissonMixtureManager.h File Reference

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

Include dependency graph for STK_PoissonMixtureManager.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< PoissonMixtureManager< DataHandler_ > >
 Partial specialization for PoissonMixtureManager. More...
 
class  STK::PoissonMixtureManager< DataHandler >
 A mixture manager is a factory class for injection dependency in the STK++ derived class of the MixtureComposer 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 PoissonMixtureManager class.

Definition in file STK_PoissonMixtureManager.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 45 of file STK_PoissonMixtureManager.h.

51{
52
53// forward declaration
54template<class DataHandler> class PoissonMixtureManager;
55
56namespace hidden
57{
61template <class DataHandler_>
62struct MixtureManagerTraits <PoissonMixtureManager<DataHandler_> >
63{
65 typedef DataHandler_ DataHandler;
67 typedef Integer Type;
69 typedef std::vector< std::pair<int,int> > MissingIndexes;
71 typedef std::vector< std::pair<std::pair<int,int>, Type > > MissingValues;
72
73 // All data handlers will store and return a specific container for
74 // the data they handle. The DataHandlerTraits class allow us to know the
75 // type of these containers when data is of type Type.
78 typedef typename DataHandlerTraits<DataHandler, Type>::Data Data;
79 // Classes wrapping the Real and Integer containers
81 typedef DataBridge<Data> DataBridgeType;
82};
83
84} // namespace hidden
85
95template<class DataHandler>
96class PoissonMixtureManager: public IMixtureManager< PoissonMixtureManager<DataHandler> >
97{
98 public:
99 typedef typename hidden::MixtureManagerTraits< PoissonMixtureManager >::Type Type;
100 typedef typename hidden::MixtureManagerTraits< PoissonMixtureManager >::MissingIndexes MissingIndexes;
101 typedef typename hidden::MixtureManagerTraits< PoissonMixtureManager >::MissingValues MissingValues;
102 typedef typename hidden::MixtureManagerTraits< PoissonMixtureManager >::Data Data;
103 typedef typename hidden::MixtureManagerTraits< PoissonMixtureManager >::DataBridgeType DataBridgeType;
104
105 typedef IMixtureManager< PoissonMixtureManager > Base;
106 using Base::getDataBridge;
107 using Base::getIdModel;
108 using Base::registerDataBridge;
109 using Base::p_handler;
110
111 // All Poisson bridges
112 typedef PoissonBridge<Clust::Poisson_ljk_, Data> MixtureBridge_ljk;
113 typedef PoissonBridge<Clust::Poisson_lk_, Data> MixtureBridge_lk;
114 typedef PoissonBridge<Clust::Poisson_ljlk_, Data> MixtureBridge_ljlk;
115
117 PoissonMixtureManager(DataHandler const& handler): Base(&handler) {}
119 ~PoissonMixtureManager() {}
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::Poisson_ljk_:
133 { static_cast<MixtureBridge_ljk*>(p_mixture)->getMissingValues(missing);}
134 break;
135 case Clust::Poisson_lk_:
136 { static_cast<MixtureBridge_lk*>(p_mixture)->getMissingValues(missing);}
137 break;
138 case Clust::Poisson_ljlk_:
139 { static_cast<MixtureBridge_ljlk*>(p_mixture)->getMissingValues(missing);}
140 break;
141 default: // idModel is not implemented
142 break;
143 }
144 }
149 void getParametersImpl(IMixture* p_mixture, ArrayXX& param) const
150 {
151 Clust::Mixture idModel = getIdModel(p_mixture->idData());
152 if (idModel == Clust::unknown_mixture_) return;
153 // up-cast... (Yes it's bad....;)...)
154 switch (idModel)
155 {
156 case Clust::Poisson_ljk_:
157 { static_cast<MixtureBridge_ljk*>(p_mixture)->getParameters(param);}
158 break;
159 case Clust::Poisson_lk_:
160 { static_cast<MixtureBridge_lk*>(p_mixture)->getParameters(param);}
161 break;
162 case Clust::Poisson_ljlk_:
163 { static_cast<MixtureBridge_ljlk*>(p_mixture)->getParameters(param);}
164 break;
165 default: // idModel is not implemented
166 break;
167 }
168 }
173 void setParametersImpl(IMixture* p_mixture, ArrayXX const& param) const
174 {
175 Clust::Mixture idModel = getIdModel(p_mixture->idData());
176 if (idModel == Clust::unknown_mixture_) return;
177 // up-cast... (Yes it's bad....;)...)
178 switch (idModel)
179 {
180 case Clust::Poisson_ljk_:
181 { static_cast<MixtureBridge_ljk*>(p_mixture)->setParameters(param);}
182 break;
183 case Clust::Poisson_lk_:
184 { static_cast<MixtureBridge_lk*>(p_mixture)->setParameters(param);}
185 break;
186 case Clust::Poisson_ljlk_:
187 { static_cast<MixtureBridge_ljlk*>(p_mixture)->setParameters(param);}
188 break;
189 default: // idModel is not implemented
190 break;
191 }
192 }
198 IMixture* createMixtureImpl(String const& modelName, String const& idData, int nbCluster)
199 {
200 Clust::Mixture idModel = Clust::stringToMixture(modelName);
201 return createMixtureImpl(idModel, idData, nbCluster);
202 }
203
204 private:
210 IMixture* createMixtureImpl(Clust::Mixture idModel, String const& idData, int nbCluster)
211 {
212 DataBridgeType* p_dataBridge = new DataBridgeType(idData);
213 p_handler()->getData(idData, p_dataBridge->dataij() );
214 registerDataBridge(p_dataBridge);
215 switch (idModel)
216 {
217 case Clust::Poisson_ljk_:
218 {
219 MixtureBridge_ljk* p_mixt = new MixtureBridge_ljk( &(p_dataBridge->dataij()), idData, nbCluster);
220 return p_mixt;
221 }
222 break;
223 case Clust::Poisson_lk_:
224 { return new MixtureBridge_lk( &(p_dataBridge->dataij()), idData, nbCluster);}
225 break;
226 case Clust::Poisson_ljlk_:
227 { return new MixtureBridge_ljlk( &(p_dataBridge->dataij()), idData, nbCluster);}
228 break;
229 default:
230 return 0; // 0 if idModel is not implemented
231 break;
232 }
233 return 0; // 0 if idModel is not a STK++ model
234 }
235};
236
237} // namespace STK
238
239#undef STK_CREATE_MIXTURE
240
241#endif /* STK_POISSONMIXTUREMANAGER_H */
int Integer
STK fundamental type of integer values.