bug-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-gsl] [bug #25039] gsl_ran_exponential range should be [0,inf]


From: Brian Gough
Subject: [Bug-gsl] [bug #25039] gsl_ran_exponential range should be [0,inf]
Date: Mon, 08 Dec 2008 19:26:49 +0000
User-agent: Emacs-w3m/1.4.4 w3m/0.5.2

URL:
  <http://savannah.gnu.org/bugs/?25039>

                 Summary: gsl_ran_exponential range should be [0,inf]
                 Project: GNU Scientific Library
            Submitted by: bjg
            Submitted on: Mon 08 Dec 2008 07:26:47 PM GMT
                Category: Accuracy problem
                Severity: 2 - Minor
        Operating System: 
                  Status: Confirmed
             Assigned to: None
             Open/Closed: Open
                 Release: 1.12
         Discussion Lock: Any

    _______________________________________________________

Details:

From: "Adam Stinchcombe" <address@hidden>
To: address@hidden
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,
Adam Stinchcombe






    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?25039>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]