STK++ 0.9.13
STK_Poisson_lk.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
35#ifndef STK_POISSON_LK_H
36#define STK_POISSON_LK_H
37
38#include "../PoissonModels/STK_PoissonBase.h"
39
40namespace STK
41{
42
43//forward declaration, to allow for recursive template
44template<class Array>class Poisson_lk;
45
46namespace hidden
47{
50template<class Array_>
52{
53 typedef Array_ Array;
54 typedef typename Array::Type Type;
57};
58
59} // namespace hidden
60
68template<class Array>
69class Poisson_lk: public PoissonBase<Poisson_lk<Array> >
70{
71 public:
73 using Base::param_;
74 using Base::p_data;
75
76
88 inline Real lambda(int k, int j) const { return param_.lambda_[k];}
90 void randomInit( CArrayXX const* const& p_tik, CPointX const* const& p_tk) ;
92 bool run( CArrayXX const* const& p_tik, CPointX const* const& p_tk) ;
94 inline int computeNbFreeParameters() const { return this->nbCluster();}
95};
96
97/* Initialize randomly the parameters of the Poisson mixture. */
98template<class Array>
99void Poisson_lk<Array>::randomInit( CArrayXX const* const& p_tik, CPointX const* const& p_tk)
100{
101 Real m = p_data()->template cast<Real>().mean();
102 for (int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
103 { param_.lambda_[k] = Law::Exponential::rand(m);}
104}
105
106
107/* Compute the modalities probabilities */
108template<class Array>
109bool Poisson_lk<Array>::run( CArrayXX const* const& p_tik, CPointX const* const& p_tk)
110{
111 for (int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
112 {
113 param_.lambda_[k]= 0.;
114 for (int j=p_data()->beginCols(); j< p_data()->endCols(); ++j)
115 {
116 for (int i=p_tik->beginRows(); i < p_tik->endRows(); ++i)
117 { param_.lambda_[k] += p_data()->elt(i,j) * p_tik->elt(i,k);}
118 }
119 param_.lambda_[k] /= p_data()->sizeCols()*p_tk->elt(k);
120 }
121 return true;
122}
123
124} // namespace STK
125
126#endif /* STK_Poisson_LK_H */
virtual Real rand() const
Generate a pseudo Exponential random variate.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
Base class for the Poisson models.
Parameters param_
parameters of the derived mixture model.
The Poisson mixture model Poisson_lk has a probability function of the form.
void randomInit(CArrayXX const *const &p_tik, CPointX const *const &p_tk)
Initialize randomly the parameters of the Poisson mixture.
Poisson_lk(Poisson_lk const &model)
copy constructor
PoissonBase< Poisson_lk< Array > > Base
bool run(CArrayXX const *const &p_tik, CPointX const *const &p_tk)
Compute the weighted probabilities.
~Poisson_lk()
destructor
Real lambda(int k, int j) const
Poisson_lk(int nbCluster)
default constructor
int computeNbFreeParameters() const
double Real
STK fundamental type of Real values.
The namespace STK is the main domain space of the Statistical ToolKit project.
ModelParameters< Clust::Poisson_lk_ > Parameters
Type of the structure storing the parameters of a MixturePoisson_lk model.
Main class for the mixtures traits policy.