38#include "../include/STK_Law_Poisson.h"
56static Real gauss_icdf_fast(
Real const& p)
59 if (p == 0.5)
return 0.;
63 -3.969683028665376e+01
64 , 2.209460984245205e+02
65 , -2.759285104469687e+02
66 , 1.383577518672690e+02
67 , -3.066479806614716e+01
68 , 2.506628277459239e+00
72 -5.447609879822406e+01
73 , 1.615858368580409e+02
74 , -1.556989798598866e+02
75 , 6.680131188771972e+01
76 , -1.328068155288572e+01
80 -7.784894002430293e-03
81 , -3.223964580411365e-01
82 , -2.400758277161838e+00
83 , -2.549732539343734e+00
84 , 4.374664141464968e+00
85 , 2.938163982698783e+00
90 , 3.224671290700398e-01
91 , 2.445134137142996e+00
92 , 3.754408661907416e+00
95 Real t, u, q = std::min(p, 1-p);
101 u = u*(((((a[0]*t+a[1])*t+a[2])*t+a[3])*t+a[4])*t+a[5])
102 /(((((b[0]*t+b[1])*t+b[2])*t+b[3])*t+b[4])*t+1.);
107 t = sqrt(-2.*log(q));
108 u = (((((c[0]*t+c[1])*t+c[2])*t+c[3])*t+c[4])*t+c[5])
109 /((((d[0]*t+d[1])*t+d[2])*t+d[3])*t+1);
111 return (p > 0.5 ? - u : u);
119static int poisson_icd_raw(
Real const& p,
Real const& lambda)
122 Real q=1, el = std::exp(-lambda), s = p/el;
126 q += lambda*lambda/2;
129 q = gauss_icdf_fast(p);
130 Real sqlambda = std::sqrt(lambda);
131 int k = round(lambda + q * sqlambda + (q-1.)*(q+1.)*(1.-q/(12.*sqlambda))/6);
157 return poisson_icd_raw(Law::generator.randUnif(),
lambda_);
167 if (x<0)
return( 0. );
169 if (
lambda_==0.)
return( (x==0) ? 1. : 0. );
174 /(Const::_SQRT2PI_*std::sqrt(x))
193 -Const::_LNSQRT2PI_-std::log((
Real)x)/2.
206 if (
lambda_ == 0.)
return( 1. );
218 if (
p == 0.)
return 0;
231 if (
cdf(k - 1) <
p)
return k;
240 if(
cdf(k) >=
p)
return k;
250{
return poisson_icd_raw(Law::generator.randUnif(),
lambda);}
260 if (x<0)
return( 0. );
262 if (
lambda==0.)
return( (x==0) ? 1. : 0. );
267 /(Const::_SQRT2PI_*std::sqrt(x))
284 if (x==0)
return( -
lambda );
287 -Const::_LNSQRT2PI_-std::log((
Real)x)/2.
301 if (
lambda == 0.)
return( 1. );
313 if (
p == 0.)
return 0;
In this file we give the main mathematical constants.
In this file we declare usual Real functions.
In this file we declare functions around the gamma function ratio.
In this file we declare functions around the gamma function.
In this file we declare raw the functions.
virtual Real cdf(Real const &t) const
compute the cumulative distribution function Give the probability that a Poisson random variate is le...
Real lambda_
mean of the Poisson distribution
Real const & lambda() const
virtual int icdf(Real const &p) const
inverse cumulative distribution function The quantile is defined as the smallest value q such that F...
virtual Real lpdf(int const &x) const
compute the log probability distribution function.
virtual Real pdf(int const &x) const
compute the probability distribution function.
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
Real dev0(Real const &a, Real const &b)
compute the partial deviance .
Real lgammaStirlingError(Real const &z)
Compute the error when we compute using the Stirling's formula.
Real gammaRatioQ(Real const &a, Real const &x)
Compute the incomplete gamma function ratio Q(a,x).
double Real
STK fundamental type of Real values.
Real gammaRatioQ_raw(Real const &a, Real const &x)
The namespace STK is the main domain space of the Statistical ToolKit project.
Arithmetic properties of STK fundamental types.