[PYTHON] If you draw an Omikuji with a probability of 1% 100 times in a row, will you win once?

This theme

In the original article that was inspired, it's not a fortune, but a gacha, but ...

When the probability becomes clear, it is meaningless unless it is understood correctly. A common mistake is the belief that if the probability of appearance is 1%, it will almost certainly come out if you draw the gacha 100 times. As a matter of fact, the probability of hitting a gacha with a probability of 1% by pulling it 100 times is only about 63%. In other words, if 100 players draw 100 times each, 63 will win, but the remaining 37 will lose 100 times. http://www.4gamer.net/games/999/G999905/20160305003/

What does that really mean? A brief introduction to the mathematical background, calculation and illustration in Python.

Probabilistically

1% chance of winning each time If you draw a gacha 100 times in a row, may you never win? !!

It is that. If you draw an Omikuji at a shrine, you can't usually restore it (instead, it will be tied to somewhere in the shrine's precincts), so each time you draw it, you will lose one from all the Omikuji. (Non-restoration extraction). In this gacha, one out of 100 lottery is always won, so it is a restoration extraction. (Speaking of Omikuji, it is equivalent to returning your lottery)

Let's calculate with Python

So

1% chance of winning each time If you draw a gacha 100 times in a row, may you never win? !!

Let's quantify. This is equivalent to pulling a loss 100 times in a row.

(1-0.01)^{100}=0.99^{100}

I hope you can calculate. If you let me calculate with python,

>>> 0.99**100
0.3660323412732292

Therefore, it will not hit even once about 0.366 ≒ 36.6% (sorry). This is the original article

The remaining 37 people are all lost 100 times.

That's the part.

Think mathematically

In this case, the non-restoration extraction is performed 100 times in a row, so the "binomial distribution" is equivalent in mathematics.

A common story is a context like "How many times does the back or front of the coin come out?", But the way the front side comes out is Ibitsu, "The probability that the front comes out is 0.01, the probability that the back comes out is 0.99" It is a situation like this. (I would like to see what kind of coin it is, but ...)

Formulation

Then, the probability of getting a r hit in 100 non-restoring extracts is

\begin{eqnarray}
{}_{100} C _r\times 0.01^r\times (1-0.01)^{100-r}
\end{eqnarray}

Let's calculate some

When r = 1

\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}

⇒It's about 0.370, so the probability of not winning even once and the probability of winning once are almost the same.

When r = 2

\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 time it is about 0.18, so the probability will suddenly be halved ...

Try drawing a probability distribution

It is difficult to think about each individual case each time, so if you draw a (probability) distribution, you can see the whole picture.

Try drawing a graph in Python

import pandas as pd
import numpy as np

init = 0
trial = 100
prob = 0.01

###Recursively calculate combinations
def comb(n, r):
    if n == 0 or r == 0: return 1
    return comb(n, r-1) * (n-r+1) / r 

###Calculate the probability of being r times
def binominal(n,r,p):
    return comb(n,r)*(p**r)*((1-p)**(n-r))

###Function vectorization
bi = np.vectorize(binominal)

###Have the number of trials in an array
arr = np.arange(init, trial)

###Calculate binomial distribution by vector operation
plot_values = pd.DataFrame(bi(trial, arr, prob), columns=['probability'])

###Illustrated
plot_values.plot()

graph.png

⇒ The peak ends near 0 and 1, and the probability is rapidly approaching 0 ... (sweat)

Poisson distribution

The distribution of ↑, the one who saw it somewhere is sharp. It's a Poisson distribution. On the "binomial distribution" page of Wikipedia If> n is large and p is small enough, then np is reasonably large, so the Poisson distribution with the parameter λ = np gives a good approximation of the binomial distribution B (n, p). That is, when the expected value λ = np is constant and n is sufficiently large,

P[X=k]\simeq \frac{\lambda^ke^{-\lambda}}{k!}

There is. We used python to calculate r = 0, 1, 2, but let's try applying k = 0, 1, 2 to the above formula. Note that λ = 100 × 0.01 = 1 is generally

P[X=k]\simeq \frac{1}{e\times k!}

So

P[X=0]=P[X=1]=\frac{1}{e} \simeq 0.3679...

And you can see that the probabilities are about the same when r = 0, 1. further,

P[X=2]=\frac{1}{2e}\simeq 0.1839...

So, in the case of r = 2, the probability of r = 0, 1 is half, which is almost correct!

Recommended Posts

If you draw an Omikuji with a probability of 1% 100 times in a row, will you win once?
You will be an engineer in 100 days --Day 63 --Programming --Probability 1
You will be an engineer in 100 days --Day 64 --Programming --Probability 2
If you give a list with the default argument of the function ...
If you want a singleton in python, think of the module as a singleton
You will be an engineer in 100 days ――Day 24 ―― Python ―― Basics of Python language 1
[Python] If you want to draw a scatter plot of multiple clusters
You will be an engineer in 100 days ――Day 30 ―― Python ―― Basics of Python language 6
You will be an engineer in 100 days ――Day 25 ―― Python ―― Basics of Python language 2
A memorandum of filter commands that you might forget in an instant
Draw a heart in Ruby with PyCall
You will be an engineer in 100 days --Day 29 --Python --Basics of the Python language 5
You will be an engineer in 100 days --Day 33 --Python --Basics of the Python language 8
You will be an engineer in 100 days --Day 26 --Python --Basics of the Python language 3
You will be an engineer in 100 days --Day 35 --Python --What you can do with Python
Test the number of times you have thrown a query (sql) in django
If you guys in the scope kitchen can do it with a margin ~ ♪
You will be an engineer in 100 days --Day 32 --Python --Basics of the Python language 7
If you get a long error when tabbing an interactive shell with Anaconda
You will be an engineer in 100 days --Day 28 --Python --Basics of the Python language 4
Even if you are a beginner in python and have less than a year of horse racing, you could win a triple.
Draw a graph of a quadratic function in Python
Draw a graph with Japanese labels in Jupyter
If you define a method in a Ruby class and define a method in it, it becomes a method of the original class.
Understand Python yield If you put yield in a function, it will change to a generator
What to do if you run python in IntelliJ and end with an error
[Python] If you create a file with the same name as the module to be imported, an Attribute Error will occur.