资源简介
这是用DQN来走迷宫的一个代码,可以看出DQN的完整用法。
代码片段和文件信息
“““
Reinforcement learning maze example.
Red rectangle: explorer.
Black rectangles: hells [reward = -1].
Yellow bin circle: paradise [reward = +1].
All other states: ground [reward = 0].
This script is the environment part of this example.
The RL is in RL_brain.py.
View more on my tutorial page: https://morvanzhou.github.io/tutorials/
“““
import numpy as np
import time
import sys
if sys.version_info.major == 2:
import Tkinter as tk
else:
import tkinter as tk
UNIT = 40 # pixels
MAZE_H = 4 # grid height
MAZE_W = 4 # grid width
class Maze(tk.Tk object):
def __init__(self):
super(Maze self).__init__()
self.action_space = [‘u‘ ‘d‘ ‘l‘ ‘r‘]
self.n_actions = len(self.action_space)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-01-10 20:07 __pycache__\
文件 3292 2019-01-10 20:07 __pycache__\maze_env.cpython-36.pyc
文件 5017 2019-01-10 20:07 __pycache__\RL_brain.cpython-36.pyc
目录 0 2019-01-11 08:13 logs\
文件 71826 2019-01-11 08:13 logs\events.out.tfevents.1547165588.LAPTOP-N3IBU884
文件 4284 2019-01-10 16:46 maze_env.py
文件 7807 2019-01-11 08:41 RL_brain.py
文件 1393 2019-01-10 17:17 run_this.py
评论
共有 条评论