STK++ 0.9.13
STK_IMixtureManager.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_IMIXTUREMANAGER_H
37#define STK_IMIXTUREMANAGER_H
38
41
42#include <Arrays/include/STK_Array2D.h> // for get and set parameters
43
44#include "STK_IMixture.h"
45
46namespace STK
47{
68template<class Derived>
69class IMixtureManager: public IRecursiveTemplate<Derived>
70{
71 public:
78
83
85 DataHandler const* const p_handler() const { return p_handler_;}
86
91 Clust::Mixture getIdModel( String const& idData) const;
96 String getIdModelName( String const& idData) const;
97
107 IMixture* createMixture(String const& idData, int nbCluster);
118 void releaseDataBridge(String const& idData);
119
124 Data const& getData( String const& idData) const;
125
126 // pure virtual methods
132 {this->asDerived().getMissingValuesImpl(p_mixture, missing);}
137 inline void getParameters(IMixture* p_mixture, ArrayXX& data) const
138 { this->asDerived().getParametersImpl(p_mixture, data);}
143 inline void setParameters(IMixture* p_mixture, ArrayXX const& data) const
144 { this->asDerived().setParametersImpl(p_mixture, data);}
145
146 protected:
151 IDataBridge* getDataBridge( String const& idData) const;
152
153 private:
157 std::vector<IDataBridge*> v_data_;
158
163 inline IMixture* createMixture(String const& modelName, String const& idData, int nbCluster)
164 { return this->asDerived().createMixtureImpl(modelName, idData, nbCluster);}
165};
166
167/* Utility function allowing to find the idModel from the idData
168 * @param idData the id name of the data we want the idModel
169 * @return the idModel
170 **/
171template<class Derived>
173{
175 if (!p_handler()->getIdModelName( idData, modelName))
176 {
177#ifdef STK_MIXTURE_VERY_VERBOSE
178 stk_cout << _T("In IMixtureManager::getIdModel, fail to get idData = ") << idData << _T("\n");
179#endif
181 }
182#ifdef STK_MIXTURE_VERY_VERBOSE
183 stk_cout << _T("In IMixtureManager::getIdModel, success to get idData = ") << idData << _T("\n");
184 stk_cout << _T("In IMixtureManager::getIdModel, modelName = ") << modelName << _T("\n");
185#endif
187}
188
189/* Default constructor, need an instance of a DataHandler. */
190template<class Derived>
192 : p_handler_(p_handler)
193{}
194/* destructor */
195template<class Derived>
197{
198 typedef std::vector<IDataBridge*>::iterator DataIterator;
199 for (DataIterator it = v_data_.begin() ; it != v_data_.end(); ++it)
200 { delete (*it);}
201}
202/* Utility function allowing to find the idModel name from the idData
203 * @param idData the id name of the data we want the idModel
204 * @return the idModel name
205 **/
206template<class Derived>
208{
210 if (!p_handler_->getIdModelName( idData, modelName))
211 {
212#ifdef STK_MIXTURE_VERY_VERBOSE
213 stk_cout << _T("In IMixtureManager::getIdModelName, fail to get idData = ") << idData << _T("\n");
214#endif
215 }
216#ifdef STK_MIXTURE_VERY_VERBOSE
217 stk_cout << _T("In IMixtureManager::getIdModeName, success to get idData = ") << idData << _T("\n");
218 stk_cout << _T("In IMixtureManager::getIdModel, modelName = ") << modelName << _T("\n");
219#endif
220 return modelName;
221}
222
223/* create a mixture and initialize it.
224 * @param idData name of the model
225 * @param nbCluster number of cluster of the model
226 * @return 0 if the idData is not find, the result of @c createMixture( idModel, idData, nbCluster)
227 * otherwise.
228 **/
229template<class Derived>
231{
233 if (!p_handler_->getIdModelName( idData, modelName)) { return 0;};
234 return createMixture( modelName, idData, nbCluster);
235}
236/* @brief register a data manager to the IMixtureManager.
237 * For each mixture created and registered, a data manager is created
238 * and registered so that it will be deleted when the mixture itself is
239 * deleted.
240 * @param p_data a pointer on the data manager
241 **/
242template<class Derived>
244{ v_data_.push_back(p_data);}
245/* release a data set from v_data_.
246 * @param idData name of the data set to release
247 **/
248template<class Derived>
250{
251 typedef std::vector<IDataBridge*>::iterator DataIterator;
252 for (DataIterator it = v_data_.begin(); it != v_data_.end(); ++it)
253 { if ((*it)->idData() == idData) {delete (*it); v_data_.erase(it); break;}}
254}
255
256/* Utility lookup function allowing to find a DataBridge from its idData
257 * @param idData the id name of the mixture we want to get
258 * @return a pointer on the DataBridge
259 **/
260template<class Derived>
262{
263 typedef std::vector<IDataBridge*>::const_iterator ConstDataIterator;
264 for (ConstDataIterator it = v_data_.begin(); it != v_data_.end(); ++it)
265 { if ((*it)->idData() == idData) return (*it);}
266 return 0;
267}
268
269/* get the wrapper for any kind of data set using its Id
270 * @param idData Id name of the data set attached to the mixture
271 * @return a constant reference on the array with the data set
272 **/
273template<class Derived>
275{
276 IDataBridge* p_bridge = getDataBridge(idData);
277 if (p_bridge)
278 return static_cast<DataBridgeType*>(p_bridge)->dataij();
279 else
281}
282
283} // namespace STK
284
285
286#endif /* STK_IMIXTUREMANAGER_H */
In this file, we define the final class Array2D.
In this file we define the data wrapper class.
define the main interface for linking specific mixture model to the composer.
#define STKRUNTIME_ERROR_1ARG(Where, Arg, Error)
Definition STK_Macros.h:129
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
Interface class wrapping a data set.
Interface base class for mixture managers.
hidden::MixtureManagerTraits< Derived >::MissingIndexes MissingIndexes
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< Derived >::Type Type
hidden::MixtureManagerTraits< Derived >::DataHandler DataHandler
void registerDataBridge(IDataBridge *p_data)
register a data bridge to the IMixtureManager.
Data const & getData(String const &idData) const
get the wrapper for any kind of data set using its Id
IMixtureManager(DataHandler const *const p_handler)
Default constructor, need an instance of a DataHandler.
void setParameters(IMixture *p_mixture, ArrayXX const &data) const
set the parameters from an IMixture.
String getIdModelName(String const &idData) const
Utility function allowing to find the idModel name from the idData.
DataHandler const *const p_handler() const
IMixture * createMixture(String const &idData, int nbCluster)
create a mixture and initialize it.
void releaseDataBridge(String const &idData)
release a data bridge from v_data_.
IMixture * createMixture(String const &modelName, String const &idData, int nbCluster)
create a concrete mixture and initialize it.
hidden::MixtureManagerTraits< Derived >::MissingValues MissingValues
hidden::MixtureManagerTraits< Derived >::DataBridgeType DataBridgeType
hidden::MixtureManagerTraits< Derived >::Data Data
IDataBridge * getDataBridge(String const &idData) const
Utility lookup function allowing to find a DataBridge from its idData.
DataHandler const *const p_handler_
A pointer on the concrete instance of the data handler.
std::vector< IDataBridge * > v_data_
vector of pointers to the data components
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.
Interface base class for all classes implementing the curious recursive template paradigm.
Derived & asDerived()
static cast : return a reference of this with a cast to the derived class.
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.
Main class for the mixture managers traits policy.