Giter VIP home page Giter VIP logo

mehdishahbazi / reinforce-cart-pole-gymnasium Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 2.0 651 KB

This repo implements the REINFORCE algorithm for solving the Cart Pole V1 environment of the Gymnasium library using Python 3.8 and PyTorch 2.0.1.

License: MIT License

Python 100.00%
cart cart-pole cart-pole-balancing deep-learning deep-reinforcement-learning gym pendulum policy policy-based policy-gradient

reinforce-cart-pole-gymnasium's Introduction

Description

This repository contains the PyTorch implementation of the REINFORCE algorithm to solve the Cart Pole V1 environment provided by the Gymnasium library. In this environment, a pendulum is placed upright on a cart, and the goal is to balance the pole by applying actions (forces) in the left and right direction on the cart.

REINFORCE Algorithm

REINFORCE is a policy gradient algorithm to discover a good policy that maximizes cumulative discounted rewards. In simple terms, the core idea of the algorithm is to learn the good policy by increasing the likelihood of selecting actions with positive returns while decreasing the probability of choosing actions with negative returns using neural network function approximation. REINFORCE uses gradient ascent optimization which facilitates the learning of policies by modifying the parameters toward higher expected rewards. Hence, it is useful in policy optimization, allowing an agent to learn from its own mistakes.

Requirements

The code is implemented in Python 3.8.10 and has been tested on Windows 10 without encountering any issues. Below are the non-standard libraries and their corresponding versions used in writing the code:

gymnasium==0.29.1
numpy==1.22.0
torch==2.0.1+cu118

Note: This repository uses the latest version of Gymnasium for compatibility and optimization purposes. This code does not utilize any deprecated or old versions of the Gym library.

Usage

The network final weights are pre-saved in the root directory ./final_weights.pt. There is no need to initiate training from the beginning for testing the code. Upon executing the code, the weights will automatically be loaded, allowing seamless rendering and testing. Have fun in the environment!

Showcase

You can view the training procedure through the following GIFs, demonstrating the learned process across episodes.

Results

Here is a summary of the training outcome over 400 episodes. The plot depicts the raw rewards obtained during training.

Beyond Pendulum Balancing

Explore my solutions for various environments within the Gymnasium library, each presenting captivating challenges that showcase the exciting applications of deep reinforcement learning techniques. Some of these solved environments include:

Toy Text Environments:
  1. Frozen Lake v1 → Solved with DQN algorithm
  2. Cliff Walking v0 → Solved with DQN algorithm
Classic Control Environments:
  1. Mountain Car v0 → Solved with DQN algorithm

reinforce-cart-pole-gymnasium's People

Contributors

mehdishahbazi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.