Skip to content

About

An interactive Monte Carlo simulation and Reinforcement Learning model that solves the Monty Hall problem, proving that switching doors doubles your win rate.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚪 MonteMonty

Monte Carlo Simulation + Reinforcement Learning

MonteMonty is an interactive implementation of the famous Monty Hall Problem.

The project uses Monte Carlo simulation to demonstrate the probability difference between staying and switching doors, and Monte Carlo Reinforcement Learning to train an agent to learn the optimal strategy.

The project also includes an interactive Streamlit web application where users can play the Monty Hall game themselves.


🎯 Project Overview

The Monty Hall Problem is a probability puzzle involving three doors:

  • 🚗 One door contains a car
  • 🐐 Two doors contain goats
  • The player initially chooses one door
  • The host opens one of the remaining doors, always revealing a goat
  • The player can either Stay with their original choice or Switch to the remaining unopened door

The optimal strategy is to switch, which gives approximately a 66.7% chance of winning, compared with approximately 33.3% when staying.

MonteMonty demonstrates this result experimentally and shows how a reinforcement learning agent can learn the same strategy.


🧠 Methods

1. Monte Carlo Simulation

Thousands of Monty Hall games are simulated using two fixed strategies:

  • Always Stay
  • Always Switch

The results are compared with the theoretical probabilities.

Strategy Theoretical Win Rate
Stay ~33.3%
Switch ~66.7%

As the number of simulations increases, the experimental results converge toward these theoretical probabilities.


2. Monte Carlo Reinforcement Learning

A simple Monte Carlo reinforcement learning agent is trained to choose between:

  • stay
  • switch

The agent learns using:

  • States
  • Actions
  • Rewards
  • Q-values
  • Exploration and exploitation

The Q-value represents the expected reward of taking an action in a particular state.

After training, the agent consistently learns that:

Switching has a higher expected reward than staying.


📊 Results

After training the reinforcement learning agent for 10,000 games, the learned policy was evaluated on a separate set of 10,000 games.

Example evaluation:

Strategy Win Rate
Always Stay 33.47%
Always Switch 66.44%
Trained RL Agent 66.93%

The small difference between Always Switch and the RL Agent is due to random variation from simulation.

The important result is that the RL agent learned a strategy with performance very close to the optimal Always Switch strategy.


🌐 Streamlit Application

The Streamlit application allows users to interactively play the Monty Hall Problem.

Game flow

  1. Choose one of three doors
  2. The host reveals a goat behind another door
  3. Choose whether to Stay or Switch
  4. Reveal the result
  5. Play again

The application also displays:

  • 📊 Strategy explanation
  • 🧠 Learned Q-values
  • 🤖 The strategy learned by the RL agent

📁 Project Structure

MonteMonty/
│
├── app.py
├── requirements.txt
├── README.md
│
├── src/
│   ├── monty_hall.py
│   ├── monte_carlo.py
│   ├── rl_agent.py
│   ├── train_agent.py
│   ├── test_agent.py
│   └── compare_strategies.py
│
└── results/
    ├── q_values.json
    ├── win_rate_comparison.png
    ├── monte_carlo_convergence.png
    └── rl_learning_curve.png

About

An interactive Monte Carlo simulation and Reinforcement Learning model that solves the Monty Hall problem, proving that switching doors doubles your win rate.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages