美文网首页
2019-01-03[Stay Sharp]Gaussian D

2019-01-03[Stay Sharp]Gaussian D

作者: 三千雨点 | 来源:发表于2019-01-03 22:45 被阅读2次

The Gaussian Distribution

The Gaussian Distribution (Normal distribution). For a single variable x, the Gaussian distribution's equation is

\mathcal { N } ( x | \mu , \sigma ^ { 2 } ) = \frac { 1 } { \left( 2 \pi \sigma ^ { 2 } \right) ^ { 1 / 2 } } \exp \left\{ - \frac { 1 } { 2 \sigma ^ { 2 } } ( x - \mu ) ^ { 2 } \right\}
The corresponding of The Gaussian Distribution is

image.png

which is generated by the code

import matplotlib.pyplot as plt, matplotlib.mlab as mlab
import numpy as np
import math

mu = 0
variance = 1
sigma = math.sqrt(variance)
x = np.linspace(mu - 3*sigma, mu + 3*sigma, 100)
plt.plot(x, mlab.normpdf(x, mu, sigma))
plt.show()

The Central Limit Theorem

WikiPedia says, the central limit theorem (CLT) establishes that, in some situations, when independent random variables are added, their properly normalized sum tends to a Gaussian Distribution, even if the original variables themselves are not normally distributed.

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from wand.image import Image
from wand.display import display

n = 1000

avg = []
for i in range(1, n):
    a = np.random.randint(1, 7, 10)
    avg.append(np.average(a))

def clt(current):
    plt.cla()
    if current == 1000:
        a.event_source.stop()

    plt.hist(avg[0:current])
    plt.gca().set_title('Expected value of die rolls')
    plt.gca().set_xlabel('Average from die roll')
    plt.gca().set_ylabel('Frequency')

    plt.annotate('Die roll = {}'.format(current), [3, 27])

fig = plt.figure()
a = animation.FuncAnimation(fig, clt, interval=1)

References

https://medium.freecodecamp.org/how-to-visualize-the-central-limit-theorem-in-python-b619f5b00168

相关文章

网友评论

      本文标题:2019-01-03[Stay Sharp]Gaussian D

      本文链接:https://www.haomeiwen.com/subject/sblcrqtx.html