STK++ 0.9.13

Exponential distribution law. More...

#include <STK_Law_Exponential.h>

Inheritance diagram for STK::Law::Exponential:
Inheritance graph

Public Types

typedef IUnivLaw< RealBase
 

Public Member Functions

 Exponential (Real const &scale=1)
 constructor.
 
virtual ~Exponential ()
 destructor.
 
virtual Real rand () const
 Generate a pseudo Exponential random variate.
 
virtual Real pdf (Real const &x) const
 Give the value of the pdf at x.
 
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.
 
virtual Real icdf (Real const &p) const
 The inverse cumulative distribution function is.
 
- Public Member Functions inherited from STK::Law::IUnivLaw< Real >
virtual ~IUnivLaw ()
 Virtual destructor.
 
virtual Real lcdf (Real const &t) const
 compute the lower tail log-cumulative distribution function Give the log-probability that a random variate is less or equal to t.
 
virtual Real cdfc (Real const &t) const
 calculate the complement of cumulative distribution function, called in statistics the survival function.
 
virtual Real lcdfc (Real const &t) const
 calculate the log-complement of cumulative distribution function Give the log-probability that a random variate is greater than t.
 
- Public Member Functions inherited from STK::Law::ILawBase
String constname () const
 

Static Public Member Functions

static Real rand (Real const &scale)
 Generate a pseudo Exponential random variate with the specified parameter.
 
static Real pdf (Real const &x, Real const &scale)
 Give the value of the pdf at x.
 
static Real lpdf (Real const &x, Real const &scale)
 Give the value of the log-pdf at x.
 
static Real cdf (Real const &t, Real const &scale)
 Compute he cumulative distribution function.
 
static Real icdf (Real const &p, Real const &scale)
 Compute rhe inverse cumulative distribution function.
 

Protected Attributes

Real scale_
 The scale parameter.
 
- Protected Attributes inherited from STK::Law::ILawBase
String name_
 Name of the Law.
 

Additional Inherited Members

- Protected Member Functions inherited from STK::Law::IUnivLaw< Real >
 IUnivLaw (String const &name)
 Constructor.
 
 IUnivLaw (IUnivLaw const &law)
 copy Constructor.
 
- Protected Member Functions inherited from STK::Law::ILawBase
 ILawBase (String const &name)
 Constructor.
 
 ~ILawBase ()
 destructor.
 

Detailed Description

Exponential distribution law.

In probability theory and statistics, the exponential distribution (a.k.a. negative exponential distribution) is the probability distribution that describes the time between events in a Poisson process, i.e. a process in which events occur continuously and independently at a constant average rate. It is a particular case of gamma distribution. It is the continuous analogue of the geometric distribution, and it has the key property of being memoryless. In addition to being used for the analysis of Poisson processes, it is found in various other contexts.

The probability density function (pdf) of an exponential distribution is

\[
  f(x; \lambda) = \frac{1}{\lambda} e^{- x/\lambda} 1_{x\geq 0}
\]

where $\lambda>0$ is the scale (inverse rate) parameter.

Definition at line 63 of file STK_Law_Exponential.h.

Member Typedef Documentation

◆ Base

Constructor & Destructor Documentation

◆ Exponential()

STK::Law::Exponential::Exponential ( Real const scale = 1)
inline

constructor.

Definition at line 68 of file STK_Law_Exponential.h.

69 : Base(String(_T("Exponential"))), scale_(scale)
70 {
71 // check parameters
72 if ( !Arithmetic<Real>::isFinite(scale) || scale <= 0 )
73 STKDOMAIN_ERROR_1ARG(Exponential::Exponential,scale,invalid argument);
74 }
#define STKDOMAIN_ERROR_1ARG(Where, Arg, Error)
Definition STK_Macros.h:165
#define _T(x)
Let x unmodified.
Exponential(Real const &scale=1)
constructor.
Real scale_
The scale parameter.
std::basic_string< Char > String
STK fundamental type of a String.
static bool isFinite(Type const &x)

References Exponential(), and STKDOMAIN_ERROR_1ARG.

Referenced by Exponential().

◆ ~Exponential()

virtual STK::Law::Exponential::~Exponential ( )
inlinevirtual

destructor.

Definition at line 76 of file STK_Law_Exponential.h.

76{}

Member Function Documentation

◆ cdf() [1/2]

Real STK::Law::Exponential::cdf ( Real const t) const
virtual

The cumulative distribution function is.

\[
 F(t; \lambda)= 1- e^{- t/\lambda}
\]

Parameters
ta real value

Implements STK::Law::IUnivLaw< Real >.

Definition at line 85 of file STK_Law_Exponential.cpp.

86{
87 // NA value
88 if (isNA(t)) return Arithmetic<Real>::NA();
89 // trivial cases
90 if (t <= 0.) return 0.0;
91 if (Arithmetic<Real>::isInfinite(t)) return 1.0; /* t= +inf */
92
93 return 1.-exp(-t/scale_);
94}
bool isNA(Type const &x)
utility method allowing to know if a value is a NA (Not Available) value
static bool isInfinite(Type const &x)
static Type NA()
Adding a Non Available (NA) special number.

References STK::isNA(), STK::Arithmetic< Type >::NA(), and scale_.

◆ cdf() [2/2]

Real STK::Law::Exponential::cdf ( Real const t,
Real const scale 
)
static

Compute he cumulative distribution function.

Parameters
ta real value
scalethe scale of the distribution

Definition at line 157 of file STK_Law_Exponential.cpp.

158{
159 // NA value
160 if (isNA(t)) return Arithmetic<Real>::NA();
161 // trivial cases
162 if (t <= 0.) return 0.0;
163 if (Arithmetic<Real>::isInfinite(t)) return 1.0; /* t= +inf */
164
165 return(1.-exp(-t/scale));
166}

References STK::isNA(), and STK::Arithmetic< Type >::NA().

◆ icdf() [1/2]

Real STK::Law::Exponential::icdf ( Real const p) const
virtual

The inverse cumulative distribution function is.

\[
F^{-1}(p; \lambda) = - \lambda\log(1-p).
\]

Parameters
pa probability

Implements STK::Law::IUnivLaw< Real >.

Definition at line 99 of file STK_Law_Exponential.cpp.

100{
101 // check NA value
102 if (isNA(p)) return Arithmetic<Real>::NA();
103 // check parameter
104 if ((p > 1.) || (p < 0.))
105 STKDOMAIN_ERROR_1ARG(Exponential::icdf,p,invalid argument);
106 // trivial cases
107 if (p == 0.) return 0.0;
108 if (p == 1.) return Arithmetic<Real>::infinity();
109 // result
110 return (- scale_ * log(1.-p));
111}
virtual Real icdf(Real const &p) const
The inverse cumulative distribution function is.

References icdf(), STK::isNA(), STK::Arithmetic< Type >::NA(), scale_, and STKDOMAIN_ERROR_1ARG.

Referenced by icdf(), STK::Law::Uniform::icdf(), STK::Law::UniformDiscrete::icdf(), and icdf().

◆ icdf() [2/2]

Real STK::Law::Exponential::icdf ( Real const p,
Real const scale 
)
static

Compute rhe inverse cumulative distribution function.

Parameters
pa probability
scalethe scale of the distribution

Definition at line 172 of file STK_Law_Exponential.cpp.

173{
174 // check NA value
175 if (isNA(p)) return Arithmetic<Real>::NA();
176
177 // check parameter
178 if ((p > 1.) || (p < 0.))
179 STKDOMAIN_ERROR_1ARG(Exponential::icdf,p,invalid argument);
180 // trivial cases
181 if (p == 0.) return 0.0;
182 if (p == 1.) return Arithmetic<Real>::infinity();
183 // result
184 return(- scale * log(1.-p));
185}

References icdf(), STK::isNA(), STK::Arithmetic< Type >::NA(), and STKDOMAIN_ERROR_1ARG.

◆ lpdf() [1/2]

Real STK::Law::Exponential::lpdf ( Real const x) const
virtual

Give the value of the log-pdf at x.

Parameters
xa real value

Reimplemented from STK::Law::IUnivLaw< Real >.

Definition at line 71 of file STK_Law_Exponential.cpp.

72{
73 // NA value
74 if (isNA(x)) return Arithmetic<Real>::NA();
75 // trivial cases
76 if (x<0) return -Arithmetic<Real>::infinity();
77 if (Arithmetic<Real>::isInfinite(x)) return -Arithmetic<Real>::infinity();
78 // compute result
79 return (-x / scale_) - std::log(scale_) ;
80}

References STK::isNA(), STK::Arithmetic< Type >::NA(), and scale_.

◆ lpdf() [2/2]

Real STK::Law::Exponential::lpdf ( Real const x,
Real const scale 
)
static

Give the value of the log-pdf at x.

Parameters
xa real value
scalethe scale of the distribution

Definition at line 142 of file STK_Law_Exponential.cpp.

143{
144 // NA value
145 if (isNA(x)) return Arithmetic<Real>::NA();
146 // trivial cases
147 if (x<0) return -Arithmetic<Real>::infinity();
148 if (Arithmetic<Real>::isInfinite(x)) return -Arithmetic<Real>::infinity();
149 // compute result
150 return (-x / scale) - std::log(scale) ;
151}

References STK::isNA(), and STK::Arithmetic< Type >::NA().

◆ pdf() [1/2]

Real STK::Law::Exponential::pdf ( Real const x) const
virtual

Give the value of the pdf at x.

Parameters
xa real value

Implements STK::Law::IUnivLaw< Real >.

Definition at line 57 of file STK_Law_Exponential.cpp.

58{
59 // NA value
60 if (isNA(x)) return Arithmetic<Real>::NA();
61 // trivial cases
62 if (x<0) return 0.0;
63 if (Arithmetic<Real>::isInfinite(x)) return 0.0;
64 // compute result
65 return std::exp(-x/scale_) / scale_;
66}

References STK::isNA(), STK::Arithmetic< Type >::NA(), and scale_.

◆ pdf() [2/2]

Real STK::Law::Exponential::pdf ( Real const x,
Real const scale 
)
static

Give the value of the pdf at x.

Parameters
xa real value
scalethe scale of the distribution

Definition at line 128 of file STK_Law_Exponential.cpp.

129{
130 // NA value
131 if (isNA(x)) return Arithmetic<Real>::NA();
132 // trivial cases
133 if (x<0) return 0.0;
134 if (Arithmetic<Real>::isInfinite(x)) return 0.0;
135 // compute result
136 return std::exp(-x/scale) / scale;
137}

References STK::isNA(), and STK::Arithmetic< Type >::NA().

◆ rand() [1/2]

◆ rand() [2/2]

Real STK::Law::Exponential::rand ( Real const scale)
static

Generate a pseudo Exponential random variate with the specified parameter.

Parameters
scalethe scale of the distribution

Definition at line 117 of file STK_Law_Exponential.cpp.

118{
119 // check parameters
120 if ( scale <= 0 )
121 STKDOMAIN_ERROR_1ARG(Exponential::rand,scale,invalid argument);
122 return generator.randExp() * scale;
123}
virtual Real rand() const
Generate a pseudo Exponential random variate.

References rand(), and STKDOMAIN_ERROR_1ARG.

Member Data Documentation

◆ scale_

Real STK::Law::Exponential::scale_
protected

The scale parameter.

Definition at line 140 of file STK_Law_Exponential.h.

Referenced by cdf(), icdf(), lpdf(), pdf(), and rand().


The documentation for this class was generated from the following files: