mdipierro / nlib

The book "Annotated Algorithms in Python" and the nlib.py library
1.33k stars 115 forks source link

Exponential sampling is wrong #22

Open Oleg-Krivosheev opened 7 years ago

Oleg-Krivosheev commented 7 years ago

Formula (6.67, 6.68). Statement that -log(1-u) is equivalent to -log(u) is true iff u is U(0,1) in the (0,1) range. In reality Python U(0,1) as well as C/C++ U(0,1) are defined in the interval [0,1). Thus, -log(1-u) will always work while -log(u) sometimes will produce FP exceptions when 0 is sampled