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

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

#include <STK_BernoulliModel.h>

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

Public Types

typedef Array::Type Type
 Type of the data contained in the container.
 
typedef IUnivStatModel< Array, WColVector, Law::BernoulliBase
 Base class.
 
- Public Types inherited from STK::IUnivStatModel< Array, WColVector, Law::Bernoulli >
typedef ColVector::Type Type
 Type of the data contained in the container.
 
typedef IRunnerUnsupervised< Array, WColVector > Runner
 Type of the Runner.
 

Public Member Functions

 BernoulliModel ()
 default constructor.
 
 BernoulliModel (Array const &data)
 Constructor with data set.
 
 BernoulliModel (Array const *p_data)
 Constructor with a ptr on the data set.
 
 BernoulliModel (BernoulliModel const &model)
 Copy constructor.
 
BernoulliModelclone () const
 clone patern
 
virtual ~BernoulliModel ()
 destructor
 
virtual int computeNbFreeParameters () const
 compute the number of free parameters
 
- Public Member Functions inherited from STK::IUnivStatModel< Array, WColVector, Law::Bernoulli >
virtual ~IUnivStatModel ()
 destructor
 
Real computeLnLikelihood () const
 compute the log Likelihood of the statistical model.
 
Law::Bernoulli constlaw () const
 
virtual bool run ()
 Estimate the parameters of the model and update the.
 
virtual bool run (WColVector const &weights)
 compute the weighted empirical probability of success based on the observed variables.
 
- 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::IRunnerUnsupervised< Array, Weights_ >
Array constp_data () const
 get the data set
 
virtual void setData (Array const *p_data)
 Set the data set.
 
virtual void setData (Array const &data)
 Set the data set.
 
virtual bool run (Weights_ const &weights)=0
 run the weighted computations.
 
- Public Member Functions inherited from STK::IRunnerBase
String consterror () const
 get the last error message.
 

Protected Member Functions

virtual void computeParameters ()
 compute the empirical probability of success based on the observed variables.
 
virtual void computeParameters (WColVector const &weights)
 compute the weighted empirical probability of success based on the observed variables.
 
- Protected Member Functions inherited from STK::IUnivStatModel< Array, WColVector, Law::Bernoulli >
 IUnivStatModel ()
 default constructor.
 
 IUnivStatModel (Array const &data)
 Constructor with data set.
 
 IUnivStatModel (Array const *p_data)
 Constructor with a ptr on the data set.
 
 IUnivStatModel (IUnivStatModel const &model)
 Copy constructor.
 
virtual void update ()
 This virtual method will be called if the user set a new data 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::IRunnerUnsupervised< Array, Weights_ >
 IRunnerUnsupervised ()
 default constructor.
 
 IRunnerUnsupervised (Array const *const p_data)
 constructor with a pointer on the constant data set
 
 IRunnerUnsupervised (Array const &data)
 constructor with a constant reference on the data set
 
 IRunnerUnsupervised (IRunnerUnsupervised const &runner)
 copy constructor
 
 ~IRunnerUnsupervised ()
 destructor
 
- Protected Member Functions inherited from STK::IRunnerBase
 IRunnerBase ()
 default constructor
 
 IRunnerBase (IRunnerBase const &runner)
 copy constructor
 
virtual ~IRunnerBase ()
 destructor
 

Additional Inherited Members

- Protected Attributes inherited from STK::IUnivStatModel< Array, WColVector, Law::Bernoulli >
Law::Bernoulli law_
 The probability law of the model.
 
- Protected Attributes inherited from STK::IRunnerUnsupervised< Array, Weights_ >
Array constp_data_
 A pointer on the original data set.
 
- Protected Attributes inherited from STK::IRunnerBase
String msg_error_
 String with the last error message.
 
bool hasRun_
 true if run has been used, false otherwise
 

Detailed Description

template<class Array, class WColVector>
class STK::BernoulliModel< Array, WColVector >

A Bernoulli model, is a statistical model of the following form.

\[
    f(x_i = x|\theta) =
      p^{x_i} (1-p)^{1-x_i}, \quad x_i\in\{0,1\}, \quad i=1\ldots,n.
\]

Definition at line 57 of file STK_BernoulliModel.h.

Member Typedef Documentation

◆ Base

template<class Array , class WColVector >
typedef IUnivStatModel<Array, WColVector, Law::Bernoulli> STK::BernoulliModel< Array, WColVector >::Base

Base class.

Definition at line 65 of file STK_BernoulliModel.h.

◆ Type

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

Type of the data contained in the container.

Definition at line 63 of file STK_BernoulliModel.h.

Constructor & Destructor Documentation

◆ BernoulliModel() [1/4]

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

default constructor.

Definition at line 67 of file STK_BernoulliModel.h.

67: Base() {}
IUnivStatModel< Array, WColVector, Law::Bernoulli > Base
Base class.

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

◆ BernoulliModel() [2/4]

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

Constructor with data set.

Definition at line 69 of file STK_BernoulliModel.h.

69: Base(data) {}

◆ BernoulliModel() [3/4]

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

Constructor with a ptr on the data set.

Definition at line 71 of file STK_BernoulliModel.h.

71: Base(p_data) {}
Array const * p_data() const
get the data set

◆ BernoulliModel() [4/4]

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

Copy constructor.

Definition at line 73 of file STK_BernoulliModel.h.

73: Base(model) {}

◆ ~BernoulliModel()

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

destructor

Definition at line 77 of file STK_BernoulliModel.h.

77{}

Member Function Documentation

◆ clone()

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

clone patern

Definition at line 75 of file STK_BernoulliModel.h.

75{ return new BernoulliModel(*this);}
BernoulliModel()
default constructor.

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

◆ computeNbFreeParameters()

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

compute the number of free parameters

Implements STK::IUnivStatModel< Array, WColVector, Law::Bernoulli >.

Definition at line 79 of file STK_BernoulliModel.h.

79{ return 1;}

◆ computeParameters() [1/2]

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

compute the empirical probability of success based on the observed variables.

The NA values are discarded.

Implements STK::IUnivStatModel< Array, WColVector, Law::Bernoulli >.

Definition at line 85 of file STK_BernoulliModel.h.

86 {
87 Real sum=0.;
88 int nbObs=p_data()->size();
89 for (int i=p_data()->begin(); i<=p_data()->lastIdx(); ++i)
90 { (p_data()->elt(i) == binaryNA_) ? --nbObs : sum += p_data()->elt(i);}
91 if (nbObs != 0) { this->law_.setProb(sum/nbObs);}
92 else { this->law_.setProb(0.);}
93 }
Law::Bernoulli law_
The probability law of the model.
void setProb(Real const &prob)
Arrays::SumOp< Lhs, Rhs >::result_type sum(Lhs const &lhs, Rhs const &rhs)
convenience function for summing two arrays
@ binaryNA_
Not Available value.
Definition STK_Binary.h:51
double Real
STK fundamental type of Real values.

References STK::binaryNA_, STK::IUnivStatModel< Array, WColVector, Law::Bernoulli >::law_, STK::IRunnerUnsupervised< Array, Weights_ >::p_data(), STK::Law::Bernoulli::setProb(), and STK::sum().

◆ computeParameters() [2/2]

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

compute the weighted empirical probability of success based on the observed variables.

The NA values are discarded.

Implements STK::IUnivStatModel< Array, WColVector, Law::Bernoulli >.

Definition at line 97 of file STK_BernoulliModel.h.

98 {
99 Real sum=0.;
100 int nbObs=p_data()->size();
101 for (int i=p_data()->begin(); i<=p_data()->lastIdx(); ++i)
102 { (p_data()->elt(i) == binaryNA_) ? --nbObs : sum += weights[i]*p_data()->elt(i);}
103 if (nbObs != 0) { this->law_.setProb(sum/nbObs);}
104 else { this->law_.setProb(0.);}
105 }

References STK::binaryNA_, STK::IUnivStatModel< Array, WColVector, Law::Bernoulli >::law_, STK::IRunnerUnsupervised< Array, Weights_ >::p_data(), STK::Law::Bernoulli::setProb(), and STK::sum().


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