Unity with the Gaussian distribution --Part1: understanding Gaussian distribution

Original link:  https://www.alanzucconi.com/2015/09/09/understanding-the-gaussian-distribution/


  • introduction

Consider how to generate random points on a plane. These points can represent enemy, trees, or any instance. In Unity, the easiest way is:

Vector3 position = new Vector3();
position.x = Random.Range(min,max),
position.y = Random.Range(min,max);
transform.position = position;

With Random.Range can be generated at points in the blue box in the FIG. These points are uniformly dispersed in the plane, so that the density of the same point of the entire surface.

gvu

Just one of many natural phenomena are not uniformly distributed, they are more like that obey another probability distribution on the left of the red dot on the map: Gaussian distribution. The rule of thumb is: If there is a natural scene values ​​hovering around a certain value, then it is likely Gaussian distribution. E.g:

Injuries: an enemy, or the output of a weapon can cause.

Particle density: the number of (the sparks, dust, etc.) a particular particle nearby objects.

Green grass and trees: In an ecosystem distribution of trees and grasses, such as a plant location on the lake, or distribution of a mountain of stone.

 

  • Understand the uniform distribution

When you roll the dice, throw the probability of 6:00 1/6. From the perspective of probabilistic said dice is thrown from a uniform distribution of discrete values of a sampling process, as shown on the left. Each with a uniform distribution can be represented by n-sided die. The probability of being selected in each plane has the same x: 1 / n. Similar Random.Range function returns is a continuous, uniformly distributed over a range, as shown on the right.

800px-Uniform_discrete_pmf_svg.svg

In many cases, a uniform distribution is a good choice. For example, selecting one card from the deck of a random model can use it perfectly.

 

  • What is a Gaussian distribution

There are many phenomena in nature are not uniformly distributed. For example, when you measure the height of a house Azeri, you will find the number of occurrences of some value to be significantly higher than other values. Most people similar height, very high or very low, it is very rare. The room randomly choose a person, his height is likely very close to the average. These phenomena are typical Gaussian (or normal) distribution. Gaussian distribution to the probability of occurrence of a given value is:

\[P(x) = \frac{1}{{\sigma \sqrt {2\pi } }}e^{{{ - \left( {x - \mu } \right)^2 } \mathord{\left/ {\vphantom {{ - \left( {x - \mu } \right)^2 } {2\sigma ^2 }}} \right. \kern-\nulldelimiterspace} {2\sigma ^2 }}}\]

均匀分布仅有一个参数n,而高斯分布则有两个参数\ mu和 \sigma^2,分别代表均值和方差。均值反映了概率曲线的中心位置所在,而方差则显示了某个服从该分布的随机值偏离均值的可能性。

720px-Normal_Distribution_PDF.svg

若某个变量X服从高斯分布,则可将其写作:\[X \sim \mathcal{N} \left(\mu,\sigma^2\right)\]

 

  • 高斯分布示例

让人吃惊的是,高斯分布可以通过正态分布产生。尽管两者在表达式上大相径庭,却有着密切的联系。我们想象一下,有个酒鬼正在下图中走路:他从图的左侧中间点出发,每次往右走一步时,他以等概率往上/下走一步。在x步以后他最有可能走到哪儿去呢?

2000px-Random_Walk_example.svg

因为每步都是等概率的,所以上图所有的路径都是等概率发生的。然而越往两边的终点走,路线越少;越往中间走,路线越多。因此这个酒鬼最有可能待在离中心的终点附近。如果有足够多的酒鬼和足够的时间去走路,那么他们最终的位置计数图将很接近于高斯分布。

这个理论在19世纪被Francis Galton以bean machine实验验证过,如下图所示。这一实验背后隐藏着中心极限定理的思想:在自然界与生产中,一些现象受到许多相互独立的随机因素的影响,如果每个因素所产生的影响都很微小时,总的影响可以看作是服从正态分布的。

galton-board

  • 高斯分布推演

回头看看那个bean machine,想想每个球落入一个确定柱子里的概率是多少呢?

\[P\left(X=k\right)=\binom{n}{k} p^{k} \left ( 1-p \right )^{n-k}\]

这就是所谓的二项分布。只是这个式子看上去一点也不“高斯分布”,怎么办呢?

令n趋近于无穷大,将离散的数值转为连续的——

首先,要将二项式系数\[\binom{n}{k}=\frac{n!}{k!\left( n-k\right)!}\]扩展一下。这个式子由阶乘构成,而根据斯特林公式:\[n! \sim \sqrt{2\pi n}\left ( \frac{n}{e} \right ) ^n\],该式可转换成:\[\lim_{n\to\infty} \binom{n}{k} p^{k} \left ( 1-p \right )^{n-k} \simeq \frac{1}{\sqrt{2\pi n p \left(1-p \right )}} e ^{-\frac{\left( k-np \right)^2}{2np\left(1-p \right )}}\],其中e.g. = \ munp\left(1-p\right)=\sigma^2

Published 22 original articles · won praise 0 · Views 7400

Guess you like

Origin blog.csdn.net/georgeandgeorge/article/details/89413255