資源簡介
這是用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
評論
共有 條評論