Skip to content

Instantly share code, notes, and snippets.

@kyoro1
Last active October 8, 2016 13:24
Show Gist options
  • Save kyoro1/d6a36fb75a5d2d052609fe28b28b3a88 to your computer and use it in GitHub Desktop.
Save kyoro1/d6a36fb75a5d2d052609fe28b28b3a88 to your computer and use it in GitHub Desktop.
正規分布N(0,1)に従う乱数ジェネレータ ref: http://qiita.com/kyoro1/items/d42fb4d146e1d8c81948
\begin{eqnarray}
X_1 &=& \sqrt{-2\log(U_1)}\cos(2\pi U_2) \\
X_2 &=& \sqrt{-2\log(U_2)}\sin(2\pi U_1)
\end{eqnarray}
## preparation
import numpy as np
import seaborn as sns
## Sample size
N = 10000
## Uniform distributions
random_list1 = [np.random.uniform(0,1) for i in range(N)]
random_list2 = [np.random.uniform(0,1) for i in range(N)]
sns.tsplot(random_list1)
zip(random_list1,random_list2))
\begin{eqnarray}
list1 &=& [a_0, a_1, a_2, \ldots] \\
list2 &=& [b_0, b_1, b_2, \ldots]
\end{eqnarray}
[[a_0,b_0], [a_1,b_1], [a_2,b_2] \ldots] ]
norm_list = map(lambda x: np.sqrt(-2*np.log(x[0]))*np.sin(2*np.pi*x[1]), zip(random_list1,random_list2))
sns.distplot(norm_list)
rnd = np.random.RandomState(0)
random_element = [rnd.randn() for i in range(N)]
sns.distplot(random_element)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment