This repository contains a Reinforcement Learning (RL) agent implemented in PyTorch to solve the LunarLander-v2 environment from the OpenAI Gym. The agent utilizes a Deep Q-Network (DQN) to learn how to control the lunar lander and safely land it on the moon's surface.
The LunarLander-v2 environment simulates the task of landing a spacecraft on the moon. The agent has control over the craft's main engine and orientation engines to maneuver and land safely. The goal is to learn a policy that maximizes the cumulative reward while safely landing on the designated landing pad.
- Deep Q-Network (DQN): The agent's neural network architecture is implemented using PyTorch. It consists of fully connected layers with ReLU activation functions.
- Replay Memory: Experience replay is utilized to store and sample past experiences for efficient training. It helps stabilize and improve the learning process.
- Target Network: A target Q-network is used to stabilize training by providing more stable target values during the learning process.
- Epsilon-Greedy Exploration: The agent balances exploration and exploitation using an epsilon-greedy policy. It selects random actions with probability epsilon and greedy actions based on the learned Q-values otherwise.
- Training Loop: The agent interacts with the environment, collects experiences, and updates its Q-network parameters using mini-batch gradient descent.
- Average Score per Episode: The training process prints the average score achieved by the agent over the last 100 episodes. This metric indicates the agent's learning progress and performance.
- Environment Solving: The environment is considered solved when the average score over the last 100 episodes exceeds 200. Upon solving, the training process stops, and the model parameters are saved.
To run the RL agent and train it to solve the LunarLander-v2 environment, follow these steps:
- Clone this repository to your local machine.
- Install the required dependencies by executing the following command:
pip install gym gym[atari,accept-rom-license] box2d torch
Ensure you have the necessary dependencies installed, including Gym and PyTorch, to execute the code successfully.
To begin training the RL agent, execute the provided code in your preferred Python environment. Adjust hyperparameters and training settings as needed for your specific requirements.
This project is licensed under the MIT License.