LoginSignup
1
0

More than 3 years have passed since last update.

中心極限定理をパラメータと組み合せ数でグラフ化して理解する

Posted at

グラスを作成するプログラム

Nを増やしていくと、正規分布に近くことがわかります。
parameter を減らしても、Nを増やすと正規分布に近くことがわかります。

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import math

parameter = [1,2,3,4,5,6] # 組み合わせを行うパラメータ
N = 2 # 組み合わせ数

instance = []
q = [0] * N

# パラメータのN組み合わせを作成する
def comb(n):
    n = n -1
    for v in parameter:
        q[n] = v
        if(n == 0):
            val = 0
            for c in range(N):
                val += q[c]
            instance.append(val)
            continue
        comb(n)
    return instance

#期待値, パラメータ, ヒストグラムの算出
def expectedValue(darray):
    cnt = len(darray)

    params = [darray[0]]

    for v in darray:
        if(not(v in params)):
            params.append(v)

    hist = [0] * len(params)
    cnt_h = 0
    for p in params:
        for v in darray:
            if(p == v):
               hist[cnt_h]+=1
        cnt_h+=1
    e = 0
    for i in range(len(params)):
        e += params[i] * hist[i] / cnt

    return e, params, hist


comb(N)

print(instance)

expectedValue, params , hist = expectedValue(instance)

plt.plot(params, hist)
plt.show()

パラメータ毎の例

  1. parameter = [1,2,3,4,5,6], N=2
    image.png

  2. parameter = [1,2,3,4,5,6], N=3
    image.png

  3. parameter = [1,2,3,4,5,6], N=6
    image.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0