3 ms·
nope, do the math edit: i ran a monty carlo simulation¹ and i was doing the math wrong. it really does matter if monty knows or not. here's the simulation wh
by kragen 3y ago
nope, do the math
edit: i ran a monty carlo simulation¹ and i was doing the math wrong. it really does matter if monty knows or not. here's the simulation where he knows:
In [15]: non_censored_trials = got_car_trials = 0
In [16]: for trial in range(100_000):
...: car_door = random.randrange(3) # the other two doors have goats
...: your_door = random.randrange(3)
...: monty_door = random.choice(list({0, 1, 2} - {your_door, car_door}))
...: if monty_door == car_door:
...: print("Monty showed the car, never mind")
...: continue
...: non_censored_trials += 1
...: your_new_choice = next(iter({0, 1, 2} - {your_door, monty_door})) # you change your choice
...: if your_new_choice == car_door:
...: print(f"You got the car because you changed from {your_door} to {your_new_choice}")
...: got_car_trials += 1
...: else:
...: print(f"Too bad you changed; you should have stuck with {your_door}")
(...output omitted...)
In [17]: got_car_trials / non_censored_trials
Out[17]: 0.66921
so in ⅔ of the cases, switching doors gets you the car. by contrast, if monty didn't know which door would reveal a car, it's only ½ of the cases:
In [21]: non_censored_trials = got_car_trials = 0
In [22]: for trial in range(100_000):
...: car_door = random.randrange(3) # the other two doors have goats
...: your_door = random.randrange(3)
...: monty_door = random.choice(list({0, 1, 2} - {your_door}))
...: if monty_door == car_door:
...: print("Monty showed the car, never mind")
...: continue
...: non_censored_trials += 1
...: your_new_choice = next(iter({0, 1, 2} - {your_door, monty_door})) # you change your choice
...: if your_new_choice == car_door:
...: print(f"You got the car because you changed from {your_door} to {your_new_choice}")
...: got_car_trials += 1
...: else:
...: print(f"Too bad you changed; you should have stuck with {your_door}")
(...output omitted...)
In [23]: got_car_trials / non_censored_trials
Out[23]: 0.49987257709086
so if monty picked the goat door on purpose, you do gain by switching. but if he just got lucky, you don't
______
¹ thank you, manoj
- dekhn 3y agoI dunno about anybody else, but to me teaching people how to convert word problems into code/simulations and how to interpret the results is one of the most important things a country that wants to be wealthy and powerful in the future should be doing. I've always admired folks who can do these sorts of things in their head, while it takes me a bunch of time to inspect the code and convince myself it's an accurate representation of the word problem.
- kragen 3y agoin this case I couldn't verify it against an actual experiment, which i think is good practice for newly programmed simulations, but when I saw that removing car_door from monty's choices made the probability go from 50% to 67%, i was reasonably sure that i hadn't fucked up the code, just the stuff i did in my head
- rspeele 3y agoOne way to think about is, suppose you switch -- why not switch back? In the random-open case, you really know nothing new about either of the closed doors. If you can talk yourself into switching, you could make an equally good argument for switching back. In the Monty-knows-and-always-shows-goat case, you have gained information about one of the closed doors. You haven't gained any information about your initial pick door. But the other remaining door, you know there's a 2/3rds chance that Monty was forced to avoid it so as not to reveal the car. Only in the 1/3rd case where you were already on the car does Monty have freedom to open either door willy nilly.
- kragen 3y agothat's all true, but i had concocted explanations that sounded equally convincing to me of why it was wrong
- topaz0 3y agoYou can tell because only trials where you chose a goat in the first round can be "censored". Your first pick is still twice as likely to be a goat as a car, but half of the times you do choose a goat on round 1 you won't get a chance to switch. Whereas if your first pick was a car, the game is guaranteed to complete (and switching is guaranteed to lose).
- kragen 3y agothis is an excellent insight; thank you
- hgomersall 3y agoBut if the car door is picked, there's no further game to play. Surely the only interesting thing to ask is, conditioned on seeing a goat, what's the probability the third door contains a car. The cases of observing a car are irrelevant since that's not the scenario. I'm still not convinced it's any different whether Monty Hall knows or not so long as the goat door is opened. Edit: having written this, thinking about the 100 door case. If 98 random doors open (that aren't the one I picked) then the fact they all contain goats is pretty suggestive that I have the car, or at least 50/50. I'm not convinced by the code example though.
- kragen 3y agoyour first paragraph is what i thought before running the simulation, but it turned out to be wrong. if my simulation isn't convincing to you, try writing one that is
- hgomersall 3y agoI'm convinced i think, just not initially by the simulator! I needed to reason my way separately but I think I'm happy with the sim now.
- topaz0 3y agoYes, it's exactly 50/50. It's not hard to work out the details, as I did in another thread elsewhere on this article. Here goes: -There's a 1/100 chance my door is a car, in which case it doesn't matter which of the others stays closed, it will always be a goat. The game will proceed, and switching will lose. -There's a 99/100 chance my door is a goat, in which case the car is behind some other door. Choosing 98 out of 99 doors to open at random is the same as choosing 1 out of 99 doors to leave closed at random. So the chance that the car stays hidden in this case (so that switching will win) is 1/99, and 98/99 that the game ends early because the car is revealed. -Adding it up, the game ends without the chance to make a choice 99/100 * 98/99 = 98/100 of the time. Of the remaining 2%, 1/100 comes from the first case (switching loses) and 99/100 * 1/99 = 1/100 comes from the second case (switching wins). The strategies are equally effective.
- 3y ago