STK++ 0.9.13
STK_Law_Uniform.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: 23 janv. 2013
28 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
35#ifndef STK_LAW_UNIFORM_H
36#define STK_LAW_UNIFORM_H
37
38#include "STK_Law_IUnivLaw.h"
39
40namespace STK
41{
42
43namespace Law
44{
59class Uniform: public IUnivLaw<Real>
60{
61 public:
66 inline Uniform( Real const& a =0., Real const& b =1.)
67 : Base(_T("Uniform")), a_(a), b_(b), range_(b_ - a_)
68 {
69 if (range_ <= 0.)
71 }
75 inline Uniform( Uniform const& law): Base(law), a_(law.a_), b_(law.b_), range_(law.range_)
76 {};
78 inline virtual ~Uniform() {}
80 inline Real const& a() const { return a_;}
82 inline Real const& b() const { return b_;}
84 inline Real const& range() const { return range_;}
86 inline void setA(Real const& a) { a_ =a;}
88 inline void setB(Real const& b){ b_ =b;}
89
91 virtual Real rand() const;
95 virtual Real pdf( Real const& x) const;
99 virtual Real lpdf( Real const& x) const;
106 virtual Real cdf( Real const& t) const;
113 virtual Real icdf( Real const& p) const;
114
118 static Real rand( Real const& a, Real const& b);
123 static Real pdf( Real const& x, Real const& a, Real const& b);
128 static Real lpdf( Real const& p, Real const& a, Real const& b);
133 static Real cdf( Real const& t, Real const& a, Real const& b);
138 static Real icdf( Real const& p, Real const& a, Real const& b);
139
140#ifdef IS_RTKPP_LIB
142 virtual Real lcdf( Real const& t) const;
144 virtual Real cdfc( Real const& t) const;
146 virtual Real lcdfc( Real const& t) const;
147#endif
148
149 protected:
154
155 private:
157};
158
159#ifdef IS_RTKPP_LIB
160
161inline Real Uniform::rand() const
162{
163#ifdef _OPENMP
164//#pragma omp critical
165#endif
166 GetRNGstate(); Real s = Rf_runif(a_, b_); PutRNGstate(); return s;
167}
168
169inline Real Uniform::pdf( Real const& x) const { return Rf_dunif(x, a_, b_, false);}
170inline Real Uniform::lpdf( Real const& x) const { return Rf_dunif(x, a_, b_, true);}
171inline Real Uniform::cdf( Real const& t) const { return Rf_punif(t, a_, b_, true, false);}
172inline Real Uniform::lcdf( Real const& t) const { return Rf_punif(t, a_, b_, true, true);}
173inline Real Uniform::cdfc( Real const& t) const { return Rf_punif(t, a_, b_, false, false);}
174inline Real Uniform::lcdfc( Real const& t) const { return Rf_punif(t, a_, b_, false, true);}
175inline Real Uniform::icdf( Real const& p) const { return Rf_qunif(p , a_, b_, true, false);}
176
177inline Real Uniform::rand( Real const& a, Real const& b)
178{
179#ifdef _OPENMP
180//#pragma omp critical
181#endif
182 GetRNGstate(); Real s = Rf_runif(a, b); PutRNGstate(); return s;
183}
184
185inline Real Uniform::pdf(const Real& x, const Real& a, const Real& b)
186{ return Rf_dunif(x,a, b, false);}
187inline Real Uniform::lpdf(const Real& x, const Real& a, const Real& b)
188{ return Rf_dunif(x, a, b, true);}
189inline Real Uniform::cdf(const Real& t, const Real& a, const Real& b)
190{ return Rf_punif(t, a, b, true, false);}
191inline Real Uniform::icdf(const Real& p, const Real& a, const Real& b)
192{ return Rf_qunif(p , a, b, true, false);}
193
194#endif
195
196} // namespace Law
197
198} // namespace STK
199
200#endif /*STK_LAW_UNIFORM_H*/
In this file we define the interface base class IUnivLaw for all probabilities laws.
#define STKINVALIDARGUMENT_ERROR_2ARG(Where, Arg1, Arg2, Error)
Definition STK_Macros.h:183
#define _T(x)
Let x unmodified.
Interface base class for all the univariate distributions.
virtual Real cdfc(Real const &t) const
calculate the complement of cumulative distribution function, called in statistics the survival funct...
virtual Real lcdfc(Real const &t) const
calculate the log-complement of cumulative distribution function Give the log-probability that a rand...
virtual Real lcdf(Real const &t) const
compute the lower tail log-cumulative distribution function Give the log-probability that a random va...
class for the Uniform law distribution.
Uniform(Real const &a=0., Real const &b=1.)
constructor.
virtual ~Uniform()
destructor.
virtual Real icdf(Real const &p) const
The inverse cumulative distribution function is.
Real const & b() const
virtual Real rand() const
Generate a pseudo Uniform random variate.
Real a_
The lower bound.
Real const & a() const
Uniform(Uniform const &law)
copy constructor.
void setB(Real const &b)
virtual Real pdf(Real const &x) const
Give the value of the pdf at x.
Real b_
The upper bound.
virtual Real lpdf(Real const &x) const
Give the value of the log-pdf at x.
virtual Real cdf(Real const &t) const
The cumulative distribution function is.
Real const & range() const
IUnivLaw< Real > Base
void setA(Real const &a)
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
double Real
STK fundamental type of Real values.
The namespace STK is the main domain space of the Statistical ToolKit project.