STK++ 0.9.13
STK_IMixtureModel.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: 16 oct. 2012
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_IMIXTUREMODEL_H
38#define STK_IMIXTUREMODEL_H
39
43
44#ifdef STK_MIXTURE_DEBUG
46#endif
47
48namespace STK
49{
50namespace Clust
51{
56template <class Mixture> struct MixtureTraits;
57
58} // namespace Clust
59
63template <int Id> struct ModelParameters;
64
92template<class Derived>
94{
95 public:
98 typedef typename Array::Type Type;
99
100 protected:
107 , p_dataij_(0)
108 {}
120
121 public:
123 inline ~IMixtureModel() {}
125 inline IMixtureModel* create() const { return new Derived(this->nbCluster());}
127 inline Array const* p_data() const { return p_dataij_;}
128
133 inline void setData(Array const& data)
134 {
135 p_dataij_ = &data;
137 }
142 inline bool initializeStep() { return this->asDerived().initializeStepImpl();}
144 inline void setParametersStep()
145 {
146 param_.setParametersStep();
147 this->asDerived().setParametersImpl();
148 }
151 inline void finalizeStep() { this->asDerived().finalizeStepImpl();}
152
153 // default implementation of the pseudo-virtual methods
155 inline void initializeModelImpl() {}
157 inline bool initializeStepImpl() { return true;}
159 inline void finalizeStepImpl() {}
160
165 template<class Weights>
166 Type sample(int i, int j, Weights const& tk) const
167 { return this->asDerived().rand(i, j, Law::Categorical::rand(tk));}
168
169 protected:
181 {
182 // set dimensions
183 this->setNbSample(p_dataij_->sizeRows());
184 this->setNbVariable(p_dataij_->sizeCols());
185 // call specific model initialization stuff
186 this->asDerived().initializeModelImpl();
187 }
189 Parameters param_;
190
191 private:
194};
195
196} // namespace STK
197
198#endif /* STK_IMIXTUREMODEL_H */
This file define methods for displaying Arrays and Expressions.
In this file we define the interface base class for mixture models.
In this file we define the Categorical distribution.
In this file we define the constant and utilities methods used in the project Model.
Base class for all Mixture model.
void setNbSample(int nbSample)
Set the number of sample of the model.
Main interface class for mixture models.
IMixtureModel(IMixtureModel const &model)
copy constructor.
void setParametersStep()
set the parameters stored in stat_proba_ and release stat_proba_.
Type sample(int i, int j, Weights const &tk) const
void finalizeStep()
This function will be called once the model is estimated.
Clust::MixtureTraits< Derived >::Array Array
IMixtureModel * create() const
create pattern.
bool initializeStep()
This function will be called once the model is created and data is set.
void setData(Array const &data)
Set the data set.
Clust::MixtureTraits< Derived >::Parameters Parameters
void initializeModelImpl()
default implementation of initializeModelImpl (do nothing)
IMixtureModel(int nbCluster)
Default constructor.
Array const * p_data() const
Parameters param_
parameters of the derived mixture model
void finalizeStepImpl()
default implementation of finalizeStepImpl (do nothing)
bool initializeStepImpl()
default implementation of initializeStepImpl (return true)
Array const * p_dataij_
pointer on the data set
void initializeModel()
Initialize the model before its first use.
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.
virtual int rand() const
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
The namespace STK is the main domain space of the Statistical ToolKit project.
Main class for the mixtures traits policy.
struct storing the parameters of the mixture.