STK++ 0.9.13
STK_IGaussianModel.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------*/
2/* Copyright (C) 2004-2016 Serge Iovleff, Université Lille 1, Inria
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program; if not, write to the
16 Free Software Foundation, Inc.,
17 59 Temple Place,
18 Suite 330,
19 Boston, MA 02111-1307
20 USA
21
22 Contact : S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
23 */
24
25/*
26 * Project: stkpp::Model
27 * created on: 13 août 2011
28 * Purpose: Create a gaussian statistical model.
29 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
30 *
31 **/
32
37#ifndef STK_IGAUSSIANMODEL_H
38#define STK_IGAUSSIANMODEL_H
39
40#include "STK_Model_Util.h"
41#include "STK_IStatModel.h"
42
47
49
50namespace STK
51{
52template<class> class IGaussianModel;
53
54namespace hidden
55{
56
57template<class Data_>
59{
60 class Void {};
61 typedef Data_ Array;
62 typedef Data_ Data;
63 typedef Void ParamHandler;
64};
65
66} // namespace hidden
67
73template<class Vector>
74Real gaussianLnLikelihood(ExprBase<Vector> const& data, Real const& mu, Real const& sigma)
75{
76 if (sigma)
77 {
78 Real scale = 0., std = std::sqrt((double)sigma);
79 // compute scale
80 scale = ((data-mu)/std).maxElt();
81 Real sum = 0;
82 if (scale)
83 { sum = (((data-mu)/std)/scale).norm2();}
84 return - ( 0.5*sum*scale*scale
85 + data.size() * (std::log((double)std) + Const::_LNSQRT2PI_)
86 );
87 }
88 // 0 variance
90}
91
151template <class Array>
152class IGaussianModel: public IStatModel< IGaussianModel<Array> >
153{
157
158 protected:
162 IGaussianModel( Array const* p_data): Base(p_data) {}
166 IGaussianModel( Array const& data): Base(data) {}
167
168 public:
170 virtual ~IGaussianModel() {}
172 inline RowVector const& mean() const { return mean_;}
173
174 protected:
178 inline void compMean() { mean_ = Stat::mean(*(this->p_dataij_));}
182 inline void compWeightedMean(ColVector const& weights)
183 { mean_ = Stat::mean(*(this->p_data_), weights);}
185 virtual void compCovariance() =0;
189 virtual void compWeightedCovariance(ColVector const& weights) =0;
190};
191
192} // namespace STK
193
194#endif /* STK_IGAUSSIANMODEL_H */
A Array2DPoint is a one dimensional horizontal container.
In this file, we define Array2DSquare class.
A Array2DVector is a one dimensional horizontal container.
In this file, we define the final class Array2D.
In this file we define the class IStatModel.
In this file we define the constant and utilities methods used in the project Model.
This file contain the functors computings statistics.
Compute the the maximum likelihood estimates of a complete Gaussian statistical model.
void compWeightedMean(ColVector const &weights)
compute the empirical weighted mean
IGaussianModel(Array const *p_data)
constructor.
virtual ~IGaussianModel()
destructor.
RowVector const & mean() const
virtual void compWeightedCovariance(ColVector const &weights)=0
compute the empirical weighted covariance matrix.
hidden::Traits< Array >::Row RowVector
RowVector mean_
Vector of the empirical means.
hidden::Traits< Array >::Col ColVector
void compMean()
compute the empirical mean
virtual void compCovariance()=0
compute the empirical covariance matrix.
IGaussianModel(Array const &data)
constructor.
IStatModel< IGaussianModel< Array > > Base
Base class for all Statistical Models [Deprecated], have been replaced by IStatModel.
Data const * p_dataij_
A pointer on the original data set.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
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.
hidden::FunctorTraits< Derived, MeanOp >::Row mean(Derived const &A)
Compute the mean(s) value(s) of A.
The namespace STK is the main domain space of the Statistical ToolKit project.
Real gaussianLnLikelihood(ExprBase< Vector > const &data, Real const &mu, Real const &sigma)
Compute the gaussian log likehood of a one dimensionnal gaussian model.
Arithmetic properties of STK fundamental types.