Skip to Content
Python Deep Learning - Second Edition
book

Python Deep Learning - Second Edition

by Ivan Vasilev, Daniel Slater, Gianmario Spacagna, Peter Roelants, Valentino Zocca
January 2019
Intermediate to advanced
386 pages
11h 13m
English
Packt Publishing
Content preview from Python Deep Learning - Second Edition

Playing cart pole with A2C

In this section, we'll implement an agent that tries to play the cart pole game with the help of A2C. We'll do this with the familiar tools: the OpenAI Gym and TensorFlow. Recall that the state of the cart-pole environment is described by the position and angle of the cart and the pole. We'll use feedforward networks with one hidden layer for both the actor and the critic. Let's start!:

  1. First, we'll do the imports:
from collections import namedtupleimport gymimport matplotlib.pyplot as pltimport numpy as npimport tensorflow as tf
  1. Next, we'll create the environment:
env = gym.make('CartPole-v0')
  1. Then, we'll add some of the hyperparameters, which describe the training. We'll take the INPUT_SIZE and ACTIONS_COUNT ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Deep Learning

Python Deep Learning

Valentino Zocca, Gianmario Spacagna, Daniel Slater, Peter Roelants

Publisher Resources

ISBN: 9781789348460Supplemental Content