STK++ 0.9.13
STK::JointGammaModel< Array, WColVector > Class Template Reference

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

#include <STK_JointGammaModel.h>

Inheritance diagram for STK::JointGammaModel< Array, WColVector >:
Inheritance graph

Classes

class  dloglikelihood
 

Public Types

typedef Array::Type Type
 Type of the data contained in the container.
 
typedef hidden::Traits< Array >::Row RowVector
 Type of the row vector of the container.
 
typedef hidden::Traits< Array >::Col ColVector
 Type of the column vector of the container.
 
typedef IMultiStatModel< Array, WColVector, JointGammaParametersBase
 Base class.
 
- Public Types inherited from STK::IMultiStatModel< Array, WColVector, JointGammaParameters >
typedef hidden::StatModelTraits< Array >::Data Data
 Type of the container with the data.
 
typedef hidden::StatModelTraits< Array >::Type Type
 Type of the data in the container.
 
typedef hidden::StatModelTraits< Array >::WColVector WColVector
 Type of the vector with the weights.
 
typedef hidden::StatModelTraits< Array >::Parameters Parameters
 Type of the parameters of the Model.
 

Public Member Functions

 JointGammaModel ()
 default constructor.
 
 JointGammaModel (Array const &data)
 Constructor with data set.
 
 JointGammaModel (Array const *p_data)
 Constructor with a ptr on the data set.
 
 JointGammaModel (JointGammaModel const &model)
 Copy constructor.
 
virtual ~JointGammaModel ()
 destructor
 
JointGammaModelclone () const
 clone pattern.
 
Array2DPoint< Real > constshape () const
 
Array2DPoint< Real > constscale () const
 
Array2DPoint< Real > constmean () const
 
Array2DPoint< Real > constmeanLog () const
 vector of the mean log of the observations
 
Array2DPoint< Real > constvariance () const
 vector of the variance of the observations
 
virtual int computeNbFreeParameters () const
 compute the number of free parameters
 
virtual Real computeLnLikelihood (RowVector const &rowData) const
 compute the log Likelihood of an observation.
 
- Public Member Functions inherited from STK::IMultiStatModel< Array, WColVector, JointGammaParameters >
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.
 

Protected Member Functions

virtual void computeParameters ()
 compute the parameters
 
virtual void computeParameters (WColVector const &weights)
 compute the weighted parameters
 
- Protected Member Functions inherited from STK::IMultiStatModel< Array, WColVector, JointGammaParameters >
 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.
 

Private Member Functions

Array2DPoint< Real > & shape ()
 
Array2DPoint< Real > & scale ()
 
Array2DPoint< Real > & mean ()
 
Array2DPoint< Real > & meanLog ()
 vector of the mean log of the observations
 
Array2DPoint< Real > & variance ()
 vector of the variance of the observations
 

Additional Inherited Members

- Protected Attributes inherited from STK::IMultiStatModel< Array, WColVector, JointGammaParameters >
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 Array, class WColVector>
class STK::JointGammaModel< Array, 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 110 of file STK_JointGammaModel.h.

Member Typedef Documentation

◆ Base

Base class.

Definition at line 121 of file STK_JointGammaModel.h.

◆ ColVector

template<class Array , class WColVector >
typedef hidden::Traits<Array>::Col STK::JointGammaModel< Array, WColVector >::ColVector

Type of the column vector of the container.

Definition at line 119 of file STK_JointGammaModel.h.

◆ RowVector

template<class Array , class WColVector >
typedef hidden::Traits<Array>::Row STK::JointGammaModel< Array, WColVector >::RowVector

Type of the row vector of the container.

Definition at line 117 of file STK_JointGammaModel.h.

◆ Type

template<class Array , class WColVector >
typedef Array::Type STK::JointGammaModel< Array, WColVector >::Type

Type of the data contained in the container.

Definition at line 115 of file STK_JointGammaModel.h.

Constructor & Destructor Documentation

◆ JointGammaModel() [1/4]

template<class Array , class WColVector >
STK::JointGammaModel< Array, WColVector >::JointGammaModel ( )
inline

default constructor.

Definition at line 125 of file STK_JointGammaModel.h.

125: Base() {}
IMultiStatModel< Array, WColVector, JointGammaParameters > Base
Base class.

Referenced by STK::JointGammaModel< Array, WColVector >::clone().

◆ JointGammaModel() [2/4]

template<class Array , class WColVector >
STK::JointGammaModel< Array, WColVector >::JointGammaModel ( Array const data)
inline

Constructor with data set.

Definition at line 127 of file STK_JointGammaModel.h.

127: Base(data){}

◆ JointGammaModel() [3/4]

template<class Array , class WColVector >
STK::JointGammaModel< Array, WColVector >::JointGammaModel ( Array const p_data)
inline

Constructor with a ptr on the data set.

Definition at line 129 of file STK_JointGammaModel.h.

◆ JointGammaModel() [4/4]

template<class Array , class WColVector >
STK::JointGammaModel< Array, WColVector >::JointGammaModel ( JointGammaModel< Array, WColVector > const model)
inline

Copy constructor.

Definition at line 131 of file STK_JointGammaModel.h.

131: Base(model) {}

◆ ~JointGammaModel()

template<class Array , class WColVector >
virtual STK::JointGammaModel< Array, WColVector >::~JointGammaModel ( )
inlinevirtual

destructor

Definition at line 133 of file STK_JointGammaModel.h.

133{}

Member Function Documentation

◆ clone()

template<class Array , class WColVector >
JointGammaModel * STK::JointGammaModel< Array, WColVector >::clone ( ) const
inline

clone pattern.

Returns
a clone of this.

Definition at line 135 of file STK_JointGammaModel.h.

135{ return new JointGammaModel(*this);}
JointGammaModel()
default constructor.

References STK::JointGammaModel< Array, WColVector >::JointGammaModel().

◆ computeLnLikelihood()

template<class Array , class WColVector >
virtual Real STK::JointGammaModel< Array, WColVector >::computeLnLikelihood ( RowVector const rowData) const
inlinevirtual

compute the log Likelihood of an observation.

Definition at line 152 of file STK_JointGammaModel.h.

153 {
154 Real sum =0.;
155 for (Integer j= rowData.begin(); j < rowData.end(); ++j)
156 { sum += Law::Gamma::lpdf(rowData[j], shape()[j], scale()[j]);}
157 return sum;
158 }
Array2DPoint< Real > const & shape() const
Array2DPoint< Real > const & scale() const
virtual Real lpdf(Real const &x) const
Compute.
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(), STK::JointGammaModel< Array, WColVector >::scale(), STK::JointGammaModel< Array, WColVector >::shape(), and STK::sum().

◆ computeNbFreeParameters()

template<class Array , class WColVector >
virtual int STK::JointGammaModel< Array, WColVector >::computeNbFreeParameters ( ) const
inlinevirtual

compute the number of free parameters

Definition at line 149 of file STK_JointGammaModel.h.

150 { return 2*p_data()->sizeCols();}

References STK::IMultiStatModel< Array, WColVector, JointGammaParameters >::p_data().

◆ computeParameters() [1/2]

template<class Array , class WColVector >
virtual void STK::JointGammaModel< Array, WColVector >::computeParameters ( )
inlineprotectedvirtual

compute the parameters

Definition at line 176 of file STK_JointGammaModel.h.

177 {
178 for (int j=p_data()->beginCols(); j < p_data()->endCols(); ++j)
179 {
180 mean()[j] = p_data()->col(j).safe().mean();
181 meanLog()[j] = p_data()->col(j).safe(1.).log().mean();
182 variance()[j] = p_data()->col(j).safe().variance();
183 Real x0 = (mean()[j]*mean()[j]) / variance()[j];
184 Real x1 = 0.9*x0 + 0.05/(mean()[j] - meanLog()[j]);
185 dloglikelihood funct(mean()[j], meanLog()[j]);
186 Real a = Algo::findZero(funct, x0, x1);
187 // replace with moment estimate if needed
188 if (!Arithmetic<Real>::isFinite(a)) { a = mean()[j]*mean()[j]/variance()[j];}
189 shape()[j] = a;
190 scale()[j] = mean()[j]/a;
191 }
192 }
Array2DPoint< Real > const & meanLog() const
vector of the mean log of the observations
Array2DPoint< Real > const & variance() const
vector of the variance of the observations
Array2DPoint< Real > 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(), STK::JointGammaModel< Array, WColVector >::mean(), STK::JointGammaModel< Array, WColVector >::meanLog(), STK::IMultiStatModel< Array, WColVector, JointGammaParameters >::p_data(), STK::JointGammaModel< Array, WColVector >::scale(), STK::JointGammaModel< Array, WColVector >::shape(), and STK::JointGammaModel< Array, WColVector >::variance().

◆ computeParameters() [2/2]

template<class Array , class WColVector >
virtual void STK::JointGammaModel< Array, WColVector >::computeParameters ( WColVector const weights)
inlineprotectedvirtual

compute the weighted parameters

Definition at line 194 of file STK_JointGammaModel.h.

195 {
196 for (int j=p_data()->beginCols(); j < p_data()->endCols(); ++j)
197 {
198 mean()[j] = p_data()->col(j).safe().wmean(weights);
199 meanLog()[j] = p_data()->col(j).safe(1).log().wmean(weights);
200 variance()[j] = p_data()->col(j).safe().wvariance(weights);
201 Real x0 = (mean()[j]*mean()[j]) / variance()[j];
202 Real x1 = 0.9*x0 + 0.05/(mean()[j] - meanLog()[j]);
203 dloglikelihood funct(mean()[j], meanLog()[j]);
204 Real a = Algo::findZero(funct, x0, x1);
205 // replace with moment estimate if needed
206 if (!Arithmetic<Real>::isFinite(a)) { a = mean()[j]*mean()[j]/variance()[j];}
207 shape()[j] = a;
208 scale()[j] = mean()[j]/a;
209 }
210 }

References STK::Algo::findZero(), STK::JointGammaModel< Array, WColVector >::mean(), STK::JointGammaModel< Array, WColVector >::meanLog(), STK::IMultiStatModel< Array, WColVector, JointGammaParameters >::p_data(), STK::JointGammaModel< Array, WColVector >::scale(), STK::JointGammaModel< Array, WColVector >::shape(), and STK::JointGammaModel< Array, WColVector >::variance().

◆ mean() [1/2]

template<class Array , class WColVector >
Array2DPoint< Real > & STK::JointGammaModel< Array, WColVector >::mean ( )
inlineprivate
Returns
the vector of the mean of the observations

Definition at line 218 of file STK_JointGammaModel.h.

218{return p_param()->mean_;}

◆ mean() [2/2]

template<class Array , class WColVector >
Array2DPoint< Real > const & STK::JointGammaModel< Array, WColVector >::mean ( ) const
inline
Returns
the vector of the mean of the observations

Definition at line 142 of file STK_JointGammaModel.h.

142{return p_param()->mean_;}

Referenced by STK::JointGammaModel< Array, WColVector >::computeParameters(), and STK::JointGammaModel< Array, WColVector >::computeParameters().

◆ meanLog() [1/2]

template<class Array , class WColVector >
Array2DPoint< Real > & STK::JointGammaModel< Array, WColVector >::meanLog ( )
inlineprivate

vector of the mean log of the observations

Definition at line 220 of file STK_JointGammaModel.h.

220{return p_param()->meanLog_;}

◆ meanLog() [2/2]

template<class Array , class WColVector >
Array2DPoint< Real > const & STK::JointGammaModel< Array, WColVector >::meanLog ( ) const
inline

vector of the mean log of the observations

Definition at line 144 of file STK_JointGammaModel.h.

144{return p_param()->meanLog_;}

Referenced by STK::JointGammaModel< Array, WColVector >::computeParameters(), and STK::JointGammaModel< Array, WColVector >::computeParameters().

◆ scale() [1/2]

template<class Array , class WColVector >
Array2DPoint< Real > & STK::JointGammaModel< Array, WColVector >::scale ( )
inlineprivate
Returns
the vector of the mean of the observations

Definition at line 216 of file STK_JointGammaModel.h.

216{return p_param()->scale_;}

◆ scale() [2/2]

template<class Array , class WColVector >
Array2DPoint< Real > const & STK::JointGammaModel< Array, WColVector >::scale ( ) const
inline

◆ shape() [1/2]

template<class Array , class WColVector >
Array2DPoint< Real > & STK::JointGammaModel< Array, WColVector >::shape ( )
inlineprivate
Returns
the vector of the mean of the observations

Definition at line 214 of file STK_JointGammaModel.h.

214{return p_param()->shape_;}

◆ shape() [2/2]

template<class Array , class WColVector >
Array2DPoint< Real > const & STK::JointGammaModel< Array, WColVector >::shape ( ) const
inline

◆ variance() [1/2]

template<class Array , class WColVector >
Array2DPoint< Real > & STK::JointGammaModel< Array, WColVector >::variance ( )
inlineprivate

vector of the variance of the observations

Definition at line 222 of file STK_JointGammaModel.h.

222{return p_param()->variance_;}

◆ variance() [2/2]

template<class Array , class WColVector >
Array2DPoint< Real > const & STK::JointGammaModel< Array, WColVector >::variance ( ) const
inline

vector of the variance of the observations

Definition at line 146 of file STK_JointGammaModel.h.

146{return p_param()->variance_;}

Referenced by STK::JointGammaModel< Array, WColVector >::computeParameters(), and STK::JointGammaModel< Array, WColVector >::computeParameters().


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