STK++ 0.9.13
STK_MultiLaw_IMultiLaw.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::STatistiK::Law
27 * created on: 29 juil. 2011
28 * Purpose: .
29 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
30 *
31 **/
32
38#ifndef STK_MULTILAW_ITMULTILAW_H
39#define STK_MULTILAW_ITMULTILAW_H
40
42#include "STK_Law_ILawBase.h"
43
44namespace STK
45{
46
47namespace MultiLaw
48{
49
59template<class RowVector>
61{
62 protected:
64 IMultiLaw( String const& name) : Law::ILawBase(name) {}
65
66 public:
68 virtual ~IMultiLaw() {}
75 virtual Real pdf( RowVector const& x) const =0;
81 virtual Real lpdf( RowVector const& x) const =0;
86 virtual void rand( RowVector& x) const =0;
87};
88
99template<class RowVector, class Law>
100class JointProbability: public IMultiLaw<RowVector>
101{
102 public:
103 typedef typename RowVector::Type Type;
117 virtual ~JointProbability() {}
119 Array1D<Law> const& JointLaw() const { return jointLaw_;}
120
122 Law const& law(int const& j) const { return jointLaw_[j];}
124 Law& law(int const& j) { return jointLaw_[j];}
126 Law const& atLaw(int const& j) const { return jointLaw_.at(j);}
128 Law& atLaw(int const& j) { return jointLaw_.at(j);}
130 void resize(int const& nbVar) { jointLaw_.resize(nbVar);}
131
138 virtual Real pdf( RowVector const& x) const
139 { return std::exp((double)lpdf(x));}
145 virtual Real lpdf( RowVector const& x) const
146 {
147 if (x.range() != jointLaw_.range())
149 Real sum = 0.;
150 for (int j= x.begin(); j <= x.lastIdx(); ++j)
151 { sum+= Arithmetic<Type>::isNA(x[j]) ? 0. : jointLaw_[j].lpdf(x[j]);}
152 return sum;
153 }
158 virtual void rand( RowVector& x) const
159 {
160 x.resize(jointLaw_.range());
161 for (int j= x.begin(); j <= x.lastIdx(); ++j)
162 { x[j] = jointLaw_[j].rand();}
163 }
164 protected:
167};
168
169
170} // namespace MultiLaw
171
172} // namespace STK
173
174#endif /* STK_MULTILAW_ITMULTILAW_H */
In this file we define and implement the final class Array1D.
In this file we define the interface base class for all multivariate probabilities laws ILawBase.
#define STKRUNTIME_ERROR_NO_ARG(Where, Error)
Definition STK_Macros.h:138
RowRange const & range() const
Derived & resize(Range const &I=RowRange())
Interface base class for all the (univariate/multivariate) probabilities laws.
ILawBase(String const &name)
Constructor.
String const & name() const
Interface base Class for the multivariate distributions.
virtual Real lpdf(RowVector const &x) const =0
compute the log probability distribution function Give the value of the log-pdf at the point x.
virtual void rand(RowVector &x) const =0
simulate a realization of the Multivariate Law and store the result in x.
virtual Real pdf(RowVector const &x) const =0
compute the probability distribution function (density) of the multivariate law.
virtual ~IMultiLaw()
destructor.
IMultiLaw(String const &name)
Constructor.
joint density class for the multivariate distributions.
Array1D< Law > const & JointLaw() const
virtual Real lpdf(RowVector const &x) const
compute the log probability distribution function Give the value of the log-pdf at the point x.
Law const & atLaw(int const &j) const
JointProbability(String const &name, int nbVar)
Constructor.
void resize(int const &nbVar)
resize the joint probability
JointProbability(String const &name)
Constructor.
Law const & law(int const &j) const
virtual void rand(RowVector &x) const
simulate a realization of the joint law and store the result in x.
virtual Real pdf(RowVector const &x) const
compute the probability distribution function (density) of the multivariate law.
Array1D< Law > jointLaw_
Array with the marginal laws.
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
std::basic_string< Char > String
STK fundamental type of a String.
double Real
STK fundamental type of Real values.
The namespace STK is the main domain space of the Statistical ToolKit project.
static bool isNA(Type const &x)