Box-Muller transform Gaussian Random Number Generator
Hello, Boost random library implements GRNG (Gaussian Random Number Generator) with Box-Muller transform (code herehttp://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 [1http://www.cse.cuhk.edu.hk/%7Ephwl/mt/public/archives/papers/grng_acmcs07.pd..., 2 http://mathworld.wolfram.com/Box-MullerTransformation.html, 3http://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 GSLhttp://www.gnu.org/software/gsl/manual/html_node/The-Gaussian-Distribution.h..., Scythestat http://scythe.wustl.edu/api/rng_8h-source.html and LTILibhttp://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
AMDG Enrique Fernández wrote:
Hello,
Boost random library implements GRNG (Gaussian Random Number Generator) with Box-Muller transform (code herehttp://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 [1http://www.cse.cuhk.edu.hk/%7Ephwl/mt/public/archives/papers/grng_acmcs07.pd..., 2 http://mathworld.wolfram.com/Box-MullerTransformation.html, 3http://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.
The engine is supposed to produce values in [0, 1). Boost.Random uses 1-r2 to get values in (0, 1].
I've tried to compare with other scientific libraries like GSLhttp://www.gnu.org/software/gsl/manual/html_node/The-Gaussian-Distribution.h..., Scythestat http://scythe.wustl.edu/api/rng_8h-source.html and LTILibhttp://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.
You might want to take a look at https://svn.boost.org/trac/boost/ticket/1437 In Christ, Steven Watanabe
participants (2)
-
Enrique Fernández
-
Steven Watanabe