O'Reilly logo

Python Reinforcement Learning Projects by Rajalingappaa Shanmugamani, Yang Wenzhuo, Sean Saito

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

CartPole

At each step of the cart and pole, several variables can be observed, such as the position, velocity, angle, and angular velocity. The possible state_values of the cart are moved right and left:

  1. state_values: Four dimensions of continuous values.
  2. Actions: Two discrete values.
  3. The dimensions, or space, can be referred to as the state_value space and the action space. Let's start by importing the required libraries, as follows:
import gymimport numpy as npimport randomimport math
  1. Next, make the environment for playing CartPole, as follows:
environment = gym.make('CartPole-v0')
  1. Next, define the number of buckets and the number of actions, as follows:
no_buckets = (1, 1, 6, 3)no_actions = environment.action_space.n
  1. Next, define ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required