STK++ 0.9.13
STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw > Class Template Referenceabstract

Base class for all Statistical Models. More...

#include <STK_IUnivStatModel.h>

Inheritance diagram for STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >:
Inheritance graph

Public Types

typedef ColVector::Type Type
 Type of the data contained in the container.
 
typedef IRunnerUnsupervised< ColVector, WColVector > Runner
 Type of the Runner.
 

Public Member Functions

virtual ~IUnivStatModel ()
 destructor
 
Real computeLnLikelihood () const
 compute the log Likelihood of the statistical model.
 
UnivariateLaw constlaw () const
 
virtual int computeNbFreeParameters () const =0
 compute the number of free parameters
 
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< ColVector, WColVector >
ColVector constp_data () const
 get the data set
 
virtual void setData (ColVector const *p_data)
 Set the data set.
 
virtual void setData (ColVector const &data)
 Set the data set.
 
- Public Member Functions inherited from STK::IRunnerBase
String consterror () const
 get the last error message.
 

Protected Member Functions

 IUnivStatModel ()
 default constructor.
 
 IUnivStatModel (ColVector const &data)
 Constructor with data set.
 
 IUnivStatModel (ColVector 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.
 
virtual void computeParameters ()=0
 compute the parameters
 
virtual void computeParameters (WColVector const &weights)=0
 compute the weighted parameters
 
- 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< ColVector, WColVector >
 IRunnerUnsupervised ()
 default constructor.
 
 IRunnerUnsupervised (ColVector const *const p_data)
 constructor with a pointer on the constant data set
 
 IRunnerUnsupervised (ColVector 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
 

Protected Attributes

UnivariateLaw law_
 The probability law of the model.
 
- Protected Attributes inherited from STK::IRunnerUnsupervised< ColVector, WColVector >
ColVector 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 ColVector, class WColVector, class UnivariateLaw>
class STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >

Base class for all Statistical Models.

A Statistical model, $ \mathcal{P}$, is a collection of probability distribution functions or probability density functions (collectively referred to as ''distributions'' for brevity). A parametric model is a collection of distributions, each of which is indexed by a unique finite-dimensional parameter: $\mathcal{P}=\{\mathbb{P}_{\theta} : \theta \in \Theta\}$, where $\theta$ is a parameter and $\Theta \subseteq \mathbb{R}^d$ is the feasible region of parameters, which is a subset of d-dimensional Euclidean space. A statistical model may be used to describe the set of distributions from which one assumes that a particular data set is sampled. For example, if one assumes that data arise from a univariate Gaussian distribution, then one has assumed a Gaussian model: $
  \mathcal{P}=\{\mathbb{P}(x; \mu, \sigma) = \frac{1}{\sqrt{2 \pi} \sigma}
  \exp\left\{ -\frac{1}{2\sigma^2}(x-\mu)^2\right\} : \mu \in \mathbb{R}, \sigma > 0\}
$.

From a computational point of view a statistical model is defined with the help of two elements

  • A data set where the number of samples is the number of rows. This data set is stored in a Container of type ColVector.
  • A probability (density/law) which for each row of the data set can compute a density/probability.

The parameters of the distribution (if any) are directly managed by the probability law.

Further implementation of this interface have to implement the run() and the run(weights) methods in order to estimate the parameters of the univariate law.

Template Parameters
ColVectorcan be any kind of vector for the data set. it should at least derive from the specialization of ITContainer for Arrays::vector_,
See also
ITContainer.
Template Parameters
UnivariateLawany probabilistic law deriving from the interface class IUnivLaw,
See also
IUnivLaw.

Definition at line 86 of file STK_IUnivStatModel.h.

Member Typedef Documentation

◆ Runner

template<class ColVector , class WColVector , class UnivariateLaw >
typedef IRunnerUnsupervised<ColVector, WColVector> STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::Runner

Type of the Runner.

Definition at line 93 of file STK_IUnivStatModel.h.

◆ Type

template<class ColVector , class WColVector , class UnivariateLaw >
typedef ColVector::Type STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::Type

Type of the data contained in the container.

Definition at line 91 of file STK_IUnivStatModel.h.

Constructor & Destructor Documentation

◆ IUnivStatModel() [1/4]

template<class ColVector , class WColVector , class UnivariateLaw >
STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::IUnivStatModel ( )
inlineprotected

default constructor.

Definition at line 97 of file STK_IUnivStatModel.h.

97: IStatModelBase(), Runner() {}
IStatModelBase()
Default constructor.
IRunnerUnsupervised< ColVector, WColVector > Runner
Type of the Runner.

◆ IUnivStatModel() [2/4]

template<class ColVector , class WColVector , class UnivariateLaw >
STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::IUnivStatModel ( ColVector const data)
inlineprotected

Constructor with data set.

Definition at line 99 of file STK_IUnivStatModel.h.

99 : IStatModelBase(data.size(), 1), Runner(data)
100 { this->initialize(data.size(), 1);}
void initialize(int nbSample, int nbVariable)
set the dimensions of the parameters of the model

References STK::IStatModelBase::initialize().

◆ IUnivStatModel() [3/4]

template<class ColVector , class WColVector , class UnivariateLaw >
STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::IUnivStatModel ( ColVector const p_data)
inlineprotected

Constructor with a ptr on the data set.

Definition at line 102 of file STK_IUnivStatModel.h.

103 { if (p_data) this->initialize(p_data->size(), 1) ;}
ColVector const * p_data() const
get the data set

References STK::IStatModelBase::initialize(), and STK::IRunnerUnsupervised< ColVector, WColVector >::p_data().

◆ IUnivStatModel() [4/4]

template<class ColVector , class WColVector , class UnivariateLaw >
STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::IUnivStatModel ( IUnivStatModel< ColVector, WColVector, UnivariateLaw > const model)
inlineprotected

Copy constructor.

Definition at line 105 of file STK_IUnivStatModel.h.

106 : IStatModelBase(model), Runner(model), law_(model.law_) {}
UnivariateLaw law_
The probability law of the model.

◆ ~IUnivStatModel()

template<class ColVector , class WColVector , class UnivariateLaw >
virtual STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::~IUnivStatModel ( )
inlinevirtual

destructor

Definition at line 110 of file STK_IUnivStatModel.h.

110{}

Member Function Documentation

◆ computeLnLikelihood()

template<class ColVector , class WColVector , class UnivariateLaw >
Real STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::computeLnLikelihood ( ) const
inline

compute the log Likelihood of the statistical model.

Definition at line 112 of file STK_IUnivStatModel.h.

113 {
114 Real sum = 0.0;
115 for (int i= p_data()->begin(); i<= p_data()->lastIdx(); i++)
116 { if (!Arithmetic<Type>::isNA(p_data()->elt(i))) sum += law_.lpdf(p_data()->elt(i));}
117 return sum;
118 }
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.
static bool isNA(Type const &x)

References STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::law_, STK::IRunnerUnsupervised< ColVector, WColVector >::p_data(), and STK::sum().

Referenced by STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::run(), and STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::run().

◆ computeNbFreeParameters()

template<class ColVector , class WColVector , class UnivariateLaw >
virtual int STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::computeNbFreeParameters ( ) const
pure virtual

◆ computeParameters() [1/2]

template<class ColVector , class WColVector , class UnivariateLaw >
virtual void STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::computeParameters ( )
protectedpure virtual

◆ computeParameters() [2/2]

template<class ColVector , class WColVector , class UnivariateLaw >
virtual void STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::computeParameters ( WColVector const weights)
protectedpure virtual

compute the weighted parameters

Implemented in STK::BernoulliModel< Array, WColVector >.

◆ law()

template<class ColVector , class WColVector , class UnivariateLaw >
UnivariateLaw const & STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::law ( ) const
inline
Returns
the total available observations

Definition at line 120 of file STK_IUnivStatModel.h.

120{ return law_;}

References STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::law_.

◆ run() [1/2]

template<class ColVector , class WColVector , class UnivariateLaw >
virtual bool STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::run ( )
inlinevirtual

Estimate the parameters of the model and update the.

Implements STK::IRunnerUnsupervised< ColVector, WColVector >.

Definition at line 125 of file STK_IUnivStatModel.h.

126 {
127 if (!p_data())
128 { this->msg_error_ = STKERROR_NO_ARG(IUnivStatModel::run(),data have not be set);
129 return false;
130 }
131 try
132 {
133 // compute weighted parameters
135 // compute log-likelihood
137 // set the number of free parameters
139 }
140 catch (Exception const& e)
141 { this->msg_error_ = e.error(); return false;}
142 return true;
143 }
#define STKERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:49
String msg_error_
String with the last error message.
Definition STK_IRunner.h:96
void setNbFreeParameter(int const &nbFreeParameter)
set the number of free parameters of the model
void setLnLikelihood(Real const &lnLikelihood)
set the log-likelihood of the model
Real computeLnLikelihood() const
compute the log Likelihood of the statistical model.
virtual bool run()
Estimate the parameters of the model and update the.
virtual int computeNbFreeParameters() const =0
compute the number of free parameters
virtual void computeParameters()=0
compute the parameters

References STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::computeLnLikelihood(), STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::computeNbFreeParameters(), STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::computeParameters(), STK::Exception::error(), STK::IRunnerBase::msg_error_, STK::IRunnerUnsupervised< ColVector, WColVector >::p_data(), STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::run(), STK::IStatModelBase::setLnLikelihood(), STK::IStatModelBase::setNbFreeParameter(), and STKERROR_NO_ARG.

Referenced by STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::run(), and STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::run().

◆ run() [2/2]

template<class ColVector , class WColVector , class UnivariateLaw >
virtual bool STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::run ( WColVector const weights)
inlinevirtual

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

The NA values are discarded.

Parameters
weightsthe weights of the observations

Implements STK::IRunnerUnsupervised< ColVector, WColVector >.

Definition at line 148 of file STK_IUnivStatModel.h.

149 {
150 if (!p_data())
151 { this->msg_error_ = STKERROR_NO_ARG(IUnivStatModel::run(weights),data have not be set);
152 return false;
153 }
154 try
155 {
156 // compute weighted parameters
157 computeParameters(weights);
158 // compute log-likelihood
160 // set the number of free parameters
162 }
163 catch (Exception const& e)
164 { this->msg_error_ = e.error(); return false;}
165 return true;
166 }

References STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::computeLnLikelihood(), STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::computeNbFreeParameters(), STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::computeParameters(), STK::Exception::error(), STK::IRunnerBase::msg_error_, STK::IRunnerUnsupervised< ColVector, WColVector >::p_data(), STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::run(), STK::IStatModelBase::setLnLikelihood(), STK::IStatModelBase::setNbFreeParameter(), and STKERROR_NO_ARG.

◆ update()

template<class ColVector , class WColVector , class UnivariateLaw >
virtual void STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::update ( )
inlineprotectedvirtual

This virtual method will be called if the user set a new data set.

See also
IRunnerUnsupervised::setData

Reimplemented from STK::IRunnerBase.

Definition at line 171 of file STK_IUnivStatModel.h.

172 { if (p_data()) this->initialize(p_data()->size(), 1); }

References STK::IStatModelBase::initialize(), and STK::IRunnerUnsupervised< ColVector, WColVector >::p_data().

Member Data Documentation

◆ law_

template<class ColVector , class WColVector , class UnivariateLaw >
UnivariateLaw STK::IUnivStatModel< ColVector, WColVector, UnivariateLaw >::law_
protected

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