STK++ 0.9.13
STK_IMixtureLearner.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_Dot_org (see copyright for ...)
23*/
24
25/*
26 * Project: stkpp::Clustering
27 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
28 **/
29
34#ifndef STK_IMIXTURELEARNER_H
35#define STK_IMIXTURELEARNER_H
36
38#include <STatistiK/include/STK_Stat_Functors.h> // for sumByCol
39
40namespace STK
41{
42
56class IMixtureLearner: public IMixtureStatModel //, public IMixture
57{
58 protected:
67
68 public:
70 virtual ~IMixtureLearner();
71 // getters
73 inline CVectorXi const& ziPred() const { return ziPred_;};
75 inline Clust::modelState state() const { return state_;}
78 // virtual
80 virtual void mapStep();
81 // pure virtual
85 virtual void paramUpdateStep() = 0;
86 // template
92 template<class ColVector>
93 void setClassLabels( ColVector const& zi);
98 template<class ColVector, class RowVector>
99 void setClassLabels( ColVector const& zi, RowVector const& pk);
100
101 private:
106};
107
108/* set the mixture parameters using the given class labels.
109 * Posterior probabilities, numbers in each class are computed using these
110 * class labels.
111 **/
112template<class ColVector>
113void IMixtureLearner::setClassLabels( ColVector const& zi)
114{
115 zi_ = zi;
116 tik_ = 0.;
117 for (int i=tik_.beginRows(); i < tik_.endRows(); i++)
118 { tik_(i, zi_[i]) = 1.;}
119 // count the number of individuals in each class
121 pk_ = tk_/nbSample();
122}
123
124
125/* set the mixture parameters using the class labels and giving the
126 * proportions.
127 **/
128template<class ColVector, class RowVector>
129void IMixtureLearner::setClassLabels( ColVector const& zi, RowVector const& pk)
130{
131 pk_ = pk;
132 zi_ = zi;
133 tik_ = 0.;
134 for (int i=tik_.beginRows(); i < tik_.endRows(); i++)
135 { tik_(i, zi_[i]) = 1.;}
136 // count the number of individuals in each class
138}
139
140} // namespace STK
141
142#endif /* STK_IMIXTURELEARNER_H */
143
In this file we define the abstract base class for mixture statistical models.
This file contain the functors computings statistics.
Base class for Learner of a Mixture mixed model.
CVectorXi ziPred_
The predicted class label.
virtual void paramUpdateStep()=0
Compute the model parameters given the current mixture parameters and imputation/simulation of the mi...
void setState(Clust::modelState state)
set the state of the model : should be used by any strategy
virtual void mapStep()
Compute ziPred using the Map estimate.
void setClassLabels(ColVector const &zi)
set the mixture parameters using the given class labels.
Clust::modelState state() const
Clust::modelState state_
state of the model
CVectorXi const & ziPred() const
virtual ~IMixtureLearner()
destructor
Interface base class for Mixture (composed) model.
CArrayXX tik_
The tik probabilities.
CVectorXi const & zi() const
CPointX const & pk() const
CVectorXi zi_
The zi class label.
CPointX pk_
The proportions of each mixtures.
CPointX tk_
The sum of the columns of tik_.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
modelState
Give the state of the model.
hidden::FunctorTraits< Derived, SumOp >::Row sumByCol(Derived const &A)
The namespace STK is the main domain space of the Statistical ToolKit project.