Monty Hall is the host of the TV game show "Let's Make a Deal" in the 60 's, the paradox is named after his name. The rules of the program are this:
Monty shows you three closed doors, one with a car behind it, and a goat behind the other two doors.
[1]
The audience in the show will wear strange clothes, hoping that Monty can choose himself.
First you can choose a door arbitrarily, of course you have a 1/3 chance to select the door behind the car.
At this point Monty will open another fan, he knows there is no car behind (this is a very important detail), and asked if you need to change your choice.
Monty know that there is a car behind that door, do you think he is designed to make you unable to get the car, or to help you? The audience under the table will also be whack, shouting their own conjecture.
Whether you should stick to your initial choice or change your choice, if you are a minute before the end of the exam, I think you should stick to your choice.
As smart as you are, if you start using your emotions at first, you lose. To get the right conclusion, we must rely on reason.
1 analysis of all possible situations
At first, if you don't know where to start thinking, you might want to assume all the things that may happen.
Assuming that the car appears behind Gate 1th,
You have chosen gate 1th, Monty will randomly open gate 2nd or 3rd, you should stick to your choice
You have chosen gate 2nd, there is a car behind gate 1th, and Monty can only open door 3rd, which should change its own choice.
You chose Gate 3rd, and the Choice Gate 2nd is exactly the same.
[2]
You see, 1/3 of the situation insisted on their choice to get the car, 2/3 of the situation change their choice can get the car
So you should change your choice.
2 using random variable analysis
To use probability theory to analyze, the most important thing is to define what the random variable is. You have to look at the problem in a third-party perspective
The location of the car must be random, your choice is also random, Monty Choice, sometimes he had to have only one choice, sometimes he can from two doors, randomly choose one, so still random
Assuming that the random variable x represents your choice, the random variable y represents the Monty open door, and the random variable z represents the location of the real car
Three random variable values, all a, B, or C, representing three doors
Also, the random variable x and the random variable Z are independent of each other, because you don't know where the car is.
The problem should be described as, you chose the door A,monty opened the door B, the probability of finding a parking space in the gate C, that is, the probability of changing the choice to get the car. And did not lose the general
The result is that a 2/3 probability change in your choice can get the car
3 Computer Simulation
If you are not interested in probability, think the probability is illusory, there is still a way to save you, that is, computer simulation. The Python programming language is used here to simulate this process.
You only need to use three random numbers to simulate the three random variables described in the previous method, and then count the number of times you have to choose to get the car and change the selection to get the distribution.
def montychoose (Guessdoor, Prizedoor): if 1! = Guessdoor and 1! = Prizedoor: return 1 if 2! = Guessdoor and 2 ! = Prizedoor: Return 2 return 3
This function is used to simulate the selection of Monty, a simple logic is that Monty can only choose the door you do not have to choose, while the door without a car
def simmontyhall (numtrials): stickwins, switchwins, Nowin = (0, 0, 0) for T in range (numtrials): #进行numTrails次实验 C7/>prizedoor = Random.choice ([1, 2, 3]) #随机生成车所在的门 guess = Random.choice ([1, 2, 3]) #随机生成你的选择 toopen = Montychoos E (guess, prizedoor) if Toopen = = Prizedoor: #模拟Monty的选择 This situation does not occur Nowin + = 1 elif guess = = prizedoor:
stickwins + = 1 else: switchwins + = 1 return (Stickwins, switchwins)
Draw the result of the function back into a pie chart
The resulting results are still consistent with the above.
When I first introduced the game rules of the show, I specifically stressed that Monty know the location of the car is very important, Monty will avoid the selected car
If Monty does not know where the car is, open a door at random, and he may open the door behind it, but it will not open the door you choose directly.
Modify the above selection function as a random selection to simulate this new situation
def randomchoose (Guessdoor, Prizedoor): if Guessdoor = = 1: return Random.choice ([2,3]) if Guessdoor = = 2: C3/>return Random.choice ([1,3]) return Random.choice ([+])
This way, whether or not you modify your choice, there is no difference
All code:
Import Pylabimport randomdef montychoose (Guessdoor, Prizedoor): if 1! = Guessdoor and 1! = Prizedoor:return 1 If 2! = Guessdoor and 2! = Prizedoor:return 2 return 3def randomchoose (Guessdoor, Prizedoor): If Guessdoor = = 1:return Random.choice ([2,3]) if Guessdoor = = 2:return Random.choice ([1,3]) return Random.choice ([+]) def simmontyhall (Numtrials, CHOOSEFCN): Stickwins, switchwins, Nowin = (0, 0, 0) prizedoorchoices = [1, 2, 3] Guesschoices = [All-in-A-z] for T in range (numtrials): Prizedoor = Random.choice ([1, 2, 3]) guess = Rand Om.choice ([1, 2, 3]) Toopen = CHOOSEFCN (guess, prizedoor) if Toopen = = Prizedoor:nowin + 1 Elif guess = = prizedoor:stickwins + 1 Else:switchwins + = 1 return (stickwins, switch Wins) def displaymhsim (Simresults, title): stickwins, switchwins = Simresults Pylab.pie ([Stickwins, Switchwins], colors = [' R ',' C '], labels = [' Stick ', ' change '], autopct = '%.2f%% ') pylab.title (title) Simresults = Simmon Tyhall (100000, Montychoose) Displaymhsim (simresults, ' Monty chooses a Door ') pylab.figure () Simresults = Simmontyhall ( 100000, Randomchoose) Displaymhsim (simresults, ' Door Chosen at Random ') pylab.show ()
[3]
Thank you very much, MIT's introduction to computer programming Open class, he opened a new door for me
If you want to know more about the problem, or want to learn more about how to simulate other problems with your computer, you can read the introduction to programming, which has recently been translated into Chinese.
21, one of my favorite movies, Professor Micky, through this question, found Ben's talent in math.
(Right-click to play)
My head can't keep up. Wow, I hope you understand my explanation.
Resources:
[1-2] Https://zh.wikipedia.org/wiki/%E8%92%99%E6%8F%90%E9%9C%8D%E7%88%BE%E5%95%8F%E9%A1%8C
[3] John v. Guttag. Introduction to computation and programming Using Python. The MIT Press. 2013.
Saying probability | Monty Hall paradox