STK++ 0.9.13
STK::ModelGamma_aj_bj< Data_, WColVector_ > Class Template Reference

A joint Gamma model is a statistical model of the following form. More...

#include <STK_ModelGamma_aj_bj.h>

Inheritance diagram for STK::ModelGamma_aj_bj< Data_, WColVector_ >:
Inheritance graph

Classes

class  dloglikelihood
 

Public Types

typedef DataBridge< Data_Data
 Type of the container storing the data.
 
typedef hidden::Traits< Data_ >::Row RowVector
 
typedef WColVector_ WColVector
 Type of the array storing the weights of the data.
 
typedef IMultiStatModel< ModelGamma_aj_bj< Data_, WColVector_ > > Base
 Type of the data in the container.
 
- Public Types inherited from STK::IMultiStatModel< ModelGamma_aj_bj< Data_, WColVector_ > >
typedef hidden::StatModelTraits< ModelGamma_aj_bj< Data_, WColVector_ > >::Data Data
 Type of the container with the data.
 
typedef hidden::StatModelTraits< ModelGamma_aj_bj< Data_, WColVector_ > >::Type Type
 Type of the data in the container.
 
typedef hidden::StatModelTraits< ModelGamma_aj_bj< Data_, WColVector_ > >::WColVector WColVector
 Type of the vector with the weights.
 
typedef hidden::StatModelTraits< ModelGamma_aj_bj< Data_, WColVector_ > >::Parameters Parameters
 Type of the parameters of the Model.
 

Public Member Functions

 ModelGamma_aj_bj ()
 default constructor.
 
 ModelGamma_aj_bj (Data const &data)
 Constructor with data set.
 
 ModelGamma_aj_bj (Data const *p_data)
 Constructor with a ptr on the data set.
 
 ModelGamma_aj_bj (ModelGamma_aj_bj const &model)
 Copy constructor.
 
 ~ModelGamma_aj_bj ()
 destructor
 
CPointX constshape () const
 
CPointX constscale () const
 
CPointX constmean () const
 
CPointX constmeanLog () const
 vector of the mean log of the observations
 
CPointX constvariance () const
 vector of the variance of the observations
 
int computeNbFreeParameters () const
 compute the number of free parameters
 
Real computeLnLikelihood (RowVector const &rowData) const
 compute the log Likelihood of an observation.
 
void computeParameters ()
 compute the parameters
 
void computeParameters (WColVector const &weights)
 compute the weighted parameters
 
void writeParametersImpl (ostream &os) const
 Write the parameters on the output stream os.
 
- Public Member Functions inherited from STK::IMultiStatModel< ModelGamma_aj_bj< Data_, WColVector_ > >
Data const *const p_data () const
 
Parameters constparam () const
 
String consterror () const
 
void setData (Data const *p_data)
 Set the data set.
 
bool run ()
 Estimate the parameters of the model and update the model.
 
bool run (WColVector const &weights)
 compute the weighted empirical probability of success based on the observed variables.
 
void writeParameters (ostream &os)
 
void writeParametersImpl (ostream &os)
 default implementation of the writeParameters method.
 
- Public Member Functions inherited from STK::IStatModelBase
int nbSample () const
 
Real lnNbSample () const
 
int nbVariable () const
 
Real lnLikelihood () const
 
Real likelihood () const
 
int nbFreeParameter () const
 
Real computeBIC () const
 
Real computeAIC () const
 
Real computeML () 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.
 

Private Member Functions

CPointXshape ()
 
CPointXscale ()
 
CPointXmean ()
 
CPointXmeanLog ()
 vector of the mean log of the observations
 
CPointXvariance ()
 vector of the variance of the observations
 

Additional Inherited Members

- Protected Member Functions inherited from STK::IMultiStatModel< ModelGamma_aj_bj< Data_, WColVector_ > >
 IMultiStatModel ()
 default constructor.
 
 IMultiStatModel (Data const &data)
 Constructor with data set.
 
 IMultiStatModel (Data const *p_data)
 Constructor with a ptr on the data set.
 
 IMultiStatModel (IMultiStatModel const &model)
 Copy constructor.
 
 ~IMultiStatModel ()
 destructor
 
Parametersparam ()
 
Real computeLnLikelihood () const
 compute the log Likelihood of the statistical model.
 
void update ()
 update the model if a new data set is set
 
- Protected Member Functions inherited from STK::IStatModelBase
 IStatModelBase ()
 Default constructor.
 
 IStatModelBase (int nbSample)
 Constructor with specified dimension.
 
 IStatModelBase (int nbSample, int nbVariable)
 Constructor with specified dimension.
 
 IStatModelBase (IStatModelBase const &model)
 Copy constructor.
 
 ~IStatModelBase ()
 destructor
 
void setNbFreeParameter (int const &nbFreeParameter)
 set the number of free parameters of the model
 
void setNbSample (int const &nbSample)
 set the number of samples of the model
 
void setNbVariable (int const &nbVariable)
 set the number of variables of the model
 
void setLnLikelihood (Real const &lnLikelihood)
 set the log-likelihood of the model
 
void initialize (int nbSample, int nbVariable)
 set the dimensions of the parameters of the model
 
- Protected Member Functions inherited from STK::IRecursiveTemplate< Derived >
 IRecursiveTemplate ()
 constructor.
 
 ~IRecursiveTemplate ()
 destructor.
 
- Protected Attributes inherited from STK::IMultiStatModel< ModelGamma_aj_bj< Data_, WColVector_ > >
Data constp_data_
 Pointer on the parameters of the model.
 
Parameters param_
 Pointer on the parameters of the model.
 
String msg_error_
 String with the last error message.
 

Detailed Description

template<class Data_, class WColVector_>
class STK::ModelGamma_aj_bj< Data_, WColVector_ >

A joint Gamma model is a statistical model of the following form.

\[
    f(\mathbf{x}_i|\theta) =
    \prod_{j=1}^p\left(\frac{x_i^j}{b_j}\right)^{a_j-1}
                  \frac{e^{-x_i^j/b_j}}{b_j \, \Gamma(a_j)},
     \quad x_i^j\in\{0,1\}, \quad j=1,\ldots,p, \quad i=1,\ldots,n.
\]

Definition at line 142 of file STK_ModelGamma_aj_bj.h.

Member Typedef Documentation

◆ Base

Type of the data in the container.

Base class

Definition at line 171 of file STK_ModelGamma_aj_bj.h.

◆ Data

Type of the container storing the data.

Definition at line 163 of file STK_ModelGamma_aj_bj.h.

◆ RowVector

◆ WColVector

Type of the array storing the weights of the data.

Definition at line 166 of file STK_ModelGamma_aj_bj.h.

Constructor & Destructor Documentation

◆ ModelGamma_aj_bj() [1/4]

template<class Data_ , class WColVector_ >
STK::ModelGamma_aj_bj< Data_, WColVector_ >::ModelGamma_aj_bj ( )
inline

default constructor.

Definition at line 176 of file STK_ModelGamma_aj_bj.h.

176: Base() {}
IMultiStatModel< ModelGamma_aj_bj< Data_, WColVector_ > > Base
Type of the data in the container.

◆ ModelGamma_aj_bj() [2/4]

template<class Data_ , class WColVector_ >
STK::ModelGamma_aj_bj< Data_, WColVector_ >::ModelGamma_aj_bj ( Data const data)
inline

Constructor with data set.

Definition at line 178 of file STK_ModelGamma_aj_bj.h.

178: Base(data){}

◆ ModelGamma_aj_bj() [3/4]

template<class Data_ , class WColVector_ >
STK::ModelGamma_aj_bj< Data_, WColVector_ >::ModelGamma_aj_bj ( Data const p_data)
inline

Constructor with a ptr on the data set.

Definition at line 180 of file STK_ModelGamma_aj_bj.h.

◆ ModelGamma_aj_bj() [4/4]

template<class Data_ , class WColVector_ >
STK::ModelGamma_aj_bj< Data_, WColVector_ >::ModelGamma_aj_bj ( ModelGamma_aj_bj< Data_, WColVector_ > const model)
inline

Copy constructor.

Definition at line 182 of file STK_ModelGamma_aj_bj.h.

182: Base(model) {}

◆ ~ModelGamma_aj_bj()

destructor

Definition at line 184 of file STK_ModelGamma_aj_bj.h.

184{}

Member Function Documentation

◆ computeLnLikelihood()

template<class Data_ , class WColVector_ >
Real STK::ModelGamma_aj_bj< Data_, WColVector_ >::computeLnLikelihood ( RowVector const rowData) const

compute the log Likelihood of an observation.

Definition at line 223 of file STK_ModelGamma_aj_bj.h.

224{
225 Real sum =0.;
226 for (Integer j= rowData.begin(); j < rowData.end(); ++j)
227 { sum += Law::Gamma::lpdf(rowData[j], shape()[j], scale()[j]);}
228 return sum;
229}
virtual Real lpdf(Real const &x) const
Compute.
CPointX const & scale() const
CPointX const & shape() const
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.
int Integer
STK fundamental type of integer values.

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

◆ computeNbFreeParameters()

template<class Data_ , class WColVector_ >
int STK::ModelGamma_aj_bj< Data_, WColVector_ >::computeNbFreeParameters ( ) const
inline

compute the number of free parameters

Definition at line 198 of file STK_ModelGamma_aj_bj.h.

198{ return 2*p_data()->dataij().sizeCols();}

References STK::IMultiStatModel< ModelGamma_aj_bj< Data_, WColVector_ > >::p_data().

◆ computeParameters() [1/2]

template<class Data_ , class WColVector_ >
void STK::ModelGamma_aj_bj< Data_, WColVector_ >::computeParameters ( )

compute the parameters

Definition at line 233 of file STK_ModelGamma_aj_bj.h.

234{
235 for (int j=p_data()->dataij().beginCols(); j < p_data()->dataij().endCols(); ++j)
236 {
237 mean()[j] = p_data()->dataij().col(j).meanSafe();
238 meanLog()[j] = p_data()->dataij().col(j).safe(1.).log().mean();
239 variance()[j] = p_data()->dataij().col(j).safe().variance();
240 Real x0 = (mean()[j]*mean()[j]) / variance()[j];
241 Real x1 = 0.9*x0 + 0.05/(mean()[j] - meanLog()[j]);
242 dloglikelihood funct(mean()[j], meanLog()[j]);
243 Real a = Algo::findZero(funct, x0, x1, 1e-08);
244 // replace with moment estimate if needed
245 if (!Arithmetic<Real>::isFinite(a)) { a = mean()[j]*mean()[j]/variance()[j];}
246 shape()[j] = a;
247 scale()[j] = mean()[j]/a;
248 }
249}
CPointX const & variance() const
vector of the variance of the observations
CPointX const & meanLog() const
vector of the mean log of the observations
CPointX const & mean() const
Real findZero(IFunction< Function > const &f, Real const &x0, Real const &x1, Real tol)
find the zero of a function.
static bool isFinite(Type const &x)

References STK::Algo::findZero(), and STK::mean().

◆ computeParameters() [2/2]

template<class Data_ , class WColVector_ >
void STK::ModelGamma_aj_bj< Data_, WColVector_ >::computeParameters ( WColVector const weights)

compute the weighted parameters

Definition at line 252 of file STK_ModelGamma_aj_bj.h.

253{
254 for (int j=p_data()->dataij().beginCols(); j < p_data()->dataij().endCols(); ++j)
255 {
256 mean()[j] = p_data()->dataij().col(j).safe().wmean(weights);
257 meanLog()[j] = p_data()->dataij().col(j).safe(1).log().wmean(weights);
258 variance()[j] = p_data()->dataij().col(j).safe().wvariance(weights);
259 Real x0 = (mean()[j]*mean()[j]) / variance()[j];
260 Real x1 = 0.9*x0 + 0.05/(mean()[j] - meanLog()[j]);
261 dloglikelihood funct(mean()[j], meanLog()[j]);
262 Real a = Algo::findZero(funct, x0, x1, 1e-08);
263 // replace with moment estimate if needed
264 if (!Arithmetic<Real>::isFinite(a)) { a = mean()[j]*mean()[j]/variance()[j];}
265 shape()[j] = a;
266 scale()[j] = mean()[j]/a;
267 }
268}

References STK::Algo::findZero(), and STK::mean().

◆ mean() [1/2]

template<class Data_ , class WColVector_ >
CPointX & STK::ModelGamma_aj_bj< Data_, WColVector_ >::mean ( )
inlineprivate
Returns
the vector of the mean of the observations

Definition at line 214 of file STK_ModelGamma_aj_bj.h.

214{ return param().mean_;}

References STK::IMultiStatModel< ModelGamma_aj_bj< Data_, WColVector_ > >::param().

◆ mean() [2/2]

template<class Data_ , class WColVector_ >
CPointX const & STK::ModelGamma_aj_bj< Data_, WColVector_ >::mean ( ) const
inline
Returns
the vector of the mean of the observations

Definition at line 191 of file STK_ModelGamma_aj_bj.h.

191{return param().mean_;}

References STK::IMultiStatModel< ModelGamma_aj_bj< Data_, WColVector_ > >::param().

◆ meanLog() [1/2]

template<class Data_ , class WColVector_ >
CPointX & STK::ModelGamma_aj_bj< Data_, WColVector_ >::meanLog ( )
inlineprivate

vector of the mean log of the observations

Definition at line 216 of file STK_ModelGamma_aj_bj.h.

216{ return param().meanLog_;}

References STK::IMultiStatModel< ModelGamma_aj_bj< Data_, WColVector_ > >::param().

◆ meanLog() [2/2]

template<class Data_ , class WColVector_ >
CPointX const & STK::ModelGamma_aj_bj< Data_, WColVector_ >::meanLog ( ) const
inline

vector of the mean log of the observations

Definition at line 193 of file STK_ModelGamma_aj_bj.h.

193{return param().meanLog_;}

References STK::IMultiStatModel< ModelGamma_aj_bj< Data_, WColVector_ > >::param().

◆ scale() [1/2]

template<class Data_ , class WColVector_ >
CPointX & STK::ModelGamma_aj_bj< Data_, WColVector_ >::scale ( )
inlineprivate
Returns
the vector of the scale of the observations

Definition at line 212 of file STK_ModelGamma_aj_bj.h.

212{ return param().scale_;}

References STK::IMultiStatModel< ModelGamma_aj_bj< Data_, WColVector_ > >::param().

◆ scale() [2/2]

template<class Data_ , class WColVector_ >
CPointX const & STK::ModelGamma_aj_bj< Data_, WColVector_ >::scale ( ) const
inline
Returns
the vector of the mean of the observations

Definition at line 189 of file STK_ModelGamma_aj_bj.h.

189{return param().scale_;}

References STK::IMultiStatModel< ModelGamma_aj_bj< Data_, WColVector_ > >::param().

◆ shape() [1/2]

template<class Data_ , class WColVector_ >
CPointX & STK::ModelGamma_aj_bj< Data_, WColVector_ >::shape ( )
inlineprivate
Returns
the vector of the shape of the observations

Definition at line 210 of file STK_ModelGamma_aj_bj.h.

210{ return param().shape_;}

References STK::IMultiStatModel< ModelGamma_aj_bj< Data_, WColVector_ > >::param().

◆ shape() [2/2]

template<class Data_ , class WColVector_ >
CPointX const & STK::ModelGamma_aj_bj< Data_, WColVector_ >::shape ( ) const
inline
Returns
the vector of the mean of the observations

Definition at line 187 of file STK_ModelGamma_aj_bj.h.

187{return param().shape_;}

References STK::IMultiStatModel< ModelGamma_aj_bj< Data_, WColVector_ > >::param().

◆ variance() [1/2]

template<class Data_ , class WColVector_ >
CPointX & STK::ModelGamma_aj_bj< Data_, WColVector_ >::variance ( )
inlineprivate

vector of the variance of the observations

Definition at line 218 of file STK_ModelGamma_aj_bj.h.

218{ return param().variance_;}

References STK::IMultiStatModel< ModelGamma_aj_bj< Data_, WColVector_ > >::param().

◆ variance() [2/2]

template<class Data_ , class WColVector_ >
CPointX const & STK::ModelGamma_aj_bj< Data_, WColVector_ >::variance ( ) const
inline

vector of the variance of the observations

Definition at line 195 of file STK_ModelGamma_aj_bj.h.

195{return param().variance_;}

References STK::IMultiStatModel< ModelGamma_aj_bj< Data_, WColVector_ > >::param().

◆ writeParametersImpl()

template<class Data_ , class WColVector_ >
void STK::ModelGamma_aj_bj< Data_, WColVector_ >::writeParametersImpl ( ostream os) const

Write the parameters on the output stream os.

Definition at line 272 of file STK_ModelGamma_aj_bj.h.

273{
274 os << _T("shape = ") << shape();
275 os << _T("scale = ") << scale();
276}
#define _T(x)
Let x unmodified.

References _T.


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