Harness the power of reinforcement learning to master the classic CartPole balancing challenge.
The project applies the REINFORCE algorithm, enabling an agent to adeptly balance a pole on a cart. Underpinned by a neural network, the agent evolves its capabilities, with all training advancements, including hyperparameter fine-tuning, elegantly visualized and logged via TensorBoard.
- Python 3.x (tested on 3.10)
- pip
- Clone this repository to your local machine.
- Navigate to the project directory and install the required libraries using the
requirements.txtfile:pip install -r requirements.txt
-
Run the main training script:
python main.py
-
To visualize training progress, use TensorBoard:
tensorboard --logdir=cartpole_tensorboard
- Hyperparameter Grid Search: Comprehensive exploration of parameter space to optimize performance.
- Visualization: The
utils.pyoffers robust tools for plotting learning curves and visual demonstrations of the agent's expertise. - Policy Network: A lean and efficient neural network, as detailed in
model.py, underpins the agent's policy. - Trajectory Collection and Training: The
policy.pyequips users with functions for trajectory collection and REINFORCE algorithm-based training.
Visual insights into the project's performance:
- Hyperparameter Grid Search:

- Learning Curve (Average of 10 runs):

- Learning Process Visualization:

- Sample Learning Curve:

- Sample Performance:

All trained models are diligently saved in the assets/saved_models directory. As an example, the model trained with a
hidden layer of size 4 is available here.
Your contributions are welcomed:
- Fork the Project.
- Establish your Feature Branch (
git checkout -b feature/AmazingFeature). - Commit the Changes (
git commit -m 'Introduce AmazingFeature'). - Push to the Branch (
git push origin feature/AmazingFeature). - Open a Pull Request.
This project is licensed under the MIT License. Refer to LICENSE for detailed information.