
Boost : 
From: Eric Ford (eford_at_[hidden])
Date: 20011001 14:14:09
> I'm just look into the normal_distribution.hpp and see it's use sin
and
> cos for calculating the result (use the BoxMuller Method), altough
it
> can be "faster" with the Polar Method (see eg:
> http://www.dspguru.com/howto/tech/wgn2.htm)
> the strange thing that the current version are faster even it use
> trigonometric functions(?) at least on a PIII with MSVC 6sp4 when
> I compile release (optimezed) code.
> (I append the patch which I made for the test at the end of this
mail).
The relative speed of the two methods depends on the speed of the
RNG. Mercene Twister generates very good RNs, but isn't the fastest.
I beleive if you substitute a fast RNG, say a linear congruential, the
loop method is likely to be faster.
I wouldn't be oppose to boost providing both methods as their relative
speed can depend on the RNG speed and also how fast the sin and cos
operations are on different hardware.
> I can't find the reason. but another intersting question if the
> current implementation use the BoxMuller Method while don't have
> a do loop:
> do {
> _r2 = _rng();
> } while (_r2 == 0);
> and what's the reason of the
> _cached_rho = sqrt(2 * log(1.0_r2));
> and not the
> _cached_rho = sqrt(2 * log(r2));
> ?
> these are just my 2c.
uniform_01 returns from [0,1), so 1_r2 is (0,1]. Answers both your
questions.
E
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk