Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/konyd/deepqlearning-cartpole
This repository implements a Deep Q-Learning algorithm to train an agent to balance a pole on a cart using the CartPole-v1 environment from Gymnasium. The project includes a TensorFlow-based neural network, epsilon-greedy exploration, experience replay, and visualization of the trained agent's performance.
https://github.com/konyd/deepqlearning-cartpole
deep-learning deepq-learning gymnasium keras python tensorflow
Last synced: 4 days ago
JSON representation
This repository implements a Deep Q-Learning algorithm to train an agent to balance a pole on a cart using the CartPole-v1 environment from Gymnasium. The project includes a TensorFlow-based neural network, epsilon-greedy exploration, experience replay, and visualization of the trained agent's performance.
- Host: GitHub
- URL: https://github.com/konyd/deepqlearning-cartpole
- Owner: KonyD
- License: mit
- Created: 2025-01-26T09:46:33.000Z (5 days ago)
- Default Branch: main
- Last Pushed: 2025-01-26T09:52:57.000Z (5 days ago)
- Last Synced: 2025-01-26T10:28:18.270Z (4 days ago)
- Topics: deep-learning, deepq-learning, gymnasium, keras, python, tensorflow
- Language: Python
- Homepage:
- Size: 0 Bytes
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Deep Q-Learning with CartPole
This project implements a Deep Q-Learning (DQL) agent to solve the CartPole-v1 environment using the Gymnasium library. The agent leverages a neural network to learn the optimal policy for balancing the pole on the cart.
## Features
- **Environment:** The project uses the CartPole-v1 environment from Gymnasium.
- **Neural Network:** A fully connected feedforward neural network is implemented using TensorFlow/Keras.
- **Replay Memory:** The agent uses experience replay to train on past experiences.
- **Epsilon-Greedy Strategy:** Balances exploration and exploitation during training.
- **Training and Testing Modes:** The trained model is tested to demonstrate its performance.## Installation
1. Clone the repository:
```bash
git clone https://github.com/KonyD/DeepQLearning-CartPole.git
cd DeepQLearning-CartPole
```2. Install the required dependencies:
```bash
pip install -r requirements.txt
```## File Structure
- `main.py`: The main script containing the implementation of the DQL agent and training/testing logic.
- `requirements.txt`: List of dependencies for the project.
- `README.md`: Project documentation.## Usage
1. **Train the Agent:**
Run the script to train the agent:
```bash
python main.py
```The agent will train for a specified number of episodes and log its performance.
2. **Test the Trained Model:**
The script includes a testing phase where the trained model is evaluated in the CartPole environment.## Key Parameters
- `gamma`: Discount factor for future rewards (default: `0.95`).
- `epsilon`: Initial exploration rate (default: `1`).
- `epsilon_decay`: Decay rate for exploration (default: `0.995`).
- `epsilon_min`: Minimum exploration rate (default: `0.01`).
- `batch_size`: Size of the minibatch used for training (default: `32`).
- `episodes`: Number of training episodes (default: `50`).## Dependencies
- Python 3.8+
- Gymnasium
- TensorFlow/Keras
- NumPy
- tqdmYou can install the required libraries using the following command:
```bash
pip install -r requirements.txt
```## Results
The agent is trained to balance the pole for as long as possible. During training, the epsilon-greedy strategy ensures the agent explores the environment initially and focuses on exploitation as training progresses.
## Acknowledgments
- [OpenAI Gymnasium](https://gymnasium.farama.org/) for providing the CartPole-v1 environment.
- [TensorFlow](https://www.tensorflow.org/) for neural network implementation.## License
This project is licensed under the MIT License. See the LICENSE file for details.