Are Numpy Binomial Random Numbers Inefficient?
Solution 1:
Numpy's legacy binomial random generator is implemented in C, and the algorithm uses numerical inversion if the parameters are sufficiently small. This may be too much work if p = 0.5
, since random bits rather than random double
s could have been used instead in the binomial generator. In addition, the basic algorithm hasn't changed, it seems, for years (see also mtrand.pyx
), so that it doesn't take advantage of vectorization or multithreading, for example.
Moreover, in the early days of Numpy there wasn't "much cause to change the distribution methods that much", so that this and other random generation algorithms in Numpy were retained in the name of reproducible "randomness". However, this has changed in version 1.17 and later: Breaking changes to random generation methods, such as a new binomial generator, are now allowed, but are treated as new features that will be introduced only "on X.Y
releases, never X.Y.Z
". For details, see "RNG Policy" and "Random Sampling (numpy.random)".
If having faster binomial random variates matters to you, you should file a new Numpy issue.
EDIT (Nov. 9): Code for legacy distributions was moved.
Post a Comment for "Are Numpy Binomial Random Numbers Inefficient?"