STK++ 0.9.13
STK_MixtureSemiLearner.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
35#ifndef STK_MIXTURESEMILEARNER_H
36#define STK_MIXTURESEMILEARNER_H
37
38#include "STK_MixtureComposer.h"
39
40namespace STK
41{
42
53{
54 public:
64 virtual ~MixtureSemiLearner();
66 virtual MixtureSemiLearner* create() const;
68 virtual MixtureSemiLearner* clone() const;
70 std::vector<int> const& knownLabels() const { return knownLabels_;}
72 std::vector<int> const& unknownLabels() const { return unknownLabels_;}
76 virtual int cStep();
80 virtual int sStep();
85 virtual Real eStep();
87 virtual void mapStep();
88
93 template<class RowVector>
94 void setLabels( ExprBase<RowVector> const& zi);
95
96 protected:
98 virtual void initializeMixtureParameters();
100 virtual int randomTik();
102 virtual int randomZi();
106 std::vector<int> knownLabels_;
108 std::vector<int> unknownLabels_;
109};
110
111
112template<class RowVector>
114{
115 if (nbSample() != zi.size())
116 { STKRUNTIME_ERROR_NO_ARG(MixtureSemiLearner::setKnownLabels,zi must be of size nbSample);}
117 int nbUnknown = zi.isNA().count();
118#ifdef STK_MIXTURE_DEBUG
119 stk_cout << _T("Entering MixtureSemiLearner::setLabels()\n");
120 stk_cout << _T("nbUnknown=") << nbUnknown << _T("\n");
121#endif
122 // clear previous initialization
123 unknownLabels_.clear();
124 knownLabels_.clear();
125 zi_= baseIdx;
126 // reserve and set lables
127 unknownLabels_.reserve(nbUnknown);
128 knownLabels_.reserve(nbSample() - nbUnknown);
129 for (int i=zi.begin(); i < zi.end(); ++i)
130 {
131 if (isNA(zi[i]))
132 { unknownLabels_.push_back(i);}
133 else
134 {
135 knownLabels_.push_back(i); zi_[i] = zi[i];
136 tik_.row(i) = 0; tik_(i, zi_[i]) = 1.;
137 }
138 }
139#ifdef STK_MIXTURE_DEBUG
140 stk_cout << _T("Terminating MixtureSemiLearner::setLabels()\n");
141 stk_cout << _T("unknownLabels_.size()=") << unknownLabels_.size() << _T("\n");
142 stk_cout << _T("knownLabels_.size()=") << knownLabels_.size() << _T("\n");
143#endif
144}
145
168
169
170} // namespace STK
171
172#endif /* STK_MIXTURESEMILEARNER_H */
173
#define STKRUNTIME_ERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:138
In this file we define the class MixtureComposer.
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
UnaryOperator< IsNaOp< Type >, Derived > isNA() const
hidden::CSlice< Derived, 1, sizeCols_ >::Result row(int i) const
implement the row operator using a reference on the row of the allocator
CArrayXX tik_
The tik probabilities.
CVectorXi const & zi() const
CVectorXi zi_
The zi class label.
Main class for handling composed mixture models.
specialization of the composer for the fixed proportion case.
virtual MixtureSemiLearnerFixedProp * create() const
Create a composer, but reinitialize the mixtures parameters.
virtual void pStep()
overloading of the pStep() method.
virtual MixtureSemiLearnerFixedProp * clone() const
Create a clone of the current model, with mixtures parameters preserved.
Base class for Learning a Mixture mixed model when some classes are known.
virtual void mapStep()
Compute zi using the Map estimate.
virtual void initializeMixtureParameters()
Create the mixture model parameters tik_ and pk_.
virtual int randomZi()
generate random zi_
virtual MixtureSemiLearner * create() const
Create a composer, but reinitialize the mixtures parameters.
virtual int randomTik()
generate random tik_
std::vector< int > unknownLabels_
indexes of the unknown labels
void setLabels(ExprBase< RowVector > const &zi)
Set the known labels.
virtual ~MixtureSemiLearner()
destructor
std::vector< int > const & knownLabels() const
void createSemiLearner(MixtureSemiLearner const *const p_learner)
Copy the ingredient of the semi-learner in the creation process.
virtual int sStep()
Simulate zi accordingly to tik and replace tik by zik by calling cStep().
std::vector< int > const & unknownLabels() const
virtual int cStep()
Replace tik by zik.
virtual Real eStep()
compute the zi, the lnLikelihood of the current estimates and the next value of the tik.
virtual MixtureSemiLearner * clone() const
Create a clone of the current model, with mixtures parameters preserved.
std::vector< int > knownLabels_
indexes of the known labels
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
bool isNA(Type const &x)
utility method allowing to know if a value is a NA (Not Available) value
const int baseIdx
base index of the containers created in STK++.
double Real
STK fundamental type of Real values.
The namespace STK is the main domain space of the Statistical ToolKit project.