36#include "../include/STK_Law_Gamma.h"
37#include "../include/STK_Law_Exponential.h"
57 if(
a_ == 0.)
return 0.;
61 Real p =
c_ * generator.randUnif();
64 x = -std::log((
c_ -
p) /
a_);
65 if (generator.randExp() >= (1. -
a_) * std::log(x))
break;
69 x = std::exp(std::log(
p) /
a_);
70 if (generator.randExp() >= x)
break;
77 if (
a_ == 1.0)
return b_*generator.randExp();
85 while( (
v = 1. +
c_* ( x = generator.randGauss() ) ) <= 0. );
89 if ( (
u = generator.randUnif()) < 1.-(x*x)*(x*x)/(108. *
d_) )
break;
91 if ( std::log(
u) < 0.5*x*x+
d_*(1.-
v+std::log(
v)) )
break;
109 if (
isNA(x))
return x;
111 if (x < 0.)
return 0.;
114 : (
a_>1.) ? 0. : 1./
b_;
130 if (
isNA(x))
return x;
154 if (
t <= 0.)
return 0.;
180 Real c = 1. + a/Const::_E_;
182 if(a == 0.)
return 0.;
185 Real p =
c * generator.randUnif();
188 x = -std::log((
c -
p) / a);
189 if (generator.randExp() >= (1. - a) * std::log(x))
break;
193 x = std::exp(std::log(
p) / a);
194 if (generator.randExp() >= x)
break;
203 const Real d = a-1./3.;
204 const Real c = 1./sqrt(9.*d);
212 while( (
v = 1. +
c * ( x = generator.randGauss() ) ) <= 0. ) {}
216 if ( (
u = generator.randUnif()) < 1.-(x*x)*(x*x)/(108. * d) )
break;
218 if ( std::log(
double(
u)) < 0.5*x*x+d*(1.-
v+log(
v)) )
break;
233 if (
isNA(x))
return x;
235 if (x < 0.)
return 0.;
238 : (a>1.) ? 0. : 1./b;
254 if (
isNA(x))
return x;
275 if (
t <= 0.)
return 0.;
294 c_ = 1. +
a_/Const::_E_;
295 d_ =
c_ * generator.randUnif();
300 c_ = 1./std::sqrt(9.*
d_);
In this file we declare functions around the gamma function ratio.
In this file we declare raw the functions.
#define STKRUNTIME_ERROR_1ARG(Where, Arg, Error)
#define STKDOMAIN_ERROR_2ARG(Where, Arg1, Arg2, Error)
virtual Real rand() const
Generate a pseudo Exponential random variate.
Real a_
The shape parameter.
Real b_
The scale parameter.
virtual Real pdf(Real const &x) const
compute
virtual Real lpdf(Real const &x) const
Compute.
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...
Real c_
First and second constants for rand.
virtual Real icdf(Real const &p) const
virtual Real cdf(Real const &t) const
void computeCtes() const
compute c_ and d_
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
Real poisson_pdf_raw(Real const &x, Real const &lambda)
Compute the Poisson density.
Real gammaRatioP(Real const &a, Real const &x)
Compute the incomplete gamma function ratio P(a,x).
Real poisson_lpdf_raw(Real const &x, Real const &lambda)
Compute the log-poisson density.
bool isNA(Type const &x)
utility method allowing to know if a value is a NA (Not Available) value
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.