STK++ 0.9.13
STK_Law_Exponential.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_EXPONENTIAL_H
36#define STK_LAW_EXPONENTIAL_H
37
38#include "STK_Law_IUnivLaw.h"
39
40namespace STK
41{
42
43namespace Law
44{
63class Exponential: public IUnivLaw<Real>
64{
65 public:
68 inline Exponential( Real const& scale=1)
69 : Base(String(_T("Exponential"))), scale_(scale)
70 {
71 // check parameters
72 if ( !Arithmetic<Real>::isFinite(scale) || scale <= 0 )
74 }
76 inline virtual ~Exponential() {}
77
79 virtual Real rand() const;
83 virtual Real pdf( Real const& x) const;
87 virtual Real lpdf( Real const& x) const;
94 virtual Real cdf( Real const& t) const;
101 virtual Real icdf( Real const& p) const;
102
107 static Real rand( Real const& scale);
112 static Real pdf( Real const& x, Real const& scale);
117 static Real lpdf( Real const& x, Real const& scale);
122 static Real cdf( Real const& t, Real const& scale);
127 static Real icdf( Real const& p, Real const& scale);
128
129#ifdef IS_RTKPP_LIB
131 virtual Real lcdf( Real const& t) const;
133 virtual Real cdfc( Real const& t) const;
135 virtual Real lcdfc( Real const& t) const;
136#endif
137
138 protected:
141};
142
143#ifdef IS_RTKPP_LIB
144
145inline Real Exponential::rand() const
146{
147#ifdef _OPENMP
148//#pragma omp critical
149#endif
150GetRNGstate(); Real s = Rf_rexp(scale_); PutRNGstate(); return s;
151}
152
153inline Real Exponential::pdf( Real const& x) const { return Rf_dexp(x, scale_, false);}
154inline Real Exponential::lpdf( Real const& x) const { return Rf_dexp(x, scale_, true);}
155inline Real Exponential::cdf( Real const& t) const { return Rf_pexp(t, scale_, true, false);}
156inline Real Exponential::lcdf( Real const& t) const { return Rf_pexp(t, scale_, true, true);}
157inline Real Exponential::cdfc( Real const& t) const { return Rf_pexp(t, scale_, false, false);}
158inline Real Exponential::lcdfc( Real const& t) const { return Rf_pexp(t, scale_, false, true);}
159inline Real Exponential::icdf( Real const& p) const { return Rf_qexp(p , scale_, true, false);}
160
161inline Real Exponential::rand( Real const& scale)
162{
163#ifdef _OPENMP
164//#pragma omp critical
165#endif
166GetRNGstate(); Real s = Rf_rexp(scale); PutRNGstate(); return s;
167}
168
169inline Real Exponential::pdf(Real const& x, Real const& scale)
170{ return Rf_dexp(x, scale, false);}
171inline Real Exponential::lpdf(Real const& x, Real const& scale)
172{ return Rf_dexp(x, scale, true);}
173inline Real Exponential::cdf(Real const& t, Real const& scale)
174{ return Rf_pexp(t, scale, true, false);}
175inline Real Exponential::icdf(Real const& p, Real const& scale)
176{ return Rf_qexp(p, scale, true, false);}
177
178#endif
179} // namespace Law
180
181} // namespace STK
182
183#endif /*STK_LAW_EXPONENTIAL_H*/
In this file we define the interface base class IUnivLaw for all probabilities laws.
#define STKDOMAIN_ERROR_1ARG(Where, Arg, Error)
Definition STK_Macros.h:165
#define _T(x)
Let x unmodified.
Exponential distribution law.
virtual Real pdf(Real const &x) const
Give the value of the pdf at x.
virtual Real rand() const
Generate a pseudo Exponential random variate.
Exponential(Real const &scale=1)
constructor.
virtual Real cdf(Real const &t) const
The cumulative distribution function is.
virtual Real icdf(Real const &p) const
The inverse cumulative distribution function is.
virtual Real lpdf(Real const &x) const
Give the value of the log-pdf at x.
Real scale_
The scale parameter.
virtual ~Exponential()
destructor.
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...
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
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.
Arithmetic properties of STK fundamental types.