Jumat, 18 Mei 2018

Sponsored Links

Automated Tracking for Microscopy | Open Science
src: rsos.royalsocietypublishing.org

The Box-Muller transform, by George Edward Pelham Box and Mervin Edgar Muller, is a pseudo-random number sampling method for generating pairs of independent, standard, normally distributed (zero expectation, unit variance) random numbers, given a source of uniformly distributed random numbers. The method was in fact first mentioned by Raymond E. A. C. Paley and Norbert Wiener in 1934, and it is more likely than not that this source was well known to Box and Muller, who, however, failed to mention it in their article of 1958.

The Box-Muller transform is commonly expressed in two forms. The basic form as given by Box and Muller takes two samples from the uniform distribution on the interval [0, 1] and maps them to two standard, normally distributed samples. The polar form takes two samples from a different interval, [-1, +1], and maps them to two normally distributed samples without the use of sine or cosine functions.

The Box-Muller transform was developed as a more computationally efficient alternative to the inverse transform sampling method. The Ziggurat algorithm gives an even more efficient method. Furthermore, the Box-Muller transform can be employed for drawing from truncated bivariate Gaussian densities.


Video Box-Muller transform



Basic form

Suppose U1 and U2 are independent random variables that are from the same rectangular density function in the interval (0, 1). Let

Z 0 = R cos ( ? ) = - 2 ln U 1 cos ( 2 ? U 2 ) {\displaystyle Z_{0}=R\cos(\Theta )={\sqrt {-2\ln U_{1}}}\cos(2\pi U_{2})\,}

and

Z 1 = R sin ( ? ) = - 2 ln U 1 sin ( 2 ? U 2 ) . {\displaystyle Z_{1}=R\sin(\Theta )={\sqrt {-2\ln U_{1}}}\sin(2\pi U_{2}).\,}

Then Z0 and Z1 are independent random variables with a standard normal distribution.

The derivation is based on a property of a two-dimensional Cartesian system, where X and Y coordinates are described by two independent and normally distributed random variables, the random variables for R2 and ? (shown above) in the corresponding polar coordinates are also independent and can be expressed as

R 2 = - 2 ? ln U 1 {\displaystyle R^{2}=-2\cdot \ln U_{1}\,}

and

? = 2 ? U 2 . {\displaystyle \Theta =2\pi U_{2}.\,}

Because R2 is the square of the norm of the standard bivariate normal variable (X, Y), it has the chi-squared distribution with two degrees of freedom. In the special case of two degrees of freedom, the chi-squared distribution coincides with the exponential distribution, and the equation for R2 above is a simple way of generating the required exponential variate.


Maps Box-Muller transform



Polar form

The polar form was first proposed by J. Bell and then modified by R. Knop. While several different versions of the polar method have been described, the version of R. Knop will be described here because it is the most widely used, in part due to its inclusion in Numerical Recipes.

Given u and v, independent and uniformly distributed in the closed interval [-1, +1], set s = R2 = u2 + v2. (Clearly R = s {\displaystyle \scriptstyle R={\sqrt {s}}} ). If s = 0 or s >= 1, discard u and v, and try another pair (uv). Because u and v are uniformly distributed and because only points within the unit circle have been admitted, the values of s will be uniformly distributed in the open interval (0, 1), too. The latter can be seen by calculating the cumulative distribution function for s in the interval (0, 1). This is the area of a circle with radius s {\displaystyle \scriptstyle {\sqrt {s}}} , divided by ? {\displaystyle \scriptstyle \pi } . From this we find the probability density function to have the constant value 1 on the interval (0, 1). Equally so, the angle ? divided by 2 ? {\displaystyle \scriptstyle 2\pi } is uniformly distributed in the interval [0, 1) and independent of s.

We now identify the value of s with that of U1 and ? / ( 2 ? ) {\displaystyle \scriptstyle \theta /(2\pi )} with that of U2 in the basic form. As shown in the figure, the values of cos ? = cos 2 ? U 2 {\displaystyle \scriptstyle \cos \theta =\cos 2\pi U_{2}} and sin ? = sin 2 ? U 2 {\displaystyle \scriptstyle \sin \theta =\sin 2\pi U_{2}} in the basic form can be replaced with the ratios cos ? = u / R = u / s {\displaystyle \scriptstyle \cos \theta =u/R=u/{\sqrt {s}}} and sin ? = v / R = v / s {\displaystyle \scriptstyle \sin \theta =v/R=v/{\sqrt {s}}} , respectively. The advantage is that calculating the trigonometric functions directly can be avoided. This is helpful when trigonometric functions are more expensive to compute than the single division that replaces each one.

Just as the basic form produces two standard normal deviates, so does this alternate calculation.

z 0 = - 2 ln U 1 cos ( 2 ? U 2 ) = - 2 ln s ( u s ) = u ? - 2 ln s s {\displaystyle z_{0}={\sqrt {-2\ln U_{1}}}\cos(2\pi U_{2})={\sqrt {-2\ln s}}\left({\frac {u}{\sqrt {s}}}\right)=u\cdot {\sqrt {\frac {-2\ln s}{s}}}}

and

z 1 = - 2 ln U 1 sin ( 2 ? U 2 ) = - 2 ln s ( v s ) = v ? - 2 ln s s . {\displaystyle z_{1}={\sqrt {-2\ln U_{1}}}\sin(2\pi U_{2})={\sqrt {-2\ln s}}\left({\frac {v}{\sqrt {s}}}\right)=v\cdot {\sqrt {\frac {-2\ln s}{s}}}.}

Ecological correlates to cranial morphology in Leporids (Mammalia ...
src: dfzljdn9uc3pi.cloudfront.net


Contrasting the two forms

The polar method differs from the basic method in that it is a type of rejection sampling. It discards some generated random numbers, but can be faster than the basic method because it is simpler to compute (provided that the random number generator is relatively fast) and is more numerically robust. It avoids the use of trigonometric functions, which can be expensive in some computing environments. It discards 1 - ?/4 ? 21.46% of the total input uniformly distributed random number pairs generated, i.e. discards 4/? - 1 ? 27.32% uniformly distributed random number pairs per Gaussian random number pair generated, requiring 4/? ? 1.2732 input random numbers per output random number.

The basic form requires two multiplications, 1/2 logarithm, 1/2 square root, and one trigonometric function for each normal variate. 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 the fsincos assembler instruction or the expi instruction (usually available from C as an intrinsic function), to calculate complex

e x p ( i z ) = e i z = cos ( z ) + i sin ( z ) , {\displaystyle \mathrm {exp} (iz)=e^{iz}=\cos(z)+i\sin(z),\,}

and just separate the real and imaginary parts.

Note: To explicitly calculate the complex-polar form use the following substitutions in the general form,

Let r = - 2 l n ( u 1 ) {\displaystyle r={\sqrt {-2ln(u_{1})}}} and z = 2 ? u 2 {\displaystyle z=2\pi u_{2}} then,

  r e i z = - 2 l n ( u 1 ) e i 2 ? u 2 = - 2 l n ( u 1 ) [ cos ( 2 ? u 2 ) + i sin ( 2 ? u 2 ) ] {\displaystyle \ re^{iz}={\sqrt {-2ln(u_{1})}}e^{i2\pi u_{2}}={\sqrt {-2ln(u_{1})}}\left[\cos(2\pi u_{2})+i\sin(2\pi u_{2})\right]} .

The polar form requires 3/2 multiplications, 1/2 logarithm, 1/2 square root, and 1/2 division for each normal variate. The effect is to replace one multiplication and one trigonometric function with a single division and a conditional loop.

It should be noted that fsincos has become very fast in modern CPU architectures, such that the speed "benefit" of the rejection sampling method is no longer factual. Meanwhile, the floating-point division by s, and the conditional loop, both remain a significant expense in the rejection sampling algorithm, which are not present in the basic form.


Nanoscale simultaneous chemical and mechanical imaging via peak ...
src: advances.sciencemag.org


Tails truncation

When a computer is used to produce a uniform random variable it will inevitably have some inaccuracies because there is a lower bound on how close numbers can be to 0. If the generator uses 32 bits per output value, the smallest non-zero number that can be generated is 2 - 32 {\displaystyle 2^{-32}} . When U 1 {\displaystyle U_{1}} and U 2 {\displaystyle U_{2}} are equal to this the Box-Muller transform produces a normal random variable equal to - 2 ln ( 2 - 32 ) cos ( 2 ? 2 - 32 ) ? 6.66 {\displaystyle {\sqrt {-2\ln(2^{-32})}}\cos(2\pi 2^{-32})\approx 6.66} This means that the algorithm will not produce random variables more than 6.66 standard deviations from the mean. This corresponds to a proportion of 2.74 × 10 - 11 {\displaystyle 2.74\times 10^{-11}} lost due to the truncation.


Cell volume change through water efflux impacts cell stiffness and ...
src: www.pnas.org


Implementation

The standard Box-Muller transform generates values from the standard normal distribution (i.e. standard normal deviates) with mean 0 and standard deviation 1. The implementation below in standard C++ generates values from any normal distribution with mean ? {\displaystyle \mu } and variance ? 2 {\displaystyle \sigma ^{2}} . If Z {\displaystyle Z} is a standard normal deviate, then X = Z ? + ? {\displaystyle X=Z\sigma +\mu } will have a normal distribution with mean ? {\displaystyle \mu } and standard deviation ? {\displaystyle \sigma } . Note that because the random number generator rand has not been seeded, the same series of values will always be returned from the generateGaussianNoise function.


Retrotransposons Are the Major Contributors to the Expansion of ...
src: www.g3journal.org


See also

  • Inverse transform sampling
  • Marsaglia polar method, similar transform to Box-Muller, which uses Cartesian coordinates, instead of polar coordinates



References




External links

  • Weisstein, Eric W. "Box-Muller Transformation". MathWorld. 
  • How to Convert a Uniform Distribution to a Gaussian Distribution (C Code)

Source of the article : Wikipedia

Comments
0 Comments