<jupyter_start><jupyter_text>正規分布 1次元について$$p(x) = \frac{1}{\sqrt{2\pi\sigma^{2}}}\exp\left(-\frac{(x - \mu)^{2}}{2\sigma^{2}}\right)$$ この関数の解析 ステップ1 ただの指数関数$$f(x) = \exp\left(x\right)$$<jupyter_code>import numpy as np
import matplotlib.pyplot as plt

f = lambda x: np.exp(x)
xs = np.arange(0., 10., 0.2)
fxs = np.array([f(x) for x in xs])
plt.plot(xs, fxs)
plt.show()<jupyter_output><empty_output><jupyter_text>ステップ2 xについて負にする$$f(x) = \exp\left(-x\right)$$<jupyter_code>f = lambda x: np.exp(-x)
xs = np.arange(-10., 10., 0.2)
fxs = np.array([f(x) for x in xs])
plt.plot(xs, fxs)
plt.show()<jupyter_output><empty_output><jupyter_text>ステップ3 2乗する$$f(x) = \exp\left(-x^{2}\right)$$<jupyter_code>f = lambda x: np.exp(-x**2)
xs = np.arange(-10., 10., 0.2)
fxs = np.array([f(x) for x in xs])
plt.plot(xs, fxs)
plt.show()<jupyter_output><empty_output><jupyter_text>ステップ4 平行移動を表現する$$f(x) = \exp\left(-(x - \mu)^{2}\right)$$<jupyter_code>f = lambda x, u: np.exp(-(x - u)**2)
xs = np.arange(-10., 10., 0.2)
fxs = np.array([f(x, 3.) for x in xs])
plt.plot(xs, fxs)
plt.show()<jupyter_output><empty_output><jupyter_text>ステップ4 幅を変更できるようにする$$f(x) = \exp\left(-\frac{(x - \mu)^{2}}{2\sigma^{2}}\right)$$<jupyter_code>f = lambda x, u, s: np.exp(-((x - u)**2)/(2. * s**2.))
xs = np.arange(-10., 10., 0.2)
fxs = np.array([f(x, 3., 3.) for x in xs])
plt.plot(xs, fxs)
plt.show()<jupyter_output><empty_output><jupyter_text>ステップ5 積分して1になるように正規化$$p(x) = \frac{1}{\sqrt{2\pi\sigma^{2}}}\exp\left(-\frac{(x - \mu)^{2}}{2\sigma^{2}}\right)$$<jupyter_code>import numpy as np
import matplotlib.pyplot as plt

u = 3.
s = 2.
p = lambda x, u, s: 1. / np.sqrt(2. * np.pi * s**2) * np.exp(-((x - u)**2) / (2. * s**2))

xs = np.arange(-10., 15., 0.2)
pxs = np.array([p(x, u, s) for x in xs])
plt.plot(xs, pxs)
plt.show()<jupyter_output><empty_output><jupyter_text>設定した正規分布に従う確率密度関数を使ってデータを収集してみる<jupyter_code>pxs = np.array([np.random.normal(u, s) for i in range(100)])
plt.plot(pxs)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2522613065326633, 'fraction_numerical': 0.04020100502512563, 'mean_word_length': 4.821637426900585, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '37664', 'license': 'MIT', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1029, 'n_words': 165, 'path': 'stats/normal_distribution.ipynb', 'repo_name': 'fugashy/notebooks', 'size': '1990'}