O'Reilly logo

Hands-On Reinforcement Learning with Python by Sudharsan Ravichandiran

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

Swinging a pendulum

We have a pendulum that starts in a random position, and the goal of our agent is to swing the pendulum up so it stays upright. We will see how to use DDPG here. Credit for the code used in this section goes to wshuail (https://github.com/wangshuailong/reinforcement_learning_with_Tensorflow/tree/master/DDPG).

First, let's import the necessary libraries:

import tensorflow as tfimport numpy as npimport gym

Next, we define the hyperparameters as follows:

# number of steps in each episodeepsiode_steps = 500 # learning rate for actorlr_a = 0.001 # learning rate for criticlr_c = 0.002 # discount factorgamma = 0.9 # soft replacementalpha = 0.01 # replay buffer sizememory = 10000 # batch size for trainingbatch_size = 32 render ...

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