STK++ 0.9.13

Beta distribution law. More...

#include <STK_Law_Beta.h>

Inheritance diagram for STK::Law::Beta:
Inheritance graph

Public Types

typedef IUnivLaw< RealBase
 

Public Member Functions

 Beta (Real const &alpha=.5, Real const &beta=.5)
 default constructor.
 
virtual ~Beta ()
 Dtor.
 
Real alpha () const
 
Real beta () const
 
void setAlpha (Real alpha)
 set the alpha value
 
void setBeta (Real beta)
 set the beta value
 
virtual Real rand () const
 
virtual Real pdf (Real const &x) const
 
virtual Real lpdf (Real const &x) const
 
virtual Real cdf (Real const &t) const
 
virtual Real icdf (Real const &p) const
 
- 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 &alpha, Real const &beta)
 
static Real pdf (Real const &x, Real const &alpha, Real const &beta)
 
static Real lpdf (Real const &x, Real const &alpha, Real const &beta)
 
static Real cdf (Real const &t, Real const &alpha, Real const &beta)
 
static Real icdf (Real const &p, Real const &alpha, Real const &beta)
 

Protected Attributes

Real alpha_
 First parameter.
 
Real beta_
 Second 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

Beta distribution law.

In probability theory and statistics, the beta distribution is a family of continuous probability distributions defined on the interval [0, 1] parameterized by two positive shape parameters that appear as exponents of the random variable and control the shape of the distribution.

The Beta distribution, is a continuous probability distribution with pdf

\[
f(x) = \frac{x^{\alpha-1} (1-x)^{\beta-1} }
            {{\boldsymbol \beta}(\alpha,\beta)},
\quad x \in [0,1],\ \mbox{ et }\ \alpha,\beta>0
\]

where ${\boldsymbol \beta}(a,b) = \frac{\Gamma(\alpha)\Gamma(\beta)}{\Gamma(\alpha+\beta)} $ represents the beta function.

See also
STK::Funct::betaRatio

Definition at line 64 of file STK_Law_Beta.h.

Member Typedef Documentation

◆ Base

Constructor & Destructor Documentation

◆ Beta()

STK::Law::Beta::Beta ( Real const alpha = .5,
Real const beta = .5 
)
inline

default constructor.

Definition at line 69 of file STK_Law_Beta.h.

70 : Base(String(_T("Beta"))), alpha_(alpha), beta_(beta)
71 {
72 if ( !isFinite(alpha) || !isFinite(beta) || alpha <= 0.0 || beta <= 0.0)
73 STKDOMAIN_ERROR_2ARG("Beta::Beta",alpha,beta,"argument error");
74 }
#define STKDOMAIN_ERROR_2ARG(Where, Arg1, Arg2, Error)
Definition STK_Macros.h:147
#define _T(x)
Let x unmodified.
IUnivLaw< Real > Base
Real beta_
Second parameter.
Real beta() const
Real alpha() const
Real alpha_
First parameter.
bool isFinite(Type const &x)
utility method allowing to know if a value is a finite value
std::basic_string< Char > String
STK fundamental type of a String.

References alpha(), beta(), STK::isFinite(), and STKDOMAIN_ERROR_2ARG.

◆ ~Beta()

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

Dtor.

Definition at line 76 of file STK_Law_Beta.h.

76{}

Member Function Documentation

◆ alpha()

Real STK::Law::Beta::alpha ( ) const
inline
Returns
the alpha value

Definition at line 78 of file STK_Law_Beta.h.

78{return alpha_;}

References alpha_.

Referenced by Beta(), cdf(), rand(), and setAlpha().

◆ beta()

Real STK::Law::Beta::beta ( ) const
inline
Returns
the beta value

Definition at line 80 of file STK_Law_Beta.h.

80{ return beta_;}

References beta_.

Referenced by Beta(), cdf(), rand(), and setBeta().

◆ cdf() [1/2]

Real STK::Law::Beta::cdf ( Real const t) const
virtual
Returns
The cumulative distribution function

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

Definition at line 85 of file STK_Law_Beta.cpp.

86{
87 // check NA value
88 if (isNA(t)) return Arithmetic<Real>::NA();
89 // compute result
90 return (Arithmetic<Real>::isInfinite(t)) ? (t < 0.) ? 0.0 : 1.0
91 : Funct::betaRatio(alpha_,beta_,t, false);
92}
Real betaRatio(Real const &a, Real const &b, Real const &x, bool lower_tail=true)
Compute the incomplete beta function ratio Compute the beta ratio function.
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 alpha_, beta_, STK::Funct::betaRatio(), STK::isNA(), and STK::Arithmetic< Type >::NA().

◆ cdf() [2/2]

Real STK::Law::Beta::cdf ( Real const t,
Real const alpha,
Real const beta 
)
static
Returns
The cumulative distribution function

Definition at line 137 of file STK_Law_Beta.cpp.

138{
139 // check NA value
140 if (isNA(t)) return Arithmetic<Real>::NA();
141 // compute result
142 return (Arithmetic<Real>::isInfinite(t)) ? (t < 0.) ? 0.0 : 1.0
143 : Funct::betaRatio(alpha,beta,t, false);
144}

References alpha(), beta(), STK::Funct::betaRatio(), STK::isNA(), and STK::Arithmetic< Type >::NA().

◆ icdf() [1/2]

Real STK::Law::Beta::icdf ( Real const p) const
virtual
Returns
The inverse cumulative distribution

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

Definition at line 97 of file STK_Law_Beta.cpp.

98{
99 // check parameter
100 if ((p > 1.) || (p < 0.))
101 STKDOMAIN_ERROR_1ARG(Beta::icdf,p,argument outside [0;1]);
102 // trivial cases
103 if (p == 0.) return 0.;
104 if (p == 1.) return 1.;
105 // result
106 return 0.;
107}
#define STKDOMAIN_ERROR_1ARG(Where, Arg, Error)
Definition STK_Macros.h:165
virtual Real icdf(Real const &p) const

References icdf(), and STKDOMAIN_ERROR_1ARG.

Referenced by icdf(), and icdf().

◆ icdf() [2/2]

Real STK::Law::Beta::icdf ( Real const p,
Real const alpha,
Real const beta 
)
static
Returns
The inverse cumulative distribution

Definition at line 146 of file STK_Law_Beta.cpp.

147{
148 // check parameter
149 if ((p > 1.) || (p < 0.))
150 STKDOMAIN_ERROR_1ARG(Beta::icdf,p,argument outside [0;1]);
151 // trivial cases
152 if (p == 0.) return 0.;
153 if (p == 1.) return 1.;
154 // result
155 return 0.;
156}

References icdf(), and STKDOMAIN_ERROR_1ARG.

◆ lpdf() [1/2]

Real STK::Law::Beta::lpdf ( Real const x) const
virtual
Returns
the value of the log-pdf at x.

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

Definition at line 71 of file STK_Law_Beta.cpp.

72{
73 // check NA value
74 if (isNA(x)) return Arithmetic<Real>::NA();
75 // check parameter
77 return -Arithmetic<Real>::infinity();
78 // compute result
79 return 0.;
80}

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

◆ lpdf() [2/2]

Real STK::Law::Beta::lpdf ( Real const x,
Real const alpha,
Real const beta 
)
static
Returns
the value of the log-pdf at x.

Definition at line 126 of file STK_Law_Beta.cpp.

127{
128 // check NA value
129 if (isNA(x)) return Arithmetic<Real>::NA();
130 // check parameter
132 return -Arithmetic<Real>::infinity();
133 // compute result
134 return 0.;
135}

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

◆ pdf() [1/2]

Real STK::Law::Beta::pdf ( Real const x) const
virtual
Returns
the value of the pdf at x.

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

Definition at line 60 of file STK_Law_Beta.cpp.

61{
62 // trivial cases
63 if (!Arithmetic<Real>::isFinite(x)||(x<0.)||(x>1)) return 0.0;
64 // compute result
65 return 0.;
66}
static bool isFinite(Type const &x)

◆ pdf() [2/2]

Real STK::Law::Beta::pdf ( Real const x,
Real const alpha,
Real const beta 
)
static
Returns
the value of the pdf at x.

Definition at line 118 of file STK_Law_Beta.cpp.

119{
120 // trivial cases
121 if (!Arithmetic<Real>::isFinite(x)||(x<0.)||(x>1)) return 0.0;
122 // compute result
123 return 0.;
124}

◆ rand() [1/2]

Real STK::Law::Beta::rand ( ) const
virtual
Returns
a pseudo Beta random variate. This function use the Gamma::rand() random generator. TODO : implement the order statistics when a and b are small integers (Devroye p. 431). TODO : implement the rejection method from the normal pdf when a=b (Devroye p. 434). TODO : Implement Cheng's algorithm BA for beta pdf (Devroye p. 438)

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

Definition at line 51 of file STK_Law_Beta.cpp.

52{
54 return g1/(g1+Law::Gamma::rand(beta_, 1.));
55}
virtual Real rand() const
generate a gamma random variate using the G.S algorithm of Ahrens and Dieter (1974) for 0<a_<1 and Ma...
double Real
STK fundamental type of Real values.

References alpha_, beta_, and STK::Law::Gamma::rand().

◆ rand() [2/2]

Real STK::Law::Beta::rand ( Real const alpha,
Real const beta 
)
static
Returns
a pseudo Beta random variate with the specified parameters.

Definition at line 112 of file STK_Law_Beta.cpp.

113{
114 Real g1 = Law::Gamma::rand(alpha, 1.);
115 return g1/(g1+Law::Gamma::rand(beta, 1.));
116}

References alpha(), beta(), and STK::Law::Gamma::rand().

◆ setAlpha()

void STK::Law::Beta::setAlpha ( Real  alpha)
inline

set the alpha value

Definition at line 82 of file STK_Law_Beta.h.

82{ alpha_ = alpha;}

References alpha(), and alpha_.

◆ setBeta()

void STK::Law::Beta::setBeta ( Real  beta)
inline

set the beta value

Definition at line 84 of file STK_Law_Beta.h.

84{beta_ =beta;}

References beta(), and beta_.

Member Data Documentation

◆ alpha_

Real STK::Law::Beta::alpha_
protected

First parameter.

Definition at line 127 of file STK_Law_Beta.h.

Referenced by alpha(), cdf(), rand(), and setAlpha().

◆ beta_

Real STK::Law::Beta::beta_
protected

Second parameter.

Definition at line 129 of file STK_Law_Beta.h.

Referenced by beta(), cdf(), rand(), and setBeta().


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