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

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

#include <STK_ModelBernoulli_pj.h>

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

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 hidden::Traits< Data_ >::Type Type
 Type of the data in the container.
 
typedef IMultiStatModel< ModelBernoulli_pj< Data_, WColVector_ > > Base
 Base class.
 
- Public Types inherited from STK::IMultiStatModel< ModelBernoulli_pj< Data_, WColVector_ > >
typedef hidden::StatModelTraits< ModelBernoulli_pj< Data_, WColVector_ > >::Data Data
 Type of the container with the data.
 
typedef hidden::StatModelTraits< ModelBernoulli_pj< Data_, WColVector_ > >::Type Type
 Type of the data in the container.
 
typedef hidden::StatModelTraits< ModelBernoulli_pj< Data_, WColVector_ > >::WColVector WColVector
 Type of the vector with the weights.
 
typedef hidden::StatModelTraits< ModelBernoulli_pj< Data_, WColVector_ > >::Parameters Parameters
 Type of the parameters of the Model.
 

Public Member Functions

 ModelBernoulli_pj ()
 default constructor.
 
 ModelBernoulli_pj (Data const &data)
 Constructor with data set.
 
 ModelBernoulli_pj (Data const *p_data)
 Constructor with a ptr on the data set.
 
 ModelBernoulli_pj (ModelBernoulli_pj const &model)
 Copy constructor.
 
 ~ModelBernoulli_pj ()
 destructor
 
CPointX constprob () const
 
CPointX constlnProb () const
 vector of the log probabilities of the observations
 
CPointX constln1mProb () const
 vector of the log probabilities of the reversed 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< ModelBernoulli_pj< 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.
 

Additional Inherited Members

- Protected Member Functions inherited from STK::IMultiStatModel< ModelBernoulli_pj< 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< ModelBernoulli_pj< 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::ModelBernoulli_pj< Data_, WColVector_ >

A joint Bernoulli model is a statistical model of the form: following form.

\[
    f(\mathbf{x}_i = x|\theta) =
    \prod_{j=1}^p p_{j}^{x_i^j} (1-p_{j})^{1-x_i^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_ModelBernoulli_pj.h.

Member Typedef Documentation

◆ Base

◆ Data

Type of the container storing the data.

Definition at line 146 of file STK_ModelBernoulli_pj.h.

◆ RowVector

◆ Type

Type of the data in the container.

Definition at line 151 of file STK_ModelBernoulli_pj.h.

◆ WColVector

Type of the array storing the weights of the data.

Definition at line 149 of file STK_ModelBernoulli_pj.h.

Constructor & Destructor Documentation

◆ ModelBernoulli_pj() [1/4]

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

default constructor.

Definition at line 158 of file STK_ModelBernoulli_pj.h.

158: Base() {}
IMultiStatModel< ModelBernoulli_pj< Data_, WColVector_ > > Base
Base class.

◆ ModelBernoulli_pj() [2/4]

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

Constructor with data set.

Definition at line 160 of file STK_ModelBernoulli_pj.h.

160: Base(data) {}

◆ ModelBernoulli_pj() [3/4]

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

Constructor with a ptr on the data set.

Definition at line 162 of file STK_ModelBernoulli_pj.h.

◆ ModelBernoulli_pj() [4/4]

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

Copy constructor.

Definition at line 164 of file STK_ModelBernoulli_pj.h.

164: Base(model) {}

◆ ~ModelBernoulli_pj()

destructor

Definition at line 166 of file STK_ModelBernoulli_pj.h.

166{}

Member Function Documentation

◆ computeLnLikelihood()

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

compute the log Likelihood of an observation.

Definition at line 191 of file STK_ModelBernoulli_pj.h.

192{
193 Real sum =0.;
194 for (Integer j= rowData.begin(); j < rowData.end(); ++j)
195 {
196 sum += rowData[j] * lnProb()[j] + (1-rowData[j] * ln1mProb()[j] );
197 }
198 return sum;
199}
CPointX const & ln1mProb() const
vector of the log probabilities of the reversed observations
CPointX const & lnProb() const
vector of the log probabilities of the observations
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::sum().

◆ computeNbFreeParameters()

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

compute the number of free parameters

Definition at line 176 of file STK_ModelBernoulli_pj.h.

176{ return p_data()->dataij().sizeCols();}

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

◆ computeParameters() [1/2]

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

compute the parameters

Definition at line 203 of file STK_ModelBernoulli_pj.h.

204{
205 for (int j=p_data()->dataij().beginCols(); j < p_data()->dataij().endCols(); ++j)
206 {
207 Real sum=0.;
208 int nbObs=p_data()->dataij().sizeRows();
209
210 for (int i=p_data()->dataij().beginRows(); i<p_data()->dataij().endRows(); ++i)
211 { (p_data()->dataij().elt(i,j) == binaryNA_) ? --nbObs : sum += p_data()->dataij().elt(i,j);}
212 if (nbObs != 0) { param().prob_[j] = sum/nbObs;}
213 else { param().prob_[j] = Arithmetic<Real>::NA();}
214 }
215}
@ binaryNA_
Not Available value.
Definition STK_Binary.h:51
static Type NA()
Adding a Non Available (NA) special number.

References STK::binaryNA_, STK::Arithmetic< Type >::NA(), and STK::sum().

◆ computeParameters() [2/2]

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

compute the weighted parameters

Parameters
weightsthe weights of the samples

Definition at line 218 of file STK_ModelBernoulli_pj.h.

219{
220 // compute
221 for (int j=p_data()->dataij().beginCols(); j < p_data()->dataij().endCols(); ++j)
222 {
223 Real sum=0., wsum = 0.;
224 for (int i=p_data()->dataij().beginRows(); i<p_data()->dataij().endRows(); ++i)
225 { if (p_data()->dataij().elt(i,j) != binaryNA_)
226 { sum += weights[i]*p_data()->dataij().elt(i,j);
227 wsum += weights[i];
228 }
229 }
230 if (wsum != 0) { param().prob_[j] = sum/wsum;}
231 else { param().prob_[j] = Arithmetic<Real>::NA();}
232 }
233}

References STK::binaryNA_, STK::Arithmetic< Type >::NA(), and STK::sum().

◆ ln1mProb()

template<class Data_ , class WColVector_ >
CPointX const & STK::ModelBernoulli_pj< Data_, WColVector_ >::ln1mProb ( ) const
inline

vector of the log probabilities of the reversed observations

Definition at line 173 of file STK_ModelBernoulli_pj.h.

173{ return param().ln1mProb();}

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

◆ lnProb()

template<class Data_ , class WColVector_ >
CPointX const & STK::ModelBernoulli_pj< Data_, WColVector_ >::lnProb ( ) const
inline

vector of the log probabilities of the observations

Definition at line 171 of file STK_ModelBernoulli_pj.h.

171{ return param().lnProb();}

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

◆ prob()

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

Definition at line 169 of file STK_ModelBernoulli_pj.h.

169{ return param().prob();}

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

◆ writeParametersImpl()

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

Write the parameters on the output stream os.

Definition at line 237 of file STK_ModelBernoulli_pj.h.

238{
239 os << _T("prob = ") << prob();
240 os << _T("lnProb = ") << lnProb();
241 os << _T("ln1mProb = ") << ln1mProb();
242}
#define _T(x)
Let x unmodified.
CPointX const & prob() const

References _T.


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