Boost logo

Boost Users :

Subject: Re: [Boost-users] Box-Muller transform Gaussian Random Number Generator
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-06-04 22:09:45


AMDG

Enrique Fernández wrote:
> 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.
>

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
> 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.
>

You might want to take a look at
https://svn.boost.org/trac/boost/ticket/1437

In Christ,
Steven Watanabe


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