bug-gsl
[Top][All Lists]

## [Bug-gsl] bug: 0 not possible result in gsl_ran_exponential

 From: Adam Stinchcombe Subject: [Bug-gsl] bug: 0 not possible result in gsl_ran_exponential Date: Sat, 6 Dec 2008 19:04:35 -0500

```Hello,

Section 19.5 The Exponential Distribution
(http://www.gnu.org/software/gsl/manual/gsl-ref.html#The-Exponential-Distribution)
states that the distribution produces x >= 0, meaning that x=0 is a
possible result. The standard definition of the exponential
distribution also gives that x=0 is a possible value from the
distribution. The implementation in randist/exponential.c of gsl-1.11
is

double
gsl_ran_exponential (const gsl_rng * r, const double mu)
{
double u = gsl_rng_uniform_pos (r);

return -mu * log (u);
}

gsl_rng_uniform_pos returns a floating point number uniformly
distributed number on (0,1) , excluding both 0.0 and 1.0
(http://www.gnu.org/software/gsl/manual/gsl-ref.html#index-gsl_005frng_005funiform_005fpos-1486
). log maps (0,1) one-to-one and onto (-inf,0), excluding 0.0, which
means that the function above returns values on (0,inf),where inf is
the largest double. The point being that 0.0 is excluded as a possible
return value of the function.

I suggest the following implementation:

double
gsl_ran_exponential (const gsl_rng * r, const double mu)
{
double u = gsl_rng_uniform (r);

return -mu * log(1-u)
}

gsl_rng_uniform gives a value on [0,1) which is mapped to (0,1] by 1-u
and then to [0,inf) by log.

Since this distribution looks like the exponential everywhere except a
single point, I suspect that the statistics produced in the past were
not significantly incorrect. Please let me know if this is in fact a
bug or enlighten me as to my misunderstanding.

Cheers,