Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Reinforcement Learning with Python

You're reading from   Hands-On Reinforcement Learning with Python Master reinforcement and deep reinforcement learning using OpenAI Gym and TensorFlow

Arrow left icon
Product type Paperback
Published in Jun 2018
Publisher Packt
ISBN-13 9781788836524
Length 318 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Sudharsan Ravichandiran Sudharsan Ravichandiran
Author Profile Icon Sudharsan Ravichandiran
Sudharsan Ravichandiran
Arrow right icon
View More author details
Toc

Table of Contents (16) Chapters Close

Preface 1. Introduction to Reinforcement Learning 2. Getting Started with OpenAI and TensorFlow FREE CHAPTER 3. The Markov Decision Process and Dynamic Programming 4. Gaming with Monte Carlo Methods 5. Temporal Difference Learning 6. Multi-Armed Bandit Problem 7. Deep Learning Fundamentals 8. Atari Games with Deep Q Network 9. Playing Doom with a Deep Recurrent Q Network 10. The Asynchronous Advantage Actor Critic Network 11. Policy Gradients and Optimization 12. Capstone Project – Car Racing Using DQN 13. Recent Advancements and Next Steps 14. Assessments 15. Other Books You May Enjoy

Environment wrapper functions

The credit for the code used in this chapter goes to Giacomo Spigler's GitHub repository (https://github.com/spiglerg/DQN_DDQN_Dueling_and_DDPG_Tensorflow). Throughout this chapter, the code is explained at each and every line. For a complete structured code, check the above GitHub repository.

First, we import all the necessary libraries:

import numpy as np
import tensorflow as tf
import gym
from gym.spaces import Box
from scipy.misc import imresize
import random
import cv2
import time
import logging
import os
import sys

We define the EnvWrapper class and define some of the environment wrapper functions:

class EnvWrapper:

We define the __init__ method and initialize variables:

   def __init__(self, env_name, debug=False):

Initialize the gym environment:

        self.env = gym.make(env_name)

Get the action_space:

        self.action_space = self.env.action_space...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime