/var/log/messages

Mar 31, 2015 - 1 minute read - Comments - Python

正規分布から 6 つの値を取得

ええと、scipy が使えるので

>>> from scipy.stats import norm

みたいなことができます。正規分布から 6 つの値取得、であれば以下なのかな。

>>> norm.rvs(size=6)
array([-0.83486486,  0.85220863, -0.96179815,  1.25632517, -2.10143098,
       -0.08796307])

ただ、ThinkStats の練習問題 8-1 は自分で書け、なのだろうな。ちなみに http://thinkstats.com/erf.py にある NormalCdf という手続きが定義されてますね。

たとえば上記の配列だと標本平均は -0.3129 とのことです。これ、mu は 0 なので、ということは mean なソレを二乗して配列に追加して平均取れば良いのか。

以下なカンジで良いのかな。

from scipy import stats
from scipy.stats import norm

def getSample(x=6):
    return norm.rvs(size=x)

def getSampleMean():
    tmp = getSample()
    return stats.describe(tmp).mean

lst = []
for var in range(0, 1000):
    lst.append(getSampleMean()**2)

print(stats.describe(lst).mean)

実行してみたら 0.167553549071 という値が出力されました。これ、中央値にしたらどうなるのかな。中央値は

stats.scoreatpercentile(lst, 50)

で取得できるのか。

def getSampleCenter():
    tmp = getSample()
    return stats.scoreatpercentile(tmp, 50)

なのかな。で、出力は 0.204170670744 と出ました。なんといえば良いかどちらも微妙スね。

GPUImage for Android nand to tetris (2)

comments powered by Disqus