STK++ 0.9.13
STK_IUnivStatModel.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: 22 juil. 2011
28 * Purpose: define the class IUnivStatModel.
29 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
30 *
31 **/
32
37#ifndef STK_IUNIVSTATMODEL_H
38#define STK_IUNIVSTATMODEL_H
39#include <Sdk.h>
40
41#include "STK_IStatModelBase.h"
42
43namespace STK
44{
45
85template <class ColVector, class WColVector, class UnivariateLaw>
86class IUnivStatModel: public IStatModelBase, public IRunnerUnsupervised<ColVector, WColVector>
87{
88 public:
89 using IRunnerUnsupervised<ColVector, WColVector>::p_data;
91 typedef typename ColVector::Type Type;
94
95 protected:
99 IUnivStatModel(ColVector const& data): IStatModelBase(data.size(), 1), Runner(data)
100 { this->initialize(data.size(), 1);}
103 { if (p_data) this->initialize(p_data->size(), 1) ;}
107
108 public:
110 virtual ~IUnivStatModel() {}
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 }
120 inline UnivariateLaw const& law() const { return law_;}
122 virtual int computeNbFreeParameters() const =0;
125 virtual bool run()
126 {
127 if (!p_data())
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 }
148 virtual bool run( WColVector const& weights)
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
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 }
167
168 protected:
171 virtual void update()
172 { if (p_data()) this->initialize(p_data()->size(), 1); }
174 UnivariateLaw law_;
176 virtual void computeParameters() = 0;
178 virtual void computeParameters(WColVector const& weights) = 0;
179};
180
181
182} // namespace STK
183
184#endif /* STK_IUNIVSTATMODEL_H */
In this file we define the interface base class IStatModelBase.
#define STKERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:49
This file include all the other header files of the project Sdk.
Sdk class for all library Exceptions.
virtual const String error() const
Returns a C-style character string describing the general cause of the current error.
String msg_error_
String with the last error message.
Definition STK_IRunner.h:96
Abstract class for all classes making unsupervised learning.
ColVector const * p_data() const
get the data set
Interface base class for all Statistical Models.
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
void initialize(int nbSample, int nbVariable)
set the dimensions of the parameters of the model
Base class for all Statistical Models.
IUnivStatModel(ColVector const *p_data)
Constructor with a ptr on the data set.
IUnivStatModel(IUnivStatModel const &model)
Copy constructor.
UnivariateLaw const & law() const
virtual bool run(WColVector const &weights)
compute the weighted empirical probability of success based on the observed variables.
Real computeLnLikelihood() const
compute the log Likelihood of the statistical model.
virtual bool run()
Estimate the parameters of the model and update the.
IRunnerUnsupervised< ColVector, WColVector > Runner
Type of the Runner.
virtual int computeNbFreeParameters() const =0
compute the number of free parameters
ColVector::Type Type
Type of the data contained in the container.
UnivariateLaw law_
The probability law of the model.
virtual void computeParameters()=0
compute the parameters
virtual void computeParameters(WColVector const &weights)=0
compute the weighted parameters
IUnivStatModel()
default constructor.
virtual ~IUnivStatModel()
destructor
virtual void update()
This virtual method will be called if the user set a new data set.
IUnivStatModel(ColVector const &data)
Constructor with 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.
The namespace STK is the main domain space of the Statistical ToolKit project.
Arithmetic properties of STK fundamental types.