STK++ 0.9.13
STK_PoissonBridge.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_POISSONBRIDGE_H
38#define STK_POISSONBRIDGE_H
39
40#include "STK_Poisson_ljk.h"
41#include "STK_Poisson_ljlk.h"
42#include "STK_Poisson_lk.h"
43#include "../STK_IMixtureBridge.h"
44
45namespace STK
46{
47
48// forward declaration
49template<int Id, class Data> class PoissonBridge;
50
51namespace hidden
52{
57template<class Data_>
58struct MixtureBridgeTraits< PoissonBridge<Clust::Poisson_ljk_, Data_> >
59{
60 typedef Data_ Data;
62 typedef typename Data_::Type Type;
68 typedef std::vector<std::pair<int,int> > MissingIndexes;
70 typedef std::vector< std::pair<std::pair<int,int>, Type > > MissingValues;
71 // class of mixture
72 enum
73 {
74 idMixtureClass_ = Clust::Poisson_
75 };
76};
77
82template<class Data_>
83struct MixtureBridgeTraits< PoissonBridge<Clust::Poisson_lk_, Data_> >
84{
85 typedef Data_ Data;
87 typedef typename Data_::Type Type;
93 typedef std::vector<std::pair<int,int> > MissingIndexes;
95 typedef std::vector< std::pair<std::pair<int,int>, Type > > MissingValues;
96 // class of mixture
97 enum
98 {
99 idMixtureClass_ = Clust::Poisson_
100 };
101};
106template<class Data_>
107struct MixtureBridgeTraits< PoissonBridge< Clust::Poisson_ljlk_, Data_> >
108{
109 typedef Data_ Data;
111 typedef typename Data_::Type Type;
117 typedef std::vector<std::pair<int,int> > MissingIndexes;
119 typedef std::vector< std::pair<std::pair<int,int>, Type > > MissingValues;
120 // class of mixture
121 enum
122 {
123 idMixtureClass_ = Clust::Poisson_
124 };
125};
126
127} // namespace hidden
128
136template<int Id, class Data>
137class PoissonBridge: public IMixtureBridge< PoissonBridge<Id,Data> >
138{
139 public:
140 // Base class
144 typedef typename Data::Type Type;
145 // class of mixture
146 enum
147 {
149 };
150 typedef std::vector<std::pair<int,int> >::const_iterator ConstIterator;
151 using Base::mixture_;
152 using Base::p_dataij_;
153 using Base::v_missing_;
155
164 {
165 removeMissing(); // remove missing from data only once at creation
166 mixture_.setData(*p_dataij_);
167 }
172 {
173#ifdef STK_MIXTURE_DEBUG_CREATE
174 stk_cout << _T("Entering PoissonBridge::~PoissonBridge()\n");
175 stk_cout << _T("this =") << this << _T("\n");
176#endif
177
178 }
179 private:
188 public:
195 virtual PoissonBridge* clone() const { return new PoissonBridge(*this);}
201 virtual PoissonBridge* create() const
202 {
203#ifdef STK_MIXTURE_DEBUG_CREATE
204 stk_cout << _T("Entering PoissonBridge::create()\n");
205 stk_cout << _T("this =") << this << _T("\n");
206#endif
207
208 PoissonBridge* p_bridge = new PoissonBridge( mixture_, this->idData(), this->nbCluster());
209#ifdef STK_MIXTURE_DEBUG_CREATE
210 stk_cout << _T("p_bridge created\n");
211 stk_cout << _T("p_bridge =") << p_bridge << _T("\n");
212#endif
213 p_bridge->p_dataij_ = p_dataij_;
214 p_bridge->mixture_.setData(*p_dataij_);
215 p_bridge->v_missing_ = v_missing_;
216 return p_bridge;
217 }
218
221 Type safeValue( int j) const
222 {
223 int lmin = p_dataij_->col(j).safe().minElt(), lmax = p_dataij_->col(j).safe().maxElt();
224 if (lmax -lmin > 10)
225 { return Real(p_dataij_->col(j).safe().sum())/p_dataij_->sizeRows();}
227 for (int i= p_dataij_->beginRows(); i < p_dataij_->endRows(); ++i)
228 {
230 count[p_dataij_->elt(i,j)]++;
231 }
232 int l; count.maxElt(l);
233 return l;
234 }
235};
236
237} // namespace STK
238
239#endif /* STK_POISSONBRIDGE_H */
In this file we implement the Poisson_ljk class.
In this file we implement the Poisson_ljlk class.
In this file we implement the Poisson_lk class.
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
Interface base class for the bridges of the STK++ mixture.
MissingIndexes v_missing_
vector with the coordinates of the missing values
hidden::MixtureBridgeTraits< PoissonBridge< 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.
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...
template implementation of the IMixtureBridge interface allowing to bridge a STK++ Poisson mixture wi...
IMixtureBridge< PoissonBridge< Id, Data > > Base
hidden::MixtureBridgeTraits< PoissonBridge< Id, Data > >::Parameters Parameters
virtual PoissonBridge * clone() const
This is a standard clone function in usual sense.
std::vector< std::pair< int, int > >::const_iterator ConstIterator
PoissonBridge(Mixture const &mixture, String const &idData, int nbCluster)
private constructor used in order to create a bridge.
virtual ~PoissonBridge()
destructor
PoissonBridge(Data *p_dataij, String const &idData, int nbCluster)
default constructor.
hidden::MixtureBridgeTraits< PoissonBridge< Id, Data > >::Mixture Mixture
virtual PoissonBridge * create() const
This is a standard create function in usual sense.
PoissonBridge(PoissonBridge const &bridge)
copy constructor
Type safeValue(int j) const
std::basic_string< Char > String
STK fundamental type of a String.
double Real
STK fundamental type of Real values.
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< 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.
ModelParameters< Clust::Poisson_ljk_ > Parameters
Type of the structure storing the mixture parameters.
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::Poisson_ljlk_ > 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.
ModelParameters< Clust::Poisson_lk_ > Parameters
Type of the structure storing the mixture parameters.
std::vector< std::pair< int, int > > MissingIndexes
Type of the array storing missing values indexes.
MixtureBridgeTraits struct for bridged mixtures The traits struct MixtureBridgeTraits must be special...