[PYTHON] Probability problem

What you want to do

In one thread, the same debate on the issue of probability has been going on for decades. Therefore, I would like to explain it briefly, hoping that it will help understanding.

That thread

Collect the problems of probability that are often talked about

Theme 1

I took out one card from the 52 playing cards excluding the joker and put it in the box without looking at the front. Then, when three cards were randomly selected from the ** remaining ** cards, all three were diamonds. ** At this time **, what is the probability that the card in the box is a diamond?

Answers and simulations

The answer is 0.2041 ... ($ = \ frac {13-3} {52-3} $), but to convince you, let's do it anyway.

python


%matplotlib inline
import random, numpy as np, matplotlib.pyplot as plt
random.seed(1)
r = []
for i in range(200): #See how it converges
    m, n = 0, 0
    while True:
        a = np.array(random.sample(range(52), 4)) #Choose 4 out of 53. Diamonds are less than 13.
        if (a[1:] < 13).all(): # 2,3,When the 4th sheet is all diamond
            if a[0] < 13: #Is the first piece a diamond?
                m += 1
            n += 1
            if n == 1000:
                break
    r.append(m / n) #The first piece is the ratio of diamonds
r = np.array(r)
plt.plot(r.cumsum() / range(1, r.size+1))
print(round(r.mean(), 4), round(10 / 49, 4))
>>>
0.2041 0.2041

image

It's right.

Commentary

I tried to summarize the misunderstanding patterns.

――First: Answers the probability when you put it in the box. ――The question is what you are looking for is an answer that uses the information "all three diamonds". This is wrong because I do not understand the problem statement "** at this time ". ――Second: Three diamonds are intentionally selected. ――In other words, I misunderstood that I turned all the remaining 51 cards to the front and chose 3 diamonds from them. This is a mistake because I don't understand the question sentence " randomly ". ――Third: When choosing three diamonds, you misunderstand that you chose the first one as well. --This is wrong because you do not understand the " remaining **" in the question sentence.

Theme 2

There are two envelopes with money here. One envelope contains twice as much money as the other. (In other words, one envelope contains half the money of the other) However, I don't know how much it contains. You choose only one of the two envelopes and get the money inside. When you chose one, it contained 10,000 yen. He said, "If you want, you can replace it with another envelope." Now, answer whether it is better to change it or not.

answer

Many people say that it is the same whether or not it is changed, but the answer is "I don't know."

Commentary

――First, let's consider the problem that "one envelope contains 5,000 yen or 20,000 yen. There are several probabilities of 5,000 yen." The answer is "I don't know." (Not 1/2.) ――Next, "The amount is included so that the ratio is 2 in the two envelopes. When I opened one, it was 10,000 yen. There are some probabilities that the other envelope contains 5,000 yen." Let's consider the problem. This issue is the same as the one above. So the answer is "I don't know." --If you don't know the probability, you can't calculate the expected value. Therefore, you will not know if you should replace it.

About the book "33 Thought Experiments to Train Logical Thinking"

―― “Two Envelopes ・ 2” on page 184 of the book is the same problem as the above subject 2 (except for the numbers). ――The book states that you should calculate the expected value and change it, but it is a mistake. --In order to avoid confusion, the amount will be 10,000 yen, as in the second theme, and an additional explanation will be given. ――Let's say that the possibility that the questioner chooses "5,000 yen and 10,000 yen" is p, and the possibility that the questioner chooses "10,000 yen and 20,000 yen" is q. --If "p == q", the calculation of the expected value of the book is correct, and the conclusion "should be changed" is also correct. --When N is the set of numbers that the questioner may choose, it is impossible to set "p == q" for all $ n (\ in N) $. --Therefore, it is unfounded and unnatural to assume "p == q" for a particular n. --Since the ratio of p and q is unknown, the expected value cannot be calculated. Therefore, the correct conclusion is "I don't know."

About the book "Thought Experiment Real Game For Intellectual Winning"

--The story on page 204 of the book is the same problem as subject 2 above (except for the numbers). ――The book states that you should calculate the expected value and change it, but it is a mistake. ――In order to avoid confusion, the amount will be 10,000 yen, as in the second theme, and I will explain it additionally. ――First, let's assume that the amount of money is an integer, but it is a positive continuous value. In that case, it is impossible to think that the probability that the other is "5,000 yen, 20,000 yen" is the same. Therefore, the expected value cannot be calculated. ――Next, let's assume that the amount is an integer. Then choose one amount with equal probability and double the other amount. ――In this case, the probability of "5,000 yen, 20,000 yen" is the following three patterns. --"100% 5,000 yen" and "0% 20,000 yen" --"50% 5,000 yen" and "50% 20,000 yen" --"0% 5,000 yen" and "100% 20,000 yen" -In the case of "50% 5,000 yen" and "50% 10,000 yen", the calculation of the expected value is correct. However, there are other possibilities, and the probability of those possibilities is unknown. Therefore, the expected value for all patterns cannot be calculated. ――Finally, let's say that the amount is an integer, but you don't know how to choose the amount. The pattern is the same as above, but the probability is unknown. Therefore, the expected value cannot be calculated.

that's all