|
STK++ 1.0
|
Compute the the maximum likelihood estimates of a Gaussian statistical model. More...
#include <STK_GaussianStatModel.h>

Public Member Functions | |
| GaussianStatModel (Matrix const *p_data) | |
| constructor. | |
| virtual | ~GaussianStatModel () |
| destructor. | |
| virtual bool | run () |
| implementation of the Gaussian statistical model | |
| virtual bool | run (Vector const &weights) |
| implementation of the weighted Gaussian statistical model | |
| Point const & | mean () const |
| get the empirical mean. | |
| MatrixSquare const & | covariance () const |
| get the empirical covariance | |
Protected Member Functions | |
| virtual void | compMean () |
| compute the empirical mean | |
| virtual void | compCovariance () |
| compute the empirical covariance matrix. | |
| virtual void | compWeightedMean (Vector const &weights) |
| compute the empirical weighted mean | |
| virtual void | compWeightedCovariance (Vector const &weights) |
| compute the empirical weighted covariance matrix. | |
Protected Attributes | |
| Point | mean_ |
| Vector of the empirical means. | |
| MatrixSquare | cov_ |
| Matrix of the empirical covaiance. | |
Private Types | |
| typedef ITStatModel< Real, Point, Vector, Matrix > | RealStatModel |
Compute the the maximum likelihood estimates of a Gaussian statistical model.
A random vector
is Gaussian if
The likelihood function of a gaussian sample is:
The maximum likelihood estimator can be performed via matrix calculus formulae Re-write the likelihood in the log form using the trace trick:
The differential of this log-likelihood is
It naturally breaks down into the part related to the estimation of the mean, and to the part related to the estimation of the variance. The first order condition for maximum,
, is satisfied when the terms multiplying
and
are identically zero. Assuming (the maximum likelihood estimate of)
is non-singular, the first order condition for the estimate of the mean vector is
which leads to the maximum likelihood estimator
This lets us simplify
. Then the terms involving
in
can be combined as
The first order condition
will hold when the term in the square bracket is (matrix-valued) zero. Pre-multiplying the latter by
and dividing by
gives
Definition at line 103 of file STK_GaussianStatModel.h.
typedef ITStatModel<Real, Point, Vector, Matrix> STK::GaussianStatModel::RealStatModel [private] |
Definition at line 105 of file STK_GaussianStatModel.h.
| STK::GaussianStatModel::GaussianStatModel | ( | Matrix const * | p_data | ) |
constructor.
| p_data | pointer on the data set |
Definition at line 47 of file STK_GaussianStatModel.cpp.
References STK::IStatModelBase::nbFreeParameter_, and STK::IStatModelBase::nbVar_.
| STK::GaussianStatModel::~GaussianStatModel | ( | ) | [virtual] |
| bool STK::GaussianStatModel::run | ( | ) | [virtual] |
implementation of the Gaussian statistical model
true if no error occur and false otherwise. Implements STK::IRunnerBase.
Definition at line 61 of file STK_GaussianStatModel.cpp.
References compCovariance(), compMean(), cov_, STK::IStatModelBase::logLikelihood_, mean_, STK::IRunnerPtr2D< Real, Point, Vector, Matrix >::p_data_, STK::ITStatModel< Real, Point, Vector, Matrix >::p_law_, and STK::Law::ILawBase::update().
Referenced by STK::Gaussian2BlocksStatModel::run().
{
// compute the mean
compMean();
// compute the covariance matrix
compCovariance();
// create p_law_ (will be deleted in base class)
// update gaussian law (will be deleted in base class)
if (!p_law_) p_law_ = new Law::MultivariateNormal<Point>(mean_, cov_);
else p_law_->update();
// compute log likelihood of the gaussian law
logLikelihood_ = static_cast<Law::MultivariateNormal<Point>* >(p_law_)->logLikelihood<Vector, Matrix>(*p_data_ );
// everything ok
return true;
}
| bool STK::GaussianStatModel::run | ( | Vector const & | weights | ) | [virtual] |
implementation of the weighted Gaussian statistical model
| weights | the weights of the samples |
true if no error occur and false otherwise. Implements STK::IRunnerPtr2D< Real, Point, Vector, Matrix >.
Definition at line 81 of file STK_GaussianStatModel.cpp.
References compWeightedCovariance(), compWeightedMean(), cov_, STK::IStatModelBase::logLikelihood_, mean_, STK::IRunnerPtr2D< Real, Point, Vector, Matrix >::p_data_, STK::ITStatModel< Real, Point, Vector, Matrix >::p_law_, and STK::Law::ILawBase::update().
{
// compute the mean
compWeightedMean(weights);
// compute the covariance matrix
compWeightedCovariance(weights);
// create p_law_ (will be deleted in base class)
// update gaussian law (will be deleted in base class)
if (!p_law_) p_law_ = new Law::MultivariateNormal<Point>(mean_, cov_);
else p_law_->update();
// compute log likelihood of the gaussian law
logLikelihood_ = static_cast<Law::MultivariateNormal<Point>* >(p_law_)->logLikelihood<Vector, Matrix>(*p_data_ );
// everything ok
return true;
}
| Point const& STK::GaussianStatModel::mean | ( | ) | const [inline] |
get the empirical mean.
Definition at line 130 of file STK_GaussianStatModel.h.
References mean_.
{ return mean_;}
| MatrixSquare const& STK::GaussianStatModel::covariance | ( | ) | const [inline] |
get the empirical covariance
Definition at line 134 of file STK_GaussianStatModel.h.
References cov_.
{ return cov_;}
| void STK::GaussianStatModel::compMean | ( | ) | [protected, virtual] |
compute the empirical mean
Definition at line 98 of file STK_GaussianStatModel.cpp.
References STK::ITContainer2D< TYPE, TContainerHo, TContainerVe, TContainer2D >::col(), STK::IContainer2D::firstCol(), STK::IContainer2D::lastCol(), mean_, STK::IRunnerPtr2D< Real, Point, Vector, Matrix >::p_data_, STK::IContainer2D::rangeHo(), and STK::IContainer1D::resize().
Referenced by run().
| void STK::GaussianStatModel::compCovariance | ( | ) | [protected, virtual] |
compute the empirical covariance matrix.
Reimplemented in STK::Gaussian2BlocksStatModel.
Definition at line 110 of file STK_GaussianStatModel.cpp.
References STK::ITContainer2D< TYPE, TContainerHo, TContainerVe, TContainer2D >::col(), cov_, STK::IContainer2D::firstCol(), STK::IContainer2D::lastCol(), mean_, STK::IRunnerPtr2D< Real, Point, Vector, Matrix >::p_data_, STK::IContainer2D::rangeHo(), and STK::MatrixSquare::resize().
Referenced by run().
{
// resize mean
cov_.resize(p_data_->rangeHo());
// get dimensions
const Integer first = p_data_->firstCol(), last = p_data_->lastCol();
for (Integer i= first; i <= last; ++i)
{
cov_(i, i) = Stat::varianceWithFixedMean<Vector>(p_data_->col(i), mean_[i]);
for (Integer j= first; j < i; ++j)
{
cov_(i, j) = Stat::covarianceWithFixedMean<Vector>(p_data_->col(i), p_data_->col(j), mean_[i], mean_[j]);
cov_(j, i) = cov_(i,j);
}
}
}
| void STK::GaussianStatModel::compWeightedMean | ( | Vector const & | weights | ) | [protected, virtual] |
compute the empirical weighted mean
| weights | the weights of the samples |
Definition at line 128 of file STK_GaussianStatModel.cpp.
References STK::ITContainer2D< TYPE, TContainerHo, TContainerVe, TContainer2D >::col(), STK::IContainer2D::firstCol(), STK::IContainer2D::lastCol(), mean_, STK::IRunnerPtr2D< Real, Point, Vector, Matrix >::p_data_, STK::IContainer2D::rangeHo(), and STK::IContainer1D::resize().
Referenced by run().
| void STK::GaussianStatModel::compWeightedCovariance | ( | Vector const & | weights | ) | [protected, virtual] |
compute the empirical weighted covariance matrix.
| weights | the weights of the samples |
Reimplemented in STK::Gaussian2BlocksStatModel.
Definition at line 140 of file STK_GaussianStatModel.cpp.
References STK::ITContainer2D< TYPE, TContainerHo, TContainerVe, TContainer2D >::col(), cov_, STK::IContainer2D::firstCol(), STK::IContainer2D::lastCol(), mean_, STK::IRunnerPtr2D< Real, Point, Vector, Matrix >::p_data_, STK::IContainer2D::rangeHo(), and STK::MatrixSquare::resize().
Referenced by run().
{
// resize mean
cov_.resize(p_data_->rangeHo());
// get dimensions
const Integer first = p_data_->firstCol(), last = p_data_->lastCol();
for (Integer i= first; i <= last; ++i)
{
cov_(i, i) = Stat::varianceWithFixedMean<Vector>(p_data_->col(i), weights, mean_[i]);
for (Integer j= first; j < i; ++j)
{
cov_(i, j) = Stat::covarianceWithFixedMean<Vector>(p_data_->col(i), p_data_->col(j), weights, mean_[i], mean_[j]);
cov_(j, i) = cov_(i,j);
}
}
}
Point STK::GaussianStatModel::mean_ [protected] |
Vector of the empirical means.
Definition at line 150 of file STK_GaussianStatModel.h.
Referenced by compCovariance(), STK::Gaussian2BlocksStatModel::compCovariance(), compMean(), compWeightedCovariance(), STK::Gaussian2BlocksStatModel::compWeightedCovariance(), compWeightedMean(), mean(), and run().
MatrixSquare STK::GaussianStatModel::cov_ [protected] |
Matrix of the empirical covaiance.
Definition at line 152 of file STK_GaussianStatModel.h.
Referenced by compCovariance(), STK::Gaussian2BlocksStatModel::compCovariance(), compWeightedCovariance(), STK::Gaussian2BlocksStatModel::compWeightedCovariance(), covariance(), and run().