STK++ 0.9.13
STK_Poisson_ljlk.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_LJLK_H
36#define STK_POISSON_LJLK_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_ljlk;
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_ljlk: public PoissonBase<Poisson_ljlk<Array> >
71{
72 public:
74 using Base::param_;
75 using Base::p_data;
76
88 void randomInit( CArrayXX const* const& p_tik, CPointX const* const& p_tk) ;
90 bool run( CArrayXX const* const& p_tik, CPointX const* const& p_tk) ;
92 inline int computeNbFreeParameters() const
93 { return this->nbCluster()+p_data()->sizeCols();}
94};
95
96/* Initialize randomly the parameters of the Poisson mixture. */
97template<class Array>
98void Poisson_ljlk<Array>::randomInit( CArrayXX const* const& p_tik, CPointX const* const& p_tk)
99{
100 for (int j=p_data()->beginCols(); j< p_data()->endCols(); ++j)
101 {
102 Real m = p_data()->col(j).template cast<Real>().mean();
103 for (int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
104 {
105 param_.lambdak_[k] = Law::Exponential::rand(m)/param_.lambdaj_[j];
106 }
107 }
108}
109
110
111/* Compute the lambdas */
112template<class Array>
113bool Poisson_ljlk<Array>::run( CArrayXX const* const& p_tik, CPointX const* const& p_tk)
114{
115 param_.lambdaj_ = (Stat::sumByRow(*p_tik).transpose() * (*p_data()))
116 /(Stat::sumByRow(*p_tik) * Stat::sumByRow(*p_data())).sum();
117 param_.lambdak_ = Stat::sumByRow(*p_data()).transpose() * (*p_tik)/(*p_tk);
118 return true;
119}
120
121} // namespace STK
122
123#endif /* STK_Poisson_LJLK_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_ljlk is a Poisson model with a probability function of the form.
~Poisson_ljlk()
destructor
PoissonBase< Poisson_ljlk< Array > > Base
bool run(CArrayXX const *const &p_tik, CPointX const *const &p_tk)
Compute the weighted probabilities.
int computeNbFreeParameters() const
Poisson_ljlk(Poisson_ljlk const &model)
copy constructor
Poisson_ljlk(int nbCluster)
default constructor
void randomInit(CArrayXX const *const &p_tik, CPointX const *const &p_tk)
Initialize randomly the parameters of the Poisson mixture.
Arrays::SumOp< Lhs, Rhs >::result_type sum(Lhs const &lhs, Rhs const &rhs)
convenience function for summing two arrays
double Real
STK fundamental type of Real values.
hidden::FunctorTraits< Derived, SumOp >::Col sumByRow(Derived const &A)
The namespace STK is the main domain space of the Statistical ToolKit project.
ModelParameters< Clust::Poisson_ljlk_ > Parameters
Type of the structure storing the parameters of a MixturePoisson_ljlk model.
Main class for the mixtures traits policy.