STK++ 0.9.13
STK_Poisson_ljk.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_LJK_H
36#define STK_POISSON_LJK_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_ljk;
45
46namespace hidden
47{
50template<class Array_>
52{
53 typedef Array_ Array;
54 typedef typename Array::Type Type;
57};
58
59} // namespace hidden
60
69template<class Array>
70class Poisson_ljk: public PoissonBase<Poisson_ljk<Array> >
71{
72 public:
75 using Base::param_;
76 using Base::p_data;
77
89 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
95 { return this->nbCluster()*p_data()->sizeCols();}
96};
97
98/* Initialize randomly the parameters of the Poisson mixture. */
99template<class Array>
100void Poisson_ljk<Array>::randomInit( CArrayXX const* const& p_tik, CPointX const* const& p_tk)
101{
102 for (int j=p_data()->beginCols(); j< p_data()->endCols(); ++j)
103 {
104 Real m = p_data()->col(j).template cast<Real>().mean();
105 for (int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
106 { param_.lambda_[k][j] = Law::Exponential::rand(m);}
107 }
108}
109
110
111/* Compute the lambda_jk */
112template<class Array>
113bool Poisson_ljk<Array>::run( CArrayXX const* const& p_tik, CPointX const* const& p_tk)
114{
115 for (int j=p_data()->beginCols(); j< p_data()->endCols(); ++j)
116 {
117 for (int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
118 {
119 param_.lambda_[k][j] = 0.;
120 for (int i= p_tik->beginRows(); i < p_tik->endRows(); ++i)
121 { param_.lambda_[k][j] += p_data()->elt(i,j) * p_tik->elt(i,k);}
122 param_.lambda_[k][j] /= p_tk->elt(k);
123 }
124 }
125 return true;
126}
127
128} // namespace STK
129
130#endif /* STK_Poisson_LJK_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_ljk is the most general Poisson model and have a probability functi...
void randomInit(CArrayXX const *const &p_tik, CPointX const *const &p_tk)
Initialize randomly the parameters of the Poisson mixture.
PoissonBase< Poisson_ljk< Array > > Base
Poisson_ljk(int nbCluster)
default constructor
Poisson_ljk(Poisson_ljk const &model)
copy constructor
hidden::MixtureTraits< Poisson_ljk< Array > >::Parameters Parameters
int computeNbFreeParameters() const
bool run(CArrayXX const *const &p_tik, CPointX const *const &p_tk)
Compute the MStep for the lambda_jk .
~Poisson_ljk()
destructor
double Real
STK fundamental type of Real values.
The namespace STK is the main domain space of the Statistical ToolKit project.
ModelParameters< Clust::Poisson_ljk_ > Parameters
Type of the structure storing the parameters of a MixturePoisson_ljk model.
Main class for the mixtures traits policy.