Marsaglia Polar Method - Practical Considerations

Practical Considerations

A direct application of this idea,

is called the Box Muller transform, in which the chi variate is usually generated as

but that transform requires logarithm, square root, sine and cosine functions. On some processors, the cosine and sine of the same argument can be calculated in parallel using a single instruction. Notably for Intel based machines, one can use fsincos assembler instruction or the expi instruction (available i.e. in D), to calculate complex

and just separate the real and imaginary parts.

The polar method, in which a random point (x, y) inside the unit circle is projected onto the unit circumference by setting s = x2 + y2 and forming the point

is a faster procedure. Some researchers argue that the conditional if instruction (for rejecting a point outside of the unit circle), can make programs slower on modern processors equipped with pipelining and branch prediction. Also this procedure requires about 27% more evaluations of the underlying random number generator (only of generated points lie inside of unit circle).

That random point on the circumference is then radially projected the required random distance by means of

using the same s because that s is independent of the random point on the circumference and is itself uniformly distributed from 0 to 1.

Read more about this topic:  Marsaglia Polar Method

Famous quotes containing the word practical:

    Tried by a New England eye, or the more practical wisdom of modern times, they are the oracles of a race already in its dotage; but held up to the sky, which is the only impartial and incorruptible ordeal, they are of a piece with its depth and serenity, and I am assured that they will have a place and significance as long as there is a sky to test them by.
    Henry David Thoreau (1817–1862)