chriscx的个人博客分享 http://blog.sciencenet.cn/u/chriscx

博文

产生Gaussian分布

已有 3922 次阅读 2014-3-13 12:14 |系统分类:科研笔记

1) 按照中心极限定理,对于独立同分布的随机变量之和逼近于正态分布。

这样就可以用rand()生成的随机数,有限次相加就可以逼近正态分布了。

加上平均值和偏差也就可以模拟服从高斯分布的随机数了。

 

2)由于上述需要多次相加,计算量比较大。由此有另外一种方法就是

使用Box-Muller Transformation.

将两个独立生成的服从均匀分布的随机数U1,U2(0,1之间)。进行如下转换

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

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

即服从两个独立的正态分布。

u,v为极坐标,s为平方和开根号(半径)

s与U1对应,.scriptstyle .theta/(2 .pi)与U2对应。

 

为啥经过这个变化就可以直接得到服从正态分布的数呢。

根据Marsaglia polar method

If u is uniformly distributed in the interval 0 ≤ u < 1,
then the point (cos(2πu), sin(2πu)) is uniformly distributed on the unit circumference x2 + y2 = 1,
and multiplying that point by an independent random variable ρ whose distribution is

.Pr(.rho<a)=.int_0^a re^{-r^2/2}.,dr

will produce a point

 .left(.rho.cos(2.pi u),.rho.sin(2.pi u).right)

whose coordinates are jointly distributed as two independent standard normal random variables.

此处的u即为上述的服从均匀分布的U2

而rho,正好是上述U1的chi-2距离。正好服从上述分布

.Pr(.rho<a)=.int_0^a re^{-r^2/2}.,dr

那么就说明,产生的两个点z0,z1服从独立的正态分布。




https://blog.sciencenet.cn/blog-1126690-775566.html


下一篇:pidgin安装webqq的流程
收藏 IP: 61.150.43.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-26 09:19

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部