[SciPy-dev] Box-Muller considered slow.

David M. Cooke cookedm at physics.mcmaster.ca
Thu Dec 8 16:25:39 CST 2005


Charles R Harris <charlesr.harris at gmail.com> writes:

> I have done some benchmarking of the ziggurat algorithm vs the Box-Muller
> algorithm in boost/random for computing gaussian random variables. The ziggurat
> method was 6x faster. As scipy at this time uses the Box-Muller method, I would
> like to propose a switch to the ziggurat method.

boost/random looks like it uses a deterministic polar method for
gaussian RVs (at least in 1.33).

I've had a look at the ziggurat algorithm; it's more complicated, so
we'd need some code for it (hint, hint :-)

Mind you, that code could be written in Pyrex, not C, as the mtrand
module is written as a Pyrex wrapper around C code.

For those interested, Marsgalia and Wai Wan Tang's updated method
(2000) is here,
http://www.jstatsoft.org/v05/i08/ziggurat.pdf

with some comments about a problem using the single random number for
rejection in it here:
http://www.doornik.com/research/ziggurat.pdf

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke                      http://arbutus.physics.mcmaster.ca/dmc/
|cookedm at physics.mcmaster.ca




More information about the Scipy-dev mailing list