Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
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
Python Reinforcement Learning

You're reading from   Python Reinforcement Learning Solve complex real-world problems by mastering reinforcement learning algorithms using OpenAI Gym and TensorFlow

Arrow left icon
Product type Course
Published in Apr 2019
Publisher Packt
ISBN-13 9781838649777
Length 496 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (4):
Arrow left icon
Yang Wenzhuo Yang Wenzhuo
Author Profile Icon Yang Wenzhuo
Yang Wenzhuo
Sean Saito Sean Saito
Author Profile Icon Sean Saito
Sean Saito
Sudharsan Ravichandiran Sudharsan Ravichandiran
Author Profile Icon Sudharsan Ravichandiran
Sudharsan Ravichandiran
Rajalingappaa Shanmugamani Rajalingappaa Shanmugamani
Author Profile Icon Rajalingappaa Shanmugamani
Rajalingappaa Shanmugamani
Arrow right icon
View More author details
Toc

Table of Contents (27) Chapters Close

Title Page
About Packt
Contributors
Preface
1. Introduction to Reinforcement Learning FREE CHAPTER 2. Getting Started with OpenAI and TensorFlow 3. The Markov Decision Process and Dynamic Programming 4. Gaming with Monte Carlo Methods 5. Temporal Difference Learning 6. Multi-Armed Bandit Problem 7. Playing Atari Games 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. Balancing CartPole 13. Simulating Control Tasks 14. Building Virtual Worlds in Minecraft 15. Learning to Play Go 16. Creating a Chatbot 17. Generating a Deep Learning Image Classifier 18. Predicting Future Stock Prices 19. Capstone Project - Car Racing Using DQN 20. Looking Ahead 1. Assessments 2. Other Books You May Enjoy Index

Car racing


So far, we have seen how to build a dueling DQN. Now, we will see how to make use of our dueling DQN when playing the car racing game.

First, let's import our necessary libraries:

import gym
import time
import logging
import os
import sys
import tensorflow as tf

Initialize all of the necessary variables:

ENV_NAME = 'Seaquest-v0'
TOTAL_FRAMES = 20000000 
MAX_TRAINING_STEPS = 20*60*60/3
TESTING_GAMES = 30
MAX_TESTING_STEPS = 5*60*60/3
TRAIN_AFTER_FRAMES = 50000
epoch_size = 50000 
MAX_NOOP_START = 30
LOG_DIR = 'logs'
outdir = 'results'
logger = tf.train.SummaryWriter(LOG_DIR)
# Intialize tensorflow session
session = tf.InteractiveSession()

Build the agent:

agent = DQN(state_size=env.observation_space.shape,
 action_size=env.action_space.n,
 session=session,
 summary_writer = logger,
 exploration_period = 1000000,
 minibatch_size = 32,
 discount_factor = 0.99,
 experience_replay_buffer = 1000000,
 target_qnet_update_frequency = 20000,
 initial_exploration_epsilon = 1.0,
 final_exploration_epsilon...
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 $19.99/month. Cancel anytime
Banner background image