Last active
April 6, 2016 05:27
-
-
Save kyoro1/89522583d316ff0362cc3bf2cbf3835b to your computer and use it in GitHub Desktop.
出現確率1%のおみくじを100回連続引けば、1回は当たる? ref: http://qiita.com/kyoro1/items/eed40ab333a9f9fd8ede
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
(1-0.01)^{100}=0.99^{100} |
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
>>> 0.99**100 | |
0.3660323412732292 |
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} | |
{}_{100} C _r\times 0.01^r\times (1-0.01)^{100-r} | |
\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
\begin{eqnarray} | |
{}_{100} C_1\times 0.01\times (1-0.01)^{99} = 100\times 0.01\times 0.99^{99}=0.3697... | |
\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
\begin{eqnarray} | |
{}_{100} C_2\times 0.01^2\times (1-0.01)^{98} = 4950\times 0.01^2\times 0.99^{98}=0.1849... | |
\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
import pandas as pd | |
import numpy as np | |
init = 0 | |
trial = 100 | |
prob = 0.01 | |
### 組み合わせを再帰的に計算 | |
def comb(n, r): | |
if n == 0 or r == 0: return 1 | |
return comb(n, r-1) * (n-r+1) / r | |
### r回当たりである確率を計算 | |
def binominal(n,r,p): | |
return comb(n,r)*(p**r)*((1-p)**(n-r)) | |
### 関数のベクトル化 | |
bi = np.vectorize(binominal) | |
### 試行回数を配列で持たせる | |
arr = np.arange(init, trial) | |
### 二項分布をベクトル演算で計算 | |
plot_values = pd.DataFrame(bi(trial, arr, prob), columns=['probability']) | |
### 図示 | |
plot_values.plot() |
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
P[X=k]\simeq \frac{\lambda^ke^{-\lambda}}{k!} |
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
P[X=k]\simeq \frac{1}{e\times k!} |
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
P[X=0]=P[X=1]=\frac{1}{e} \simeq 0.3679... |
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
P[X=2]=\frac{1}{2e}\simeq 0.1839... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment