Giter Site home page Giter Site logo

jokoum / reinforcement-learning-vs-control-theory Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 398 KB

Agent versus Controller approach in balancing CartPole system.

Python 100.00%
reinforcement-learning linear-quadratic-regularator gym-environment q-learning python cartpole-v0 control-systems gym

reinforcement-learning-vs-control-theory's Introduction

Agent versus Controller approach in balancing CartPole system.


Project inspired by Optimal Control with OpenAI Gym and Using Q-Learning to solve the CartPole balancing problem articles.

In this project two different approaches of the famous cart pole balancing problem are investigated. The first utilizes the classic Control Theory, with a State Feedback Controller while the second one utilizes a Q-learning ε-greedy Reinforcement Learning approach. The main difference of the two approaches is that in Control Theory we assume that the underlying system dynamics are known in advance, while in Reinforcement Learning the agent either learns a model of the system dynamics (model-based reinforcement learning) or tries to solve a task without a model (model-free reinforcement learning).

The CartPole-v1 environment from OpenAI Gym was used for the experiments that took place.


The State Feedback Controller approach

The control mechanism utilizes a Linear Quadratic Regulator (LQR) for the cost function minimization:

The system is described by the following equation:

or

LQR tries to find an optimal control matrix K by minimizing the cost function:

the feedback control law that minimizes the cost function is:

where K is given by

and P is found by solving the continuous time Riccati differential equation:

Results produced at one of the experiments

Cart position and velocity along with pole angle and angular velocity figures in each time step are presented below:


The Q-learning ε-greedy approach

Q-learning is a Reinforcement Learning algorithm that relies on an agent updating its action-value pair functions towards maximizing its rewards. A principal property of Q-learning algorithm is off-policy learning where it converges to an optimal policy even when acting suboptimally. In this experiment the ε-greedy policy was used, where the agent, instead of acting greedily, selects randomly with a small probability ε one of the available actions and not the one with max reward.

In the implemented approach, epsilon value was set to 1 (higher exploration) and got reduced by 0.01 per episode until reaching 0.01 (higher exploitation).

  • Results produced at one of the experiments (ε-greedy approach doesn't always produce same results)

Cart position and velocity along with pole angle and angular velocity figures in each time step are presented below:

Total iterations (balance pole without exceeding threshold) per episode are shown at the figure below:


You can clone the project from repository using the following command:
git clone https://github.com/JoKoum/reinforcement-learning-vs-control-theory.git
You can create a new virtual environment and install the dependencies using the requirements.txt file:

On macOS and Linux:

python3 -m venv <env>

On Windows:

py - m venv <env>

Package installation using requirements.txt file:

pip install -r requirements.txt

reinforcement-learning-vs-control-theory's People

Contributors

jokoum avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

raphateixeira

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.