Last active
October 8, 2016 13:24
-
-
Save kyoro1/d6a36fb75a5d2d052609fe28b28b3a88 to your computer and use it in GitHub Desktop.
正規分布N(0,1)に従う乱数ジェネレータ ref: http://qiita.com/kyoro1/items/d42fb4d146e1d8c81948
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## preparation | |
import numpy as np | |
import seaborn as sns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sns.tsplot(random_list1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
zip(random_list1,random_list2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\begin{eqnarray} | |
list1 &=& [a_0, a_1, a_2, \ldots] \\ | |
list2 &=& [b_0, b_1, b_2, \ldots] | |
\end{eqnarray} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[a_0,b_0], [a_1,b_1], [a_2,b_2] \ldots] ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
norm_list = map(lambda x: np.sqrt(-2*np.log(x[0]))*np.sin(2*np.pi*x[1]), zip(random_list1,random_list2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sns.distplot(norm_list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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