Boost logo

Boost Users :

Subject: [Boost-users] Box-Muller transform Gaussian Random Number Generator
From: Enrique Fernández (enrique.fernandez.perdomo_at_[hidden])
Date: 2009-06-04 21:40:26


Hello,

Boost random library implements GRNG (Gaussian Random Number Generator) with
Box-Muller transform (code
here<http://www.boost.org/doc/libs/1_39_0/boost/random/normal_distribution.hpp>).
I want to discuss about this line of code:

_cached_rho = sqrt(-result_type(2) * log(result_type(1)-_r2));

I don't know why log is applied to 1-r2, instead of r2 directly, yielding

_cached_rho = sqrt(-result_type(2) * log(_r2));

According with [1<http://www.cse.cuhk.edu.hk/%7Ephwl/mt/public/archives/papers/grng_acmcs07.pdf>,
2 <http://mathworld.wolfram.com/Box-MullerTransformation.html>,
3<http://en.wikipedia.org/wiki/Box-Muller_transformation>]
the uniform random variable r2 is always used directly (never 1-r2). I'd
like to know why 1-r2 is used.

I've tried to compare with other scientific libraries like
GSL<http://www.gnu.org/software/gsl/manual/html_node/The-Gaussian-Distribution.html>,
Scythestat <http://scythe.wustl.edu/api/rng_8h-source.html> and
LTILib<http://ltilib.sourceforge.net/doc/html/index.shtml>,
but they use the Box-Muller polar form (or Marsaglia polar method) or even
Ziggurat algorithm, which are supposed to be more efficient. Why isn't polar
form implemented? I'd like to know why 1-r2 is used anyway.

Regards,
  Enrique



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net