GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - kanand-cfd/cartpole_RL: A reinforcement learning model which learns to balance a pole over a cart.

BranchesTags
Open more actions menu

Latest commit

 

History

1 Commit
1 Commit

Folders and files

NameName
Last commit message
Last commit date
.idea
.idea
 
 
.gitignore
.gitignore
 
 
README.md
README.md
 
 
env.py
env.py
 
 
record_random_policy.py
record_random_policy.py
 
 
requirements.txt
requirements.txt
 
 
train.py
train.py
 
 
utils.py
utils.py
 
 
verify_gym.py
verify_gym.py
 
 
visualize_trained.py
visualize_trained.py
 
 

Repository files navigation

🧠 CartPole Reinforcement Learning Project

This project implements a from-scratch CartPole environment using physics, visualizes it with matplotlib, and trains a reinforcement learning agent (PPO) to balance the pole. It also records videos of both random and trained agents for comparison.


šŸ“¦ Project Structure

cartpole_rl/
ā”œā”€ā”€ env.py                 # Custom Gymnasium-compatible CartPole environment
ā”œā”€ā”€ train.py               # Trains PPO agent using Stable Baselines3
ā”œā”€ā”€ visualize.py           # Realtime cart-pole animation using matplotlib
ā”œā”€ā”€ visualize_and_save.py  # Saves trained agent animation to MP4 (with reward plot)
ā”œā”€ā”€ record_random_policy.py# Saves random policy animation to MP4
ā”œā”€ā”€ ppo_cartpole_custom.zip# Trained PPO model (after training)

🧰 Setup

python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Requirements:

gymnasium

stable-baselines3

matplotlib

opencv-python

numpy

šŸš€ Usage

  1. Train the PPO Agent
python train.py
  1. Visualize Trained Agent in Real-Time
python visualize.py
  1. Save Trained Agent Video (with rewards)
python visualize_trained.py
  1. Save Random Policy Video (for comparison)
python record_random_policy.py

šŸŽ„ Output Videos

cartpole_rl.mp4 — Trained agent balancing the pole

cartpole_random.mp4 — Untrained (random) agent failing quickly

Each video shows:

Left: live cart-pole animation

Right: reward plot over time

šŸ“š Concepts Demonstrated

Physics-based custom CartPole environment

Gymnasium API compliance

PPO reinforcement learning with Stable Baselines3

Live and saved visualizations

OpenCV + matplotlib integration

About

A reinforcement learning model which learns to balance a pole over a cart.

Resources

Readme
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800Ɨ600. No cookies required.