STK++ 0.9.13
STK_DiagGaussianParameters.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: Oct 24, 2013
28 * Author: Serge Iovleff
29 **/
30
36#ifndef STK_DIAGGAUSSIANPARAMETERS_H
37#define STK_DIAGGAUSSIANPARAMETERS_H
38
39#include "../STK_Clust_Util.h"
40
42#include <Arrays/include/STK_CArray.h> // for Gaussian_sksj model
45
48
49namespace STK
50{
51
55template<>
56struct ModelParameters<Clust::Gaussian_sjk_>
57{
66
70 ModelParameters(int nbCluster);
74 ModelParameters( ModelParameters const& param);
80 ModelParameters& operator=( ModelParameters const& param);
81
83 inline Real const& mean(int k, int j) const { return mean_[k][j];}
85 inline Real const& sigma(int k, int j) const { return sigma_[k][j];}
86
90 void resize(Range const& range);
91
93 void updateStatistics();
95 void setStatistics();
97 void releaseStatistics();
98
104 template<class Array>
106 {
107 for(int k=mean_.begin(), kp= params.beginRows(); k<mean_.end(); ++k, kp+=2)
108 {
109 mean_[k] = params.row(kp);
110 sigma_[k] = params.row(kp+1);
111 }
112 }
113};
114
118template<>
119struct ModelParameters<Clust::Gaussian_sk_>
120{
129
133 ModelParameters(int nbCluster);
137 ModelParameters( ModelParameters const& param);
143 ModelParameters& operator=( ModelParameters const& param);
144
146 inline Real const& mean(int k, int j) const { return mean_[k][j];}
148 inline Real const& sigma(int k, int j) const { return sigma_[k];}
149
153 void resize(Range const& range);
154
156 void updateStatistics();
158 void setStatistics();
160 void releaseStatistics();
161
167 template<class Array>
169 {
170 for(int k=mean_.begin(), kp= params.beginRows(); k<mean_.end(); ++k, kp+=2)
171 {
172 mean_[k] = params.row(kp);
173 sigma_[k] = params.row(kp+1).mean();
174 }
175 }
176};
177
181template<>
182struct ModelParameters<Clust::Gaussian_sj_>
183{
192
196 ModelParameters(int nbCluster);
200 ModelParameters( ModelParameters const& param);
206 ModelParameters& operator=( ModelParameters const& param);
207
209 inline Real const& mean(int k, int j) const { return mean_[k][j];}
211 inline Real const& sigma(int k, int j) const { return sigma_[j];}
212
216 void resize(Range const& range);
217
219 void updateStatistics();
221 void setStatistics();
223 void releaseStatistics();
224
230 template<class Array>
232 {
233 sigma_ =0.;
234 for(int k=mean_.begin(), kp= params.beginRows(); k<mean_.end(); ++k, kp+=2)
235 {
236 mean_[k] = params.row(kp);
237 sigma_ += params.row(kp+1);
238 }
239 sigma_ /= mean_.size();
240 }
241};
242
246template<>
247struct ModelParameters<Clust::Gaussian_s_>
248{
257
261 ModelParameters(int nbCluster);
265 ModelParameters( ModelParameters const& param);
271 ModelParameters& operator=( ModelParameters const& param);
272
274 inline Real const& mean(int k, int j) const { return mean_[k][j];}
276 inline Real const& sigma(int k, int j) const { return sigma_;}
277
281 void resize(Range const& range);
282
284 void updateStatistics();
286 void setStatistics();
288 void releaseStatistics();
289
295 template<class Array>
297 {
298 sigma_ =0.;
299 for(int k=mean_.begin(), kp= params.beginRows(); k<mean_.end(); ++k, kp+=2)
300 {
301 mean_[k] = params.row(kp);
302 sigma_ += params.row(kp+1).mean();
303 }
304 sigma_ /= mean_.size();
305 }
306};
307
311template<>
312struct ModelParameters<Clust::Gaussian_sjsk_>
313{
326
330 ModelParameters(int nbCluster);
337
339 inline Real const& mean(int k, int j) const { return mean_[k][j];}
341 inline Real sigma(int k, int j) const { return sigmak_[k] * sigmaj_[j];}
342
344 void resize(Range const& range);
345
352
356 template<class Array>
358 {
359 CArrayXX sigma(mean_.range(), params.cols());
360 for(int k=mean_.begin(), kp= params.beginRows(); k<mean_.end(); ++k, kp+=2)
361 {
362 mean_[k] = params.row(kp);
363 sigma.row(k) = params.row(kp+1);
364 }
365 sigmak_ = Stat::meanByRow(sigma.asDerived());
366 sigmaj_ = Stat::meanByCol(sigma.asDerived());
367 Real cte = std::sqrt((sigma/(sigmak_ * sigmaj_)).mean());
368 sigmak_ *= cte;
369 sigmaj_ *= cte;
370 }
371};
372
373} // namespace STK
374
375#endif /* STK_DIAGGAUSSIANPARAMETERS_H */
In this file we define and implement the final class Array1D.
In this file we implement the final class CArrayPoint.
In this file we implement the final class CArrayVector.
In this file we implement the final class CArray.
This file contain the functors computings statistics.
This file contain the definition and implementation of the Online classes.
hidden::CSlice< Derived, 1, sizeCols_ >::Result row(int i) const
implement the row operator using a reference on the row of the allocator
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
Index sub-vector region: Specialization when the size is unknown.
Definition STK_Range.h:265
double Real
STK fundamental type of Real values.
hidden::SliceVisitorSelector< Derived, hidden::MeanVisitor, Arrays::by_col_ >::type_result mean(Derived const &A)
If A is a row-vector or a column-vector then the function will return the usual mean value of the vec...
hidden::FunctorTraits< Derived, MeanOp >::Row meanByCol(Derived const &A)
hidden::FunctorTraits< Derived, MeanOp >::Col meanByRow(Derived const &A)
The namespace STK is the main domain space of the Statistical ToolKit project.
Stat::Online< Real, Real > stat_sigma_
Array of the standard deviation statistics.
Real sigma_
standard deviation of the variables
Array1D< Stat::Online< CPointX, Real > > stat_mean_
Array of the mean statistics.
Array1D< CPointX > mean_
array of size nbCluster with the parameters mean of the variables
void setParameters(ExprBase< Array > const &params)
Set the parameters of the mixture model.
Stat::Online< CPointX, Real > stat_sigma_
Array of the standard deviation statistics.
Array1D< Stat::Online< CPointX, Real > > stat_mean_
Array of the mean statistics.
void setParameters(ExprBase< Array > const &params)
Set the parameters of the mixture model.
Array1D< CPointX > mean_
array of size nbCluster with the parameters mean of the variables
CPointX sigma_
standard deviation of the variables
Array1D< Stat::Online< CPointX, Real > > stat_mean_
Array of the mean statistics.
Array1D< CPointX > sigma_
standard deviation of the variables
Array1D< Stat::Online< CPointX, Real > > stat_sigma_
Array of the standard deviation statistics.
Array1D< CPointX > mean_
array of size nbCluster with the parameters mean of the variables
void setParameters(ExprBase< Array > const &params)
Set the parameters of the mixture model.
void setParameters(ExprBase< Array > const &params)
Set the parameters of the mixture model.
ModelParameters(int nbCluster)
default constructor
void setStatistics()
Set the computed statistics.
Array1D< Stat::Online< CPointX, Real > > stat_mean_
Array of the mean statistics.
Stat::Online< Real, Real > stat_sigmak_
Array of the standard deviation k statistics.
Array1D< CPointX > mean_
array of size nbCluster with the parameters mean of the variables
CPointX sigmaj_
standard deviation of the variables by variables
CVectorX sigmak_
standard deviation of the variables
void releaseStatistics()
Release the computed statistics.
void updateStatistics()
update statistics of the parameters.
ModelParameters(ModelParameters const &param)
copy constructor.
void resize(Range const &range)
resize the set of parameter
Stat::Online< CPointX, Real > stat_sigmaj_
Array of the standard deviation j statistics.
Array1D< Real > sigma_
standard deviation of the variables
Array1D< CPointX > mean_
array of size nbCluster with the parameters mean of the variables
Array1D< Stat::Online< Real, Real > > stat_sigma_
Array of the standard deviation statistics.
void setParameters(ExprBase< Array > const &params)
Set the parameters of the mixture model.
Array1D< Stat::Online< CPointX, Real > > stat_mean_
Array of the mean statistics.
struct storing the parameters of the mixture.