User:Halibobo123/Box–Muller transform
![](http://upload.wikimedia.org/wikipedia/commons/thumb/1/1f/Box-Muller_transform_visualisation.svg/300px-Box-Muller_transform_visualisation.svg.png)
Box–Muller变换是乔治·爱德华·佩勒姆·巴克斯(George Edward Pelham Box)和莫文·埃德加·穆勒(Mervin Edgar Muller) [1]提出的一种方法,用于在给定均匀分布随机数源的情况下生成一对服从独立标准正态分布(期望为0,单位方差)的随机数。这种方法实际上是由雷蒙德-佩利(Raymond E. A. C. Paley)和诺伯特-维纳(Norbert Wiener)于1934第一次明确提及。
Box-Muller变换通常有两种形式。Box 和 Muller 所给出的基本形式是从区间 [0, 1] 上的均匀分布中抽取两个样本,并将其映射为两个标准的正态分布样本。极坐标形式从不同的区间 [-1, +1] 提取两个样本,并将其映射为两个正态分布样本,而无需使用正弦或余弦函数。
Box-Muller 变换是作为一种计算效率更高的逆变换采样的替代方法而开发的。[2]ziggurat 算法为标量处理器(如老式 CPU)提供了一种更高效的方法,而 Box-Muller 变换则更适用于具有矢量单元的处理器(如 GPU 或现代 CPU)。[3]
基本形式
[edit]假设 U1 和 U2 是从单位区间[0,1]上的均匀分布中抽出的独立样本。
使
和
这一推导[4]基于二维直角坐标系的一个特性,即 X 和 Y 坐标由两个独立的正态分布随机变量描述,相应极坐标中R2和Θ(如上图所示)的随机变量也是独立的,可表示为
和
由于R2是标准二元正态变量(X,Y)的正态平方,因此它具有两个自由度的卡方分布。在两个自由度的特殊情况下,卡方分布与指数分布重合,上述R2的方程是生成所需的指数变量的简单方法。
极坐标形式
[edit]![](http://upload.wikimedia.org/wikipedia/commons/thumb/d/d4/BoxMullerTransformUsingPolarCoordinates.png/400px-BoxMullerTransformUsingPolarCoordinates.png)
极坐标形式最早由 J. Bell[5]提出,后经 R. Knop[6]修改。虽然极坐标方法有几个不同的版本,但 R. Knop 的版本在此介绍,因为它使用最广泛,部分原因是它被收录在Numerical Recipes 中。D. Knuth 在The Art of Computer Programming[7]一书中以 "算法P "描述了一种略有不同的形式。
给定独立且均匀分布在封闭区间 [-1, +1] 内的 u 和 v,设 s = R2 = u2 + v2。如果 s = 0 或 s ≥ 1,则舍弃 u 和 v,尝试另一对 (u, v)。因为 u 和 v 是均匀分布的,而且只接受了单位圆内的点,所以 s 的值也将均匀分布在开放区间(0,1)内。通过计算 s 在区间(0,1)内的累积分布函数得到后者。这就是一个半径为的圆。由此我们可以发现概率密度函数在区间 (0, 1) 上的常值为 1。同样,均匀分布在区间 [0, 1],且与 s 相独立。
We now identify the value of s with that of U1 and with that of U2 in the basic form. As shown in the figure, the values of and in the basic form can be replaced with the ratios and , 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.
和
两种形式的对比
[edit]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. [8]Avoiding the use of expensive trigonometric functions improves speed over the basic form.[9] 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.[10] 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
参考文献
[edit]- Howes, Lee; Thomas, David (2008). GPU Gems 3 - Efficient Random Number Generation and Application Using CUDA. Pearson Education, Inc. ISBN 978-0-321-51526-1.
- ^ Box, G. E. P.; Muller, Mervin E. (1958). "A Note on the Generation of Random Normal Deviates". The Annals of Mathematical Statistics. 29 (2): 610–611. doi:10.1214/aoms/1177706645. JSTOR 2237361.
- ^ Kloeden and Platen, Numerical Solutions of Stochastic Differential Equations, pp. 11–12
- ^ Howes & Thomas 2008.
- ^ Sheldon Ross, A First Course in Probability, (2002), pp. 279–281
- ^ Bell, James R. (1968). "Algorithm 334: Normal random deviates". Communications of the ACM. 11 (7): 498. doi:10.1145/363397.363547.
- ^ Knop, R. (1969). "Remark on algorithm 334 [G5]: Normal random deviates". Communications of the ACM. 12 (5): 281. doi:10.1145/362946.362996.
- ^ Knuth, Donald (1998). The Art of Computer Programming: Volume 2: Seminumerical Algorithms. p. 122. ISBN 0-201-89684-2.
- ^ Everett F. Carter, Jr., The Generation and Application of Random Numbers, Forth Dimensions (1994), Vol. 16, No. 1 & 2.
- ^ Bell, James R. (1968). "Algorithm 334: Normal random deviates". Communications of the ACM. 11 (7): 498. doi:10.1145/363397.363547.
- ^ The evaluation of 2πU1 is counted as one multiplication because the value of 2π can be computed in advance and used repeatedly.
External links
[edit][[Category:带有C++代码示例的条目]] [[Category:變換]]