STK++ 0.9.13

class for the Uniform law distribution. More...

#include <STK_Law_Uniform.h>

Inheritance diagram for STK::Law::Uniform:
Inheritance graph

Public Types

typedef IUnivLaw< RealBase
 

Public Member Functions

 Uniform (Real const &a=0., Real const &b=1.)
 constructor.
 
 Uniform (Uniform const &law)
 copy constructor.
 
virtual ~Uniform ()
 destructor.
 
Real consta () const
 
Real constb () const
 
Real constrange () const
 
void setA (Real const &a)
 
void setB (Real const &b)
 
virtual Real rand () const
 Generate a pseudo Uniform 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 &a, Real const &b)
 Generate a pseudo Uniform random variate.
 
static Real pdf (Real const &x, Real const &a, Real const &b)
 Give the value of the pdf at x.
 
static Real lpdf (Real const &p, Real const &a, Real const &b)
 Give the value of the log-pdf at x.
 
static Real cdf (Real const &t, Real const &a, Real const &b)
 Give the value of the cdf at t.
 
static Real icdf (Real const &p, Real const &a, Real const &b)
 Give the value of the quantile at p.
 

Protected Attributes

Real a_
 The lower bound.
 
Real b_
 The upper bound.
 
- Protected Attributes inherited from STK::Law::ILawBase
String name_
 Name of the Law.
 

Private Attributes

Real range_
 

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

class for the Uniform law distribution.

In probability theory and statistics, the continuous uniform distribution or rectangular distribution is a family of symmetric probability distributions such that for each member of the family, all intervals of the same length on the distribution's support are equally probable. The support is defined by the two parameters, a and b, which are its minimum and maximum values.

The probability density function of the continuous uniform distribution is:

\[
  f(x; a, b) = \frac{1}{b-a} 1_{ a \leq x \leq b}.
\]

Definition at line 59 of file STK_Law_Uniform.h.

Member Typedef Documentation

◆ Base

Constructor & Destructor Documentation

◆ Uniform() [1/2]

STK::Law::Uniform::Uniform ( Real const a = 0.,
Real const b = 1. 
)
inline

constructor.

Parameters
a,bthe lower and upper bounds

Definition at line 66 of file STK_Law_Uniform.h.

67 : Base(_T("Uniform")), a_(a), b_(b), range_(b_ - a_)
68 {
69 if (range_ <= 0.)
71 }
#define STKINVALIDARGUMENT_ERROR_2ARG(Where, Arg1, Arg2, Error)
Definition STK_Macros.h:183
#define _T(x)
Let x unmodified.
Uniform(Real const &a=0., Real const &b=1.)
constructor.
Real const & b() const
Real a_
The lower bound.
Real const & a() const
Real b_
The upper bound.
IUnivLaw< Real > Base

References a_, b_, range_, STKINVALIDARGUMENT_ERROR_2ARG, and Uniform().

Referenced by Uniform().

◆ Uniform() [2/2]

STK::Law::Uniform::Uniform ( Uniform const law)
inline

copy constructor.

Parameters
lawthe law to copy

Definition at line 75 of file STK_Law_Uniform.h.

75 : Base(law), a_(law.a_), b_(law.b_), range_(law.range_)
76 {};

◆ ~Uniform()

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

destructor.

Definition at line 78 of file STK_Law_Uniform.h.

78{}

Member Function Documentation

◆ a()

Real const & STK::Law::Uniform::a ( ) const
inline
Returns
the lower bound

Definition at line 80 of file STK_Law_Uniform.h.

80{ return a_;}

References a_.

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

◆ b()

Real const & STK::Law::Uniform::b ( ) const
inline
Returns
the upper bound

Definition at line 82 of file STK_Law_Uniform.h.

82{ return b_;}

References b_.

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

◆ cdf() [1/2]

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

The cumulative distribution function is.

\[
 F(t; a,b)= \frac{t - a}{b-a}
\]

Parameters
ta real value

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

Definition at line 78 of file STK_Law_Uniform.cpp.

79{
80 if (!Arithmetic<Real>::isFinite(t) ) return t;
81 if (t <= a_) return 0.;
82 if (t >= b_) return 1.;
83 return (b_ - t)/range_;
84}
static bool isFinite(Type const &x)

References a_, b_, and range_.

◆ cdf() [2/2]

Real STK::Law::Uniform::cdf ( Real const t,
Real const a,
Real const b 
)
static

Give the value of the cdf at t.

Parameters
ta real value
a,bthe lower and upper bounds

Definition at line 134 of file STK_Law_Uniform.cpp.

135{ return (b - t)/(b-a);}

References a(), and b().

◆ icdf() [1/2]

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

The inverse cumulative distribution function is.

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

Parameters
pa probability

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

Definition at line 92 of file STK_Law_Uniform.cpp.

93{
94 // check parameter
95 if ((p > 1.) || (p < 0.))
96 STKDOMAIN_ERROR_1ARG(Exponential::icdf,p,invalid argument);
97
98 if (!Arithmetic<Real>::isFinite(p) ) return p;
99 if (p == 1.) return b_;
100 if (p == 0.) return a_;
101 return a_ + p * range_;
102}
#define STKDOMAIN_ERROR_1ARG(Where, Arg, Error)
Definition STK_Macros.h:165
virtual Real icdf(Real const &p) const
The inverse cumulative distribution function is.

References a_, b_, STK::Law::Exponential::icdf(), range_, and STKDOMAIN_ERROR_1ARG.

◆ icdf() [2/2]

Real STK::Law::Uniform::icdf ( Real const p,
Real const a,
Real const b 
)
static

Give the value of the quantile at p.

Parameters
pa probability
a,bthe lower and upper bounds

Definition at line 138 of file STK_Law_Uniform.cpp.

139{ return std::max(a,std::min((1.-p) * a + p * b, b));}

References a(), and b().

◆ lpdf() [1/2]

Real STK::Law::Uniform::lpdf ( Real const p,
Real const a,
Real const b 
)
static

Give the value of the log-pdf at x.

Parameters
pa probablility
a,bthe lower and upper bounds

Definition at line 127 of file STK_Law_Uniform.cpp.

128{
129 if (!Arithmetic<Real>::isFinite(x) ) return x;
130 if ((x < a)||(x > b)) return -Arithmetic<Real>::infinity();
131 return -std::log(b-a);
132}

References a(), and b().

◆ lpdf() [2/2]

Real STK::Law::Uniform::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 66 of file STK_Law_Uniform.cpp.

67{
68 if (!Arithmetic<Real>::isFinite(x) ) return x;
69 if ((x < a_)||(x > b_)) return -Arithmetic<Real>::infinity();
70 return -std::log(range_);
71}

References a_, b_, and range_.

◆ pdf() [1/2]

Real STK::Law::Uniform::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_Uniform.cpp.

58{
59 if (!Arithmetic<Real>::isFinite(x) ) return x;
60 if ((x < a_)||(x > b_)) return 0.;
61 return 1./range_;
62}

References a_, b_, and range_.

◆ pdf() [2/2]

Real STK::Law::Uniform::pdf ( Real const x,
Real const a,
Real const b 
)
static

Give the value of the pdf at x.

Parameters
xa real value
a,bthe lower and upper bounds

Definition at line 117 of file STK_Law_Uniform.cpp.

118{
119 if (!Arithmetic<Real>::isFinite(x) ) return x;
120 if ((x < a)||(x > b)) return 0.;
121 return 1./(b-a);
122}

References a(), and b().

◆ rand() [1/2]

Real STK::Law::Uniform::rand ( ) const
virtual

Generate a pseudo Uniform random variate.

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

Definition at line 49 of file STK_Law_Uniform.cpp.

50{
51 return ((range_ <= 1.) || (a_ <=1.)) ? a_ + range_ * generator.randUnif()
52 : a_ * (1. + generator.randUnif()*range_/a_) ;
53}

References a_, and range_.

◆ rand() [2/2]

Real STK::Law::Uniform::rand ( Real const a,
Real const b 
)
static

Generate a pseudo Uniform random variate.

Parameters
a,bthe lower and upper bounds

Definition at line 108 of file STK_Law_Uniform.cpp.

109{
110 return( (b-a <= 1.) ? a + (b-a) * generator.randUnif()
111 : a + generator.rand(b-a));
112}
virtual Real rand() const
Generate a pseudo Uniform random variate.

References a(), and b().

◆ range()

Real const & STK::Law::Uniform::range ( ) const
inline
Returns
the value b-a

Definition at line 84 of file STK_Law_Uniform.h.

84{ return range_;}

References range_.

◆ setA()

void STK::Law::Uniform::setA ( Real const a)
inline
Parameters
aset the lower bound

Definition at line 86 of file STK_Law_Uniform.h.

86{ a_ =a;}

References a(), and a_.

◆ setB()

void STK::Law::Uniform::setB ( Real const b)
inline
Parameters
bset the upper bound

Definition at line 88 of file STK_Law_Uniform.h.

88{ b_ =b;}

References b(), and b_.

Member Data Documentation

◆ a_

Real STK::Law::Uniform::a_
protected

The lower bound.

Definition at line 151 of file STK_Law_Uniform.h.

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

◆ b_

Real STK::Law::Uniform::b_
protected

The upper bound.

Definition at line 153 of file STK_Law_Uniform.h.

Referenced by b(), cdf(), icdf(), lpdf(), pdf(), setB(), and Uniform().

◆ range_

Real STK::Law::Uniform::range_
private

Definition at line 156 of file STK_Law_Uniform.h.

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


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