16.03.2021 Views

Advanced Deep Learning with Keras

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Deep Reinforcement Learning

This will help us to focus on building a working RL algorithm. To run the code in

slow motion or delay of 1 sec per action:

$ python3 q-frozenlake-9.5.1.py -d -t=1

Mode Run Approx % Goal

Train non-slippery python3 q-frozenlake-9.5.1.py 26.0

Test non-slippery python3 q-frozenlake-9.5.1.py -d 76.0

Pure random action python3 q-frozenlake-9.5.1.py -e 1.5

non-slippery

Train slippery python3 q-frozenlake-9.5.1.py -s 26

Test slippery python3 q-frozenlake-9.5.1.py -s -d 71.0

Pure random slippery python3 q-frozenlake-9.5.1.py -s -e 1.5

Table 9.5.1: Baseline and performance of generalized Q-Learning on the

FrozenLake-v0 environment with learning rate = 0.5

Listing 9.5.1, q-frozenlake-9.5.1.py shows the implementation of Q-Learning on

FrozenLake-v0 environment:

from collections import deque

import numpy as np

import argparse

import os

import time

import gym

from gym import wrappers, logger

class QAgent():

def __init__(self,

observation_space,

action_space,

demo=False,

slippery=False,

decay=0.99):

self.action_space = action_space

# number of columns is equal to number of actions

col = action_space.n

# number of rows is equal to number of states

row = observation_space.n

# build Q Table with row x col dims

self.q_table = np.zeros([row, col])

[ 290 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!