STK++ 0.9.13
STK_CategoricalBridge.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------*/
2/* Copyright (C) 2004-2016 Serge Iovleff
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.org (see copyright for ...)
23*/
24
25/*
26 * Project: stkpp::Clustering
27 * created on: 15 nov. 2013
28 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 * Originally created by Parmeet Bhatia <b..._DOT_p..._AT_gmail_Dot_com>
30 **/
31
37#ifndef STK_CATEGORICALBRIDGE_H
38#define STK_CATEGORICALBRIDGE_H
39
40#include "STK_Categorical_pjk.h"
41#include "STK_Categorical_pk.h"
42#include "../STK_IMixtureBridge.h"
43
44namespace STK
45{
46
47// forward declaration
48template<int Id, class Data> class CategoricalBridge;
49
50namespace hidden
51{
55template<class Data_>
56struct MixtureBridgeTraits< CategoricalBridge<Clust::Categorical_pjk_, Data_> >
57{
59 typedef Data_ Data;
61 typedef typename Data_::Type Type;
67 typedef std::vector<std::pair<int,int> > MissingIndexes;
69 typedef std::vector< std::pair<std::pair<int,int>, Type > > MissingValues;
70 enum
71 {
72 idMixtureClass_ = Clust::Categorical_
73 };
74};
78template<class Data_>
79struct MixtureBridgeTraits< CategoricalBridge< Clust::Categorical_pk_, Data_> >
80{
82 typedef Data_ Data;
84 typedef typename Data_::Type Type;
90 typedef std::vector<std::pair<int,int> > MissingIndexes;
92 typedef std::vector< std::pair<std::pair<int,int>, Type > > MissingValues;
93 enum
94 {
95 idMixtureClass_ = Clust::Categorical_
96 };
97};
98
99} // namespace hidden
100
110template<int Id, class Data>
111class CategoricalBridge: public IMixtureBridge< CategoricalBridge<Id,Data> >
112{
113 public:
114 // Base class
116 // type of Mixture
120 // type of data
121 typedef typename Data::Type Type;
122 // class of mixture
123 enum
124 {
126 };
127
128 typedef typename MissingIndexes::const_iterator ConstIterator;
129 using Base::mixture_;
130 using Base::p_dataij_;
131 using Base::p_tik;
132 using Base::v_missing_;
134
153 virtual CategoricalBridge* clone() const { return new CategoricalBridge(*this);}
159 virtual CategoricalBridge* create() const
160 {
162 p_bridge->p_dataij_ = p_dataij_;
163 p_bridge->mixture_.setData(*p_dataij_);
164 p_bridge->v_missing_ = v_missing_;
165 return p_bridge;
166 }
172 Type safeValue( int j) const;
173
174 private:
183};
184
185/* default constructor.
186 * - Remove the missing values from the data set,
187 * - initialize the mixture by setting the data set
188 * @param p_dataij pointer on the Data set that will be used by the bridge.
189 * @param idData id name of the mixture model
190 * @param nbCluster number of cluster
191 **/
192template<int Id, class Data>
193CategoricalBridge<Id,Data>::CategoricalBridge( Data* p_dataij, String const& idData, int nbCluster)
194 : Base( p_dataij, idData, nbCluster)
195{
197 mixture_.setData(*p_dataij_);
198}
199/* copy constructor */
200template<int Id, class Data>
202{/*mixture_.setData(*p_dataij_);*/}
203
204/* Compute a safe value for the jth variable by counting the most present
205 * modality.
206 * @return a safe value for the jth variable
207 * @param j index of the column with the safe value needed
208 **/
209template<int Id, class Data>
210typename Data::Type CategoricalBridge<Id,Data>::safeValue( int j) const
211{
212 int lmin = p_dataij_->col(j).safe().minElt(), lmax = p_dataij_->col(j).safe().maxElt();
214 for (int i= p_dataij_->beginRows(); i < p_dataij_->endRows(); ++i)
215 {
216 if (!Arithmetic<int>::isNA(p_dataij_->elt(i,j)))
217 count[p_dataij_->elt(i,j)]++;
218 }
219 int l; count.maxElt(l);
220 return l;
221}
222
223} // namespace STK
224
225#endif /* STK_CATEGORICALBRIDGE_H */
In this file we implement the Categorical_pjk mixture model.
In this file we define the Categorical_pk model.
template implementation of the IMixtureBridge interface allowing to bridge a STK++ mixture with the c...
virtual CategoricalBridge * create() const
This is a standard create function in usual sense.
hidden::MixtureBridgeTraits< CategoricalBridge< Id, Data > >::MissingIndexes MissingIndexes
hidden::MixtureBridgeTraits< CategoricalBridge< Id, Data > >::Parameters Parameters
MissingIndexes::const_iterator ConstIterator
IMixtureBridge< CategoricalBridge< Id, Data > > Base
CategoricalBridge(Data *p_dataij, String const &idData, int nbCluster)
default constructor.
virtual ~CategoricalBridge()
destructor
CategoricalBridge(Mixture const &mixture, String const &idData, int nbCluster)
protected constructor to use in order to create a bridge.
hidden::MixtureBridgeTraits< CategoricalBridge< Id, Data > >::Mixture Mixture
virtual CategoricalBridge * clone() const
This is a standard clone function in usual sense.
Type safeValue(int j) const
Compute a safe value for the jth variable by counting the most present modality.
Interface base class for the bridges of the STK++ mixture.
MissingIndexes v_missing_
vector with the coordinates of the missing values
hidden::MixtureBridgeTraits< CategoricalBridge< Id, Data > >::Data Data
virtual void removeMissing()
This function will be used once for imputation of missing data at the initialization step (.
Mixture mixture_
The Mixture to bridge with the composer.
CArrayXX const * p_tik() const
This function can be used in derived classes to get posterior probabilities from the framework.
String const & idData() const
int nbCluster() const
This function can be used in derived classes to get number of classes.
virtual void setData(YArray_ const &y, XArray_ const &x)
set the data set.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
std::basic_string< Char > String
STK fundamental type of a String.
hidden::SliceVisitorSelector< Derived, hidden::CountVisitor, Arrays::by_col_ >::type_result count(Derived const &A)
If A is a row-vector or a column-vector then the function will return the usual count value of the ve...
The namespace STK is the main domain space of the Statistical ToolKit project.
TRange< UnknownSize > Range
Definition STK_Range.h:59
Arithmetic properties of STK fundamental types.
std::vector< std::pair< int, int > > MissingIndexes
Type of the array storing missing values indexes.
ModelParameters< Clust::Categorical_pjk_ > Parameters
Type of the structure storing the mixture parameters.
std::vector< std::pair< std::pair< int, int >, Type > > MissingValues
Type of the array storing missing values.
std::vector< std::pair< int, int > > MissingIndexes
Type of the array storing missing values indexes.
std::vector< std::pair< std::pair< int, int >, Type > > MissingValues
Type of the array storing missing values.
ModelParameters< Clust::Categorical_pk_ > Parameters
Type of the structure storing the mixture parameters.
MixtureBridgeTraits struct for bridged mixtures The traits struct MixtureBridgeTraits must be special...