STK++ 0.9.13
STK_Kmm_s.cpp
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, 2014
28 * Author: Serge Iovleff
29 **/
30
37
39
42
43namespace STK
44{
45/* default constructor
46 * @param nbCluster number of cluster in the model
47 **/
48Kmm_s::Kmm_s( int nbCluster): Base(nbCluster) {}
49/* copy constructor
50 * @param model The model to copy
51 **/
53/* destructor */
55/* @return the number of free parameters of the model */
57{ return param_.dim_.sum() + 1;}
58
59/* @return the value of the probability of the i-th sample in the k-th component.
60 * @param i,k indexes of the sample and of the component
61 **/
63{
64 return(- dik_.elt(i,k)/(2.*param_.sigma2_)
65 - (std::log(param_.sigma2_)+2.*Const::_LNSQRT2PI_)*param_.dim_[k]/2.);
66}
67
68/* Initialize randomly the parameters of the Gaussian mixture. */
69void Kmm_s::randomInit( CArrayXX const* const& p_tik, CPointX const* const& p_tk)
70{
71#if STK_Kernel_DEBUG | STK_MIXTURE_VERBOSE
72 stk_cout << _T("Entering Kmm_s::randomInit( CArrayXX const* const& p_tik, CPointX const* const& p_tk)\n");
73#endif
74 // compute the standard deviation
75 compute_dik(p_tik, p_tk);
76 param_.sigma2_ = dik_.prod(*p_tik).sum()/(this->nbSample() * param_.dim_.sum())
77 + std::abs(Law::generator.randGauss(0, 0.05));
78#ifdef STK_MIXTURE_VERBOSE
79 stk_cout << _T("Kmm_s::randomInit( CArrayXX const* const& p_tik, CPointX const* const& p_tk) done\n");
80 stk_cout << param_.sigma2_ << "\n";
81#endif
82}
83
84/* Compute the weighted means and the weighted standard deviations. */
85bool Kmm_s::run( CArrayXX const* const& p_tik, CPointX const* const& p_tk)
86{
87#if STK_Kernel_DEBUG | STK_MIXTURE_VERBOSE
88 stk_cout << _T("Entering Kmm_s::run( CArrayXX const* const& p_tik, CPointX const* const& p_tk)\n");
89#endif
90 compute_dik(p_tik, p_tk);
91 param_.sigma2_ = p_tik->prod(dik_).sum()/p_tk->dot(param_.dim_);
92#ifdef STK_MIXTURE_VERBOSE
93 stk_cout << _T("Kmm_s::run( CArrayXX const* const& p_tik, CPointX const* const& p_tk) done\n");
94 stk_cout << param_.sigma2_ << "\n";
95#endif
96 return (param_.sigma2_ <= 0.) ? false : true;
97}
98
99} // namespace STK
In this file we give the main mathematical constants.
In this file we define the Kmm_s class.
In this file we define the Normal probability law class.
This file contain the functors computings statistics.
#define stk_cout
Standard stk output stream.
#define _T(x)
Let x unmodified.
hidden::OperatorSelector< Derived, Rhs, Arrays::productOp_ >::Result const prod(ExprBase< Rhs > const &other) const
hidden::Promote< Type, typenameRhs::Type >::result_type const dot(ExprBase< Rhs > const &other) const
CArrayXX dik_
Array of the intermediate results dik.
Parameters param_
parameters of the derived mixture model.
void compute_dik(CArrayXX const *p_tik, CPointX const *p_tk)
compute the distance of the ith individual to the kth centroid
The Gaussian mixture model Kmm_s is an isotrope Gaussian mixture model on a kernel space.
Definition STK_Kmm_s.h:74
void randomInit(CArrayXX const *const &p_tik, CPointX const *const &p_tk)
Initialize randomly the variances of the Gaussian kernel mixture.
Definition STK_Kmm_s.cpp:69
~Kmm_s()
destructor
Definition STK_Kmm_s.cpp:54
Real lnComponentProbability(int i, int k) const
Definition STK_Kmm_s.cpp:62
Kmm_s(int nbCluster)
default constructor
Definition STK_Kmm_s.cpp:48
bool run(CArrayXX const *const &p_tik, CPointX const *const &p_tk)
update the variances.
Definition STK_Kmm_s.cpp:85
int computeNbFreeParameters() const
Definition STK_Kmm_s.cpp:56
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
double Real
STK fundamental type of Real values.
The namespace STK is the main domain space of the Statistical ToolKit project.