STK++ 0.9.13
STK::GaussianModel< Array > Class Template Reference

Compute the maximum likelihood estimates of a complete Gaussian statistical model. More...

#include <STK_GaussianModel.h>

Inheritance diagram for STK::GaussianModel< Array >:
Inheritance graph

Public Types

typedef IGaussianModel< Array > Base
 
typedef hidden::Traits< Array >::Col ColVector
 
typedef hidden::Traits< Array >::Row RowVector
 
- Public Types inherited from STK::IStatModel< IGaussianModel< Array > >
typedef hidden::ModelTraits< IGaussianModel< Array > >::Data Data
 
typedef hidden::ModelTraits< IGaussianModel< Array > >::ParamHandler ParamHandler
 
typedef Data::Type Type
 Type of the data contained in the container.
 
typedef hidden::Traits< Data >::Row Row
 Type of the row of the data container (a sample)
 

Public Member Functions

 GaussianModel (Array const *p_data)
 constructor.
 
 GaussianModel (Array const &data)
 constructor.
 
 ~GaussianModel ()
 destructor.
 
MultiLaw::Normal< RowVector > *constp_law () const
 Accessor to the normal law.
 
bool run ()
 implementation of the Gaussian statistical model
 
bool run (ColVector const &weights)
 implementation of the weighted Gaussian statistical model
 
ArraySquareX constcovariance () const
 get the empirical covariance
 
- Public Member Functions inherited from STK::IGaussianModel< Array >
virtual ~IGaussianModel ()
 destructor.
 
RowVector constmean () const
 
- Public Member Functions inherited from STK::IStatModel< IGaussianModel< Array > >
 ~IStatModel ()
 destructor
 
Data const *const p_dataij () const
 
void setData (Data const &data)
 Set the data set of the model.
 
void setData (Data const *p_data)
 Set the data set of the model.
 
- 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 Attributes

RowVector mean_
 Vector of the empirical means.
 

Protected Member Functions

void compCovariance ()
 compute the empirical covariance matrix.
 
void compWeightedCovariance (ColVector const &weights)
 compute the empirical weighted covariance matrix.
 
- Protected Member Functions inherited from STK::IGaussianModel< Array >
 IGaussianModel (Array const *p_data)
 constructor.
 
 IGaussianModel (Array const &data)
 constructor.
 
void compMean ()
 compute the empirical mean
 
void compWeightedMean (ColVector const &weights)
 compute the empirical weighted mean
 
- Protected Member Functions inherited from STK::IStatModel< IGaussianModel< Array > >
 IStatModel (Data const &data)
 Constructor with data set.
 
 IStatModel (Data const *p_data)
 Constructor with a ptr on the 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 Attributes

ArraySquareX cov_
 ArrayXX of the empirical covaiance.
 
MultiLaw::Normal< RowVector > * p_law_
 pointer on the normal law
 
- Protected Attributes inherited from STK::IGaussianModel< Array >
RowVector mean_
 Vector of the empirical means.
 
- Protected Attributes inherited from STK::IStatModel< IGaussianModel< Array > >
Data constp_dataij_
 A pointer on the original data set.
 

Detailed Description

template<class Array>
class STK::GaussianModel< Array >

Compute the maximum likelihood estimates of a complete Gaussian statistical model.

Definition at line 52 of file STK_GaussianModel.h.

Member Typedef Documentation

◆ Base

template<class Array >
typedef IGaussianModel<Array> STK::GaussianModel< Array >::Base

Definition at line 55 of file STK_GaussianModel.h.

◆ ColVector

template<class Array >
typedef hidden::Traits<Array>::Col STK::GaussianModel< Array >::ColVector

Definition at line 60 of file STK_GaussianModel.h.

◆ RowVector

template<class Array >
typedef hidden::Traits<Array>::Row STK::GaussianModel< Array >::RowVector

Definition at line 61 of file STK_GaussianModel.h.

Constructor & Destructor Documentation

◆ GaussianModel() [1/2]

template<class Array >
STK::GaussianModel< Array >::GaussianModel ( Array const p_data)

constructor.

Parameters
p_datapointer on the data set

Definition at line 103 of file STK_GaussianModel.h.

104 : Base(p_dataij)
105 , cov_(p_dataij_->cols())
106 , p_law_(0)
107{
108 this->setNbFreeParameter(p_dataij_->sizeCols() + (p_dataij_->sizeCols()* (p_dataij_->sizeCols()-1))/2);
109}
IGaussianModel< Array > Base
ArraySquareX cov_
ArrayXX of the empirical covaiance.
MultiLaw::Normal< RowVector > * p_law_
pointer on the normal law
void setNbFreeParameter(int const &nbFreeParameter)
set the number of free parameters of the model
Data const * p_dataij_
A pointer on the original data set.

References STK::IStatModel< IGaussianModel< Array > >::p_dataij_, and STK::IStatModelBase::setNbFreeParameter().

◆ GaussianModel() [2/2]

template<class Array >
STK::GaussianModel< Array >::GaussianModel ( Array const data)

constructor.

Parameters
datareference on the data set

Definition at line 113 of file STK_GaussianModel.h.

114 : Base(data)
115 , cov_(data.cols())
116 , p_law_(0)
117{ setNbFreeParameter(p_dataij_->sizeCols() + (p_dataij_->sizeCols()* (p_dataij_->sizeCols()-1))/2);}

References STK::IStatModel< IGaussianModel< Array > >::p_dataij_, and STK::IStatModelBase::setNbFreeParameter().

◆ ~GaussianModel()

template<class Array >
STK::GaussianModel< Array >::~GaussianModel ( )

destructor.

Definition at line 121 of file STK_GaussianModel.h.

122{ if (p_law_) delete p_law_;}

Member Function Documentation

◆ compCovariance()

template<class Array >
void STK::GaussianModel< Array >::compCovariance ( )
protectedvirtual

compute the empirical covariance matrix.

Implements STK::IGaussianModel< Array >.

Definition at line 167 of file STK_GaussianModel.h.

Real covariance(ExprBase< XArray > const &X, ExprBase< YArray > const &Y, bool unbiased=false)
Compute the covariance of the variables X and Y.

References STK::Stat::covariance().

◆ compWeightedCovariance()

template<class Array >
void STK::GaussianModel< Array >::compWeightedCovariance ( ColVector const weights)
protectedvirtual

compute the empirical weighted covariance matrix.

Parameters
weightsthe weights of the samples

Implements STK::IGaussianModel< Array >.

Definition at line 173 of file STK_GaussianModel.h.

174{ cov_ = Stat::covariance(*p_dataij_, weights);}

References STK::Stat::covariance().

◆ covariance()

template<class Array >
ArraySquareX const & STK::GaussianModel< Array >::covariance ( ) const
inline

get the empirical covariance

Returns
the empirical covariance

Definition at line 86 of file STK_GaussianModel.h.

86{ return cov_;}

References STK::GaussianModel< Array >::cov_.

◆ p_law()

template<class Array >
MultiLaw::Normal< RowVector > *const & STK::GaussianModel< Array >::p_law ( ) const
inline

Accessor to the normal law.

Definition at line 73 of file STK_GaussianModel.h.

73{ return p_law_;}

References STK::GaussianModel< Array >::p_law_.

◆ run() [1/2]

template<class Array >
bool STK::GaussianModel< Array >::run ( )

implementation of the Gaussian statistical model

Returns
true if no error occur and false otherwise.

Definition at line 128 of file STK_GaussianModel.h.

129{
130 // compute the mean
131 this->compMean();
132 // compute the covariance matrix
134 // create p_law_ (will be deleted in base class)
135 // update gaussian law (will be deleted in base class)
136 if (!p_law_) p_law_ = new MultiLaw::Normal<RowVector>(mean_, cov_);
137 else p_law_->setParameters(mean_, cov_);
138 // compute log likelihood of the gaussian law
139 this->setLnLikelihood(p_law_->lnLikelihood(*p_dataij_ ));
140 // everything ok
141 return true;
142}
void compCovariance()
compute the empirical covariance matrix.
RowVector mean_
Vector of the empirical means.
void compMean()
compute the empirical mean
void setLnLikelihood(Real const &lnLikelihood)
set the log-likelihood of the model

◆ run() [2/2]

template<class Array >
bool STK::GaussianModel< Array >::run ( ColVector const weights)

implementation of the weighted Gaussian statistical model

Parameters
weightsthe weights of the samples
Returns
true if no error occur and false otherwise.

Definition at line 149 of file STK_GaussianModel.h.

150{
151 // compute the mean
152 this->compWeightedMean(weights);
153 // compute the covariance matrix
154 compWeightedCovariance(weights);
155 // create p_law_ (will be deleted in base class)
156 // update gaussian law (will be deleted in base class)
157 if (!p_law_) p_law_ = new MultiLaw::Normal<RowVector>(mean_, cov_);
158 else p_law_->setParameters(mean_, cov_);
159 // compute log likelihood of the gaussian law
160 this->setLnLikelihood(p_law_->lnLikelihood(*p_dataij_ ));
161 // everything ok
162 return true;
163}
void compWeightedCovariance(ColVector const &weights)
compute the empirical weighted covariance matrix.
void compWeightedMean(ColVector const &weights)
compute the empirical weighted mean

Member Data Documentation

◆ cov_

template<class Array >
ArraySquareX STK::GaussianModel< Array >::cov_
protected

ArrayXX of the empirical covaiance.

Definition at line 90 of file STK_GaussianModel.h.

Referenced by STK::GaussianModel< Array >::covariance().

◆ mean_

template<class Array >
RowVector STK::IGaussianModel< Array >::mean_

Vector of the empirical means.

Definition at line 176 of file STK_IGaussianModel.h.

◆ p_law_

template<class Array >
MultiLaw::Normal<RowVector>* STK::GaussianModel< Array >::p_law_
protected

pointer on the normal law

Definition at line 98 of file STK_GaussianModel.h.

Referenced by STK::GaussianModel< Array >::p_law().


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