Solving the Monty-Hall problem with Monte-Carlo Simulation
The Monty Hall problem is a classic probability puzzle that continues to intrigue mathematicians, statisticians, and now, machine learning enthusiasts. Here, we'll use a Monte Carlo simulation for verification.
Imagine you're on a game show facing three doors. Behind one door is a car, and behind the other two, goats. After you select a door, the host, who knows what's behind them, opens another door, revealing a goat. Now, you're given a choice: stick with your initial pick or switch to the other unopened door. What would you do? Intuition might say your odds are 50/50, but the puzzle's solution is far more intriguing: you should always switch.
The reason lies in probability. Your initial choice has a 1/3 chance of being correct. When the host opens a door with a goat, switching doors gives you a 2/3 chance of winning the car, as it essentially consolidates the probability of both remaining doors.
To empirically verify the Monty Hall problem's solution, we use a Monte Carlo simulation, which involves running numerous trials to observe outcomes and estimate probabilities.
The Monte Carlo simulation for the Monty Hall problem is straightforward but powerful. The process is as follows:
Python Code for Monte Carlo Simulation:
import numpy as np
win_switch = 0
win_stick = 0
trials = 100_000 # simulate 100,000 Monte Carlo iterations
for _ in range(trials):
car_position = np.random.randint(1, 4)
choice = np.random.randint(1, 4)
# The host reveals a goat
revealed = next(x for x in range(1, 4) if x != choice and x != car_position)
# Switch choice
switch_choice = next(x for x in range(1, 4) if x != choice and x != revealed)
win_switch += switch_choice == car_position
win_stick += choice == car_position
print(f"Winning by switching: {win_switch / trials:.4f}")
print(f"Winning by sticking: {win_stick / trials:.4f}")
Output:
Winning by switching: 0.6656
Winning by sticking: 0.3344
In conclusion, the Monty Hall problem demonstrates how our intuition about probability can often lead us astray. By employing a Monte Carlo simulation, we empirically verified that switching doors after the host reveals a goat leads to a significantly higher chance of winning the car, with a probability of approximately 2/3. This simulation provides a powerful tool for understanding and validating complex probability problems.
The key takeaways from this tutorial are: