This repository implements Deep Q-Learning (DQN) on the OpenAI Gymnasium LunarLander-v3 environment with three replay strategies:
- Linear Replay (Uniform): Standard experience replay drawing uniformly from past transitions.
- Prioritized Replay (PER): Samples high‑TD‑error transitions more frequently.
- Mixed Replay: Blends PER and uniform replay by a tunable ratio (
ETA).
- DQN architecture with two hidden layers (64 units each).
- Epsilon-greedy exploration with configurable decay.
- Soft target-network updates.
- Gradient clipping to stabilize training.
- Three replay buffer implementations (
linear_replay.py,priority_replay.py,MixedReplay.py). - Training curves comparison via
plot_comparison(). - Video recording of trained agents.
-
Clone the repository
git clone <your-repo-url> cd <repo-folder>
-
Create and activate a virtual environment (recommended)
python -m venv venv source venv/bin/activate # on macOS/Linux venv\\Scripts\\activate # on Windows
-
Install required Python packages
pip install --upgrade pip pip install \ gymnasium \ numpy \ torch \ matplotlib \ imageio \ pyglet # for rendering in GymnasiumInstalling Gymnasium:
pip install gymnasium
pip install "gymnasium[atari, accept-rom-license]"
pip install gymnasium[box2d]
```
4. **Local modules**
* Ensure the files `Visualization.py`, `priority_replay.py`, `linear_replay.py`, and `MixedReplay.py` are in the project root or in your Python path.
---
## Usage
1. **Run training and evaluation**
```bash
python DQN_Agent.pyThis script will:
- Train three agents (PER, Linear, Mixed) sequentially.
- Save model checkpoints under
Models/when the environment is solved. - Display and save videos of each agent’s performance.
- Plot a comparison of learning curves.
-
Configure hyperparameters
- At the top of
DQN_Agent.py, adjust constants likeLEARNING_RATE,ETA,EPSILON_DECAY, etc.
- At the top of
├── DQN_Agent.py # Main training and evaluation script
├── MixedReplay.py # Mixed replay buffer implementation
├── linear_replay.py # Uniform replay buffer implementation
├── priority_replay.py # Prioritized replay buffer implementation
├── Visualization.py # Plotting and video utilities
├── Models/ # Saved model checkpoints
└── README.md # This file
This project demonstrates how different replay strategies affect DQN performance on LunarLander-v3. You can easily switch between linear, prioritized, or mixed replay by adjusting the ETA parameter before training. The included plotting utilities help visualize and compare the learning curves of each approach.
Enjoy experimenting with replay methods and hyperparameter tuning!