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

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

#include <STK_JointBernoulliModel.h>

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

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

Public Member Functions

 JointBernoulliModel ()
 default constructor.
 
 JointBernoulliModel (Array const &data)
 Constructor with data set.
 
 JointBernoulliModel (Array const *p_data)
 Constructor with a ptr on the data set.
 
 JointBernoulliModel (JointBernoulliModel const &model)
 Copy constructor.
 
virtual ~JointBernoulliModel ()
 destructor
 
JointBernoulliModelclone () const
 clone pattern.
 
virtual int computeNbFreeParameters () const
 compute the number of free parameters
 
virtual Real computeLnLikelihood (RowVector const &rowData) const
 compute the log Likelihood of an observation.
 
Data const *const p_data () const
 
- Public Member Functions inherited from STK::IMultiStatModel< Derived >
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< Derived >
 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.
 

Additional Inherited Members

- Protected Attributes inherited from STK::IMultiStatModel< Derived >
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 = CVectorX>
class STK::JointBernoulliModel< Array, 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 105 of file STK_JointBernoulliModel.h.

Member Typedef Documentation

◆ Base

Base class.

Definition at line 115 of file STK_JointBernoulliModel.h.

◆ ColVector

template<class Array , class WColVector = CVectorX>
typedef hidden::Traits<Array>::Col STK::JointBernoulliModel< Array, WColVector >::ColVector

Type of the column vector of the container.

Definition at line 113 of file STK_JointBernoulliModel.h.

◆ RowVector

template<class Array , class WColVector = CVectorX>
typedef hidden::Traits<Array>::Row STK::JointBernoulliModel< Array, WColVector >::RowVector

Type of the row vector of the container.

Definition at line 111 of file STK_JointBernoulliModel.h.

◆ Type

template<class Array , class WColVector = CVectorX>
typedef Array::Type STK::JointBernoulliModel< Array, WColVector >::Type

Type of the data contained in the container.

Definition at line 109 of file STK_JointBernoulliModel.h.

Constructor & Destructor Documentation

◆ JointBernoulliModel() [1/4]

template<class Array , class WColVector = CVectorX>
STK::JointBernoulliModel< Array, WColVector >::JointBernoulliModel ( )
inline

default constructor.

Definition at line 119 of file STK_JointBernoulliModel.h.

119: Base() {}
IMultiStatModel< Array, WColVector, JointBernoulliParameters > Base
Base class.

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

◆ JointBernoulliModel() [2/4]

template<class Array , class WColVector = CVectorX>
STK::JointBernoulliModel< Array, WColVector >::JointBernoulliModel ( Array const data)
inline

Constructor with data set.

Definition at line 121 of file STK_JointBernoulliModel.h.

121: Base(data) {}

◆ JointBernoulliModel() [3/4]

template<class Array , class WColVector = CVectorX>
STK::JointBernoulliModel< Array, WColVector >::JointBernoulliModel ( Array const p_data)
inline

Constructor with a ptr on the data set.

Definition at line 123 of file STK_JointBernoulliModel.h.

123: Base(p_data) {}
Data const *const p_data() const

◆ JointBernoulliModel() [4/4]

template<class Array , class WColVector = CVectorX>
STK::JointBernoulliModel< Array, WColVector >::JointBernoulliModel ( JointBernoulliModel< Array, WColVector > const model)
inline

Copy constructor.

Definition at line 125 of file STK_JointBernoulliModel.h.

125: Base(model) {}

◆ ~JointBernoulliModel()

template<class Array , class WColVector = CVectorX>
virtual STK::JointBernoulliModel< Array, WColVector >::~JointBernoulliModel ( )
inlinevirtual

destructor

Definition at line 127 of file STK_JointBernoulliModel.h.

127{}

Member Function Documentation

◆ clone()

template<class Array , class WColVector = CVectorX>
JointBernoulliModel * STK::JointBernoulliModel< Array, WColVector >::clone ( ) const
inline

clone pattern.

Returns
a clone of this.

Definition at line 129 of file STK_JointBernoulliModel.h.

129{ return new JointBernoulliModel(*this);}
JointBernoulliModel()
default constructor.

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

◆ computeLnLikelihood()

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

compute the log Likelihood of an observation.

Definition at line 135 of file STK_JointBernoulliModel.h.

136 {
137 Real sum =0.;
138 for (Integer j= rowData.begin(); j < rowData.end(); ++j)
139 {
140 sum += rowData[j] * p_param()->lnProb(j)
141 + (1-rowData[j] * p_param()->ln1mProb(j) );
142 }
143 return sum;
144 }
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 Array , class WColVector = CVectorX>
virtual int STK::JointBernoulliModel< Array, WColVector >::computeNbFreeParameters ( ) const
inlinevirtual

compute the number of free parameters

Definition at line 132 of file STK_JointBernoulliModel.h.

133 { return p_data()->sizeCols();}

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

◆ computeParameters() [1/2]

template<class Array , class WColVector = CVectorX>
virtual void STK::JointBernoulliModel< Array, WColVector >::computeParameters ( )
inlineprotectedvirtual

compute the parameters

Definition at line 147 of file STK_JointBernoulliModel.h.

148 {
149 for (int j=p_data()->beginCols(); j < p_data()->endCols(); ++j)
150 {
151 Real sum=0.;
152 int nbObs=p_data()->sizeRows();
153
154 for (int i=p_data()->beginRows(); i<=p_data()->lastIdxRows(); ++i)
155 { (p_data()->elt(i,j) == binaryNA_) ? --nbObs : sum += p_data()->elt(i,j);}
156 if (nbObs != 0) { p_param()->setProb(j,sum/nbObs);}
157 else { p_param()->setProb(j, Arithmetic<Real>::NA());}
158 }
159 }
@ binaryNA_
Not Available value.
Definition STK_Binary.h:51
static Type NA()
Adding a Non Available (NA) special number.

References STK::binaryNA_, STK::JointBernoulliModel< Array, WColVector >::p_data(), and STK::sum().

◆ computeParameters() [2/2]

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

compute the weighted parameters

Parameters
weightsthe weights of the samples

Definition at line 163 of file STK_JointBernoulliModel.h.

164 {
165 // compute
166 for (int j=p_data()->beginCols(); j < p_data()->endCols(); ++j)
167 {
168 Real sum=0., wsum = 0.;
169 for (int i=p_data()->beginRows(); i<=p_data()->lastIdxRows(); ++i)
170 { if (p_data()->elt(i,j) != binaryNA_)
171 { sum += weights[i]*p_data()->elt(i,j);
172 wsum += weights[i];
173 }
174 }
175 if (wsum != 0) { p_param()->setProb(j, sum/wsum);}
176 else { p_param()->setProb(j, Arithmetic<Real>::NA());}
177 }
178 }

References STK::binaryNA_, STK::JointBernoulliModel< Array, WColVector >::p_data(), and STK::sum().

◆ p_data()

template<class Array , class WColVector = CVectorX>
Data const *const STK::IMultiStatModel< Derived >::p_data ( ) const
inline

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