Giter Site home page Giter Site logo

erfanfathi / rl_cartpole Goto Github PK

View Code? Open in Web Editor NEW
6.0 2.0 0.0 554 KB

Implementation of the Q-learning and SARSA algorithms to solve the CartPole-v1 environment. [Advance Machine Learning project - UniGe]

License: MIT License

Python 92.56% Shell 7.44%
cartpole-v1 epsilon-greedy python3 q-learning q-learning-vs-sarsa reinforcement-learning sarsa

rl_cartpole's Introduction

Reinforcement Learning on CartPole-v1

This project implements the Q-learning and SARSA algorithms to solve the CartPole-v1 environment from OpenAI Gym. The Q-learning algorithm learns an optimal action-value function, while the SARSA algorithm learns an action-value function based on the current policy. The goal is to balance a pole on a cart by applying appropriate forces.

Usage

    1. Clone the repository or download the source code files.
      git clone [email protected]:ErfanFathi/RL_Cartpole.git
    1. Install the required packages.
      pip3 install -r requirements.txt
    1. Run the script with the desired parameters. Use the following command to see the available options:
      python3 main.py --help

    This script uses command-line arguments to configure the learning parameters and other settings. You can specify the following options:

    • --algorithm: The algorithm to use for learning. Valid options are q_learning and sarsa. Default is q_learning.
    • --alpha: The learning rate. Default is 0.1.
    • --gamma: The discount factor. Default is 0.995.
    • --epsilon: The probability of choosing a random action. Default is 0.1.
    • --num_episodes: The number of episodes to run. Default is 1000.
    • --num_steps: The maximum number of steps per episode. Default is 500.
    • --num_bins: The number of bins to use for discretizing the state space. Default is 20.
  • e.g.:

     python3 main.py --algorithm q_learning --alpha 0.2 --gamma 0.99 --num_episodes 2000
    1. The script will execute the chosen algorithm on the CartPole-v1 environment. It will print the name of the generated file containing the results.
    1. After the execution, a plot of the rewards obtained during the learning process will be saved in the plots directory as a PNG file.
    1. Additionally, frames of the agent's behavior will be rendered and saved as a GIF file in the videos directory. This provides a visual representation of the learned policy.

Result

Finale

Feel free to use, modify this code. And please feel free to fork the code from Github and send pull requests.

Report any comment or bugs to:
[email protected]

Regards,
Erfan Fathi

rl_cartpole's People

Contributors

erfanfathi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.