STK++ 0.9.13
STK::PoissonBase< Derived > Class Template Reference

Base class for the Poisson models. More...

#include <STK_PoissonBase.h>

Inheritance diagram for STK::PoissonBase< Derived >:
Inheritance graph

Public Types

typedef IMixtureDensity< Derived > Base
 
- Public Types inherited from STK::IMixtureDensity< Derived >
typedef hidden::MixtureTraits< Derived >::Array Array
 
typedef hidden::MixtureTraits< Derived >::Parameters Parameters
 
typedef hidden::Traits< Array >::Type Type
 

Public Member Functions

Real lambda (int k, int j) const
 
void initializeModelImpl ()
 Initialize the parameters of the model.
 
Real lnComponentProbability (int i, int k) const
 
template<class Weights >
int impute (int i, int j, Weights const &pk) const
 
Real impute (int i, int j, CArrayXX const *p_tik) const
 
int rand (int i, int j, int k) const
 
template<class Array >
void getParameters (Array &params) const
 This function is used in order to get the current values of the lambdas.
 
void writeParameters (CArrayXX const *p_tik, ostream &os) const
 This function can be used to write summary of parameters to the output stream.
 
Array const *constp_data () const
 
int nbCluster () const
 
- Public Member Functions inherited from STK::IMixtureDensity< Derived >
 ~IMixtureDensity ()
 destructor
 
int nbCluster () const
 
int nbSample () const
 
Real lnNbSample () const
 
Array const *constp_data () const
 
Parameters constparam () const
 
void setData (Array const &data)
 Set the data set.
 
void setData (Array const &data, int nbRow, int nbCol, bool byRow=true)
 Set the data set and give dimensions.
 
bool initializeStep ()
 This function will be called at the beginning of the estimation process once the model is created and data is set.
 
void setParametersStep ()
 set the parameters obtained with the intermediate results and release the intermediate results.
 
void finalizeStep ()
 This function will be called once the model is estimated.
 
template<class Weights >
Type sample (int i, int j, Weights const &tk) const
 
- Public Member Functions inherited from STK::IRecursiveTemplate< Derived >
Derived & asDerived ()
 static cast : return a reference of this with a cast to the derived class.
 
Derived constasDerived () const
 static cast : return a const reference of this with a cast to the derived class.
 
Derived * asPtrDerived ()
 static cast : return a ptr on a Derived of this with a cast to the derived class.
 
Derived constasPtrDerived () const
 static cast : return a ptr on a constant Derived of this with a cast to the derived class.
 
Derived * clone () const
 create a leaf using the copy constructor of the Derived class.
 
Derived * clone (bool isRef) const
 create a leaf using the copy constructor of the Derived class and a flag determining if the clone is a reference or not.
 

Public Attributes

Parameters param_
 parameters of the derived mixture model.
 

Protected Member Functions

 PoissonBase (int nbCluster)
 default constructor
 
 PoissonBase (PoissonBase const &model)
 copy constructor
 
 ~PoissonBase ()
 destructor
 
- Protected Member Functions inherited from STK::IMixtureDensity< Derived >
 IMixtureDensity (int nbCluster)
 Default constructor.
 
 IMixtureDensity (IMixtureDensity const &model)
 copy constructor.
 
void initializeModel ()
 Initialize the model before its first use.
 
bool initializeStepImpl ()
 default implementation of initializeStepImpl (do nothing and return true)
 
void finalizeStepImpl ()
 default implementation of finalizeStepImpl (do nothing)
 
void setNbSample (int nbSample)
 Set the number of sample of the model (needed by kernel models)
 
- Protected Member Functions inherited from STK::IRecursiveTemplate< Derived >
 IRecursiveTemplate ()
 constructor.
 
 ~IRecursiveTemplate ()
 destructor.
 

Additional Inherited Members

- Protected Attributes inherited from STK::IMixtureDensity< Derived >
Parameters param_
 parameters of the derived mixture model.
 

Detailed Description

template<class Derived>
class STK::PoissonBase< Derived >

Base class for the Poisson models.

Definition at line 48 of file STK_PoissonBase.h.

Member Typedef Documentation

◆ Base

template<class Derived >
typedef IMixtureDensity<Derived > STK::PoissonBase< Derived >::Base

Definition at line 51 of file STK_PoissonBase.h.

Constructor & Destructor Documentation

◆ PoissonBase() [1/2]

template<class Derived >
STK::PoissonBase< Derived >::PoissonBase ( int  nbCluster)
inlineprotected

default constructor

Parameters
nbClusternumber of cluster in the model

Definition at line 60 of file STK_PoissonBase.h.

60: Base(nbCluster) {}
IMixtureDensity< Derived > Base

◆ PoissonBase() [2/2]

template<class Derived >
STK::PoissonBase< Derived >::PoissonBase ( PoissonBase< Derived > const model)
inlineprotected

copy constructor

Parameters
modelThe model to copy

Definition at line 64 of file STK_PoissonBase.h.

64: Base(model) {}

◆ ~PoissonBase()

template<class Derived >
STK::PoissonBase< Derived >::~PoissonBase ( )
inlineprotected

destructor

Definition at line 66 of file STK_PoissonBase.h.

66{}

Member Function Documentation

◆ getParameters()

template<class Derived >
template<class Array >
void STK::PoissonBase< Derived >::getParameters ( Array params) const

This function is used in order to get the current values of the lambdas.

Parameters
[out]paramsthe array with the parameters of the mixture.

Definition at line 144 of file STK_PoissonBase.h.

145{
146 params.resize(nbCluster(), p_data()->cols());
147 for (int k= params.beginRows(); k < params.endRows(); ++k)
148 {
149 for (int j= p_data()->beginCols(); j < p_data()->endCols(); ++j)
150 { params(k, j) = lambda(k,j);}
151 }
152}
Array const *const & p_data() const
Real lambda(int k, int j) const

◆ impute() [1/2]

template<class Derived >
Real STK::PoissonBase< Derived >::impute ( int  i,
int  j,
CArrayXX const p_tik 
) const
Returns
a value to impute for the jth variable of the ith sample

Definition at line 131 of file STK_PoissonBase.h.

132{
133 Real sum = 0.;
134 for (int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
135 { sum += p_tik->elt(i,k) * lambda(k,j);}
136 return sum;
137}
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.

References STK::sum().

◆ impute() [2/2]

template<class Derived >
template<class Weights >
int STK::PoissonBase< Derived >::impute ( int  i,
int  j,
Weights const pk 
) const
Returns
an imputation value for the jth variable of the ith sample
Parameters
i,jindexes of the data to impute
pkthe probabilities of each class for the ith individual

Definition at line 121 of file STK_PoissonBase.h.

122{
123 Real sum = 0.;
124 for (int k= pk.begin(); k < pk.end(); ++k)
125 { sum += pk[k] * lambda(k,j);}
126 return std::floor(sum+0.5);
127}

References STK::sum().

◆ initializeModelImpl()

template<class Derived >
void STK::PoissonBase< Derived >::initializeModelImpl ( )
inline

Initialize the parameters of the model.

Definition at line 72 of file STK_PoissonBase.h.

72{ param_.resize(p_data()->cols());}
Parameters param_
parameters of the derived mixture model.

References STK::PoissonBase< Derived >::p_data(), and STK::PoissonBase< Derived >::param_.

◆ lambda()

template<class Derived >
Real STK::PoissonBase< Derived >::lambda ( int  k,
int  j 
) const
inline
Returns
the value of lambda of the kth cluster and jth variable

Definition at line 70 of file STK_PoissonBase.h.

70{ return param_.lambda(k,j);}

References STK::PoissonBase< Derived >::param_.

Referenced by STK::PoissonBase< Derived >::rand().

◆ lnComponentProbability()

template<class Derived >
Real STK::PoissonBase< Derived >::lnComponentProbability ( int  i,
int  k 
) const
Returns
the value of the probability of the i-th sample in the k-th component.
Parameters
i,kindexes of the sample and of the component

Definition at line 107 of file STK_PoissonBase.h.

108{
109 Real sum =0.;
110 for (int j=p_data()->beginCols(); j<p_data()->endCols(); ++j)
111 {
112 Real value = lambda(k,j);
113 if (value)
114 { sum += Law::Poisson::lpdf(p_data()->elt(i,j), value);}
115 }
116 return sum;
117}
virtual Real lpdf(int const &x) const
compute the log probability distribution function.

References STK::Law::Poisson::lpdf(), and STK::sum().

◆ nbCluster()

template<class Derived >
int STK::IMixtureDensity< Derived >::nbCluster ( ) const
inline
Returns
the number of cluster

Definition at line 124 of file STK_IMixtureDensity.h.

124{ return nbCluster_;}
int nbCluster_
number of cluster.

◆ p_data()

template<class Derived >
Array const *const & STK::IMixtureDensity< Derived >::p_data ( ) const
inline
Returns
a pointer on the current data set

Definition at line 131 of file STK_IMixtureDensity.h.

131{ return p_dataij_;}
Array const * p_dataij_
pointer on the data set

Referenced by STK::PoissonBase< Derived >::initializeModelImpl().

◆ rand()

template<class Derived >
int STK::PoissonBase< Derived >::rand ( int  i,
int  j,
int  k 
) const
inline
Returns
a simulated value for the jth variable of the ith sample in the kth cluster.
Parameters
i,j,kindexes of the data to simulate

Definition at line 89 of file STK_PoissonBase.h.

90 { return Law::Poisson::rand(lambda(k,j));}
virtual int rand() const

References STK::PoissonBase< Derived >::lambda(), and STK::Law::Poisson::rand().

◆ writeParameters()

template<class Derived >
void STK::PoissonBase< Derived >::writeParameters ( CArrayXX const p_tik,
ostream os 
) const

This function can be used to write summary of parameters to the output stream.

Parameters
p_tika constant pointer on the posterior probabilities
osStream where you want to write the summary of parameters.

Definition at line 160 of file STK_PoissonBase.h.

161{
162 CPointX params(p_data()->cols());
163 for (int k= p_tik->beginCols(); k < p_tik->endCols(); ++k)
164 {
165 for (int j= p_data()->beginCols(); j < p_data()->endCols(); ++j)
166 { params[j] = lambda(k,j);}
167 os << _T("---> Component ") << k << _T("\n");
168 os << _T("lambda = ") << params;
169 }
170}
#define _T(x)
Let x unmodified.
CArrayPoint< Real, UnknownSize, Arrays::by_col_ > CPointX

References _T.

Member Data Documentation

◆ param_

template<class Derived >
Parameters STK::IMixtureDensity< Derived >::param_

parameters of the derived mixture model.

Should be an instance of the STK::ModelParameters struct.

See also
STK::ModelParameters

Definition at line 180 of file STK_IMixtureDensity.h.

Referenced by STK::PoissonBase< Derived >::initializeModelImpl(), and STK::PoissonBase< Derived >::lambda().


The documentation for this class was generated from the following file: