资源简介
Q函数、greedy策略,强化学习基础实例,采用python语言代码实现
代码片段和文件信息
from __future__ import print_function
import copy
MAP = \
‘‘‘
.........
. .
. o .
. .
.........
‘‘‘
# MAP = \
# ‘‘‘
# .........
# . x .
# . x o .
# . .
# .........
# ‘‘‘
MAP = MAP.strip().split(‘\n‘)
MAP = [[c for c in line] for line in MAP]
DX = [-1 1 0 0]
DY = [0 0 -1 1]
class Env(object):
def __init__(self):
self.map = copy.deepcopy(MAP)
self.x = 1
self.y = 1
self.step = 0
self.total_reward = 0
self.is_end = False
def interact(self action):
assert self.is_end is False
new_x = self.x + DX[action]
new_y = self.y + DY[action]
new_pos_char = self.map[new_x][new_y]
self.step += 1
if new_pos_char == ‘.‘:
reward = 0 # do not change position
elif new_pos_char == ‘ ‘:
self.x = new_x
self.y = new_y
reward = 0
elif new_pos_char == ‘o‘:
self.x = new_x
self.y = new_y
self.map[new_x][new_y] = ‘ ‘ # update map
self.is_end = True # end
reward = 100
elif new_pos_char == ‘x‘:
self.x = new_x
self.y = new_y
self.map[new_x][new_y] = ‘ ‘ # update map
reward = -5
self.total_reward += reward
return reward
@property
def state_num(self):
rows = len(self.map)
cols = len(self.map[0])
return rows * cols
@property
def present_state(self):
cols = len(self.map[0])
return self.x * cols + self.y
def print_map(self):
printed_map = copy.deepcopy(self.map)
printed_map[self.x][self.y] = ‘A‘
print(‘\n‘.join([‘‘.join([c for c in line]) for line in printed_map]))
def print_map_with_reprint(self output_list):
printed_map = copy.deepcopy(self.map)
printed_map[self.x][self.y] = ‘A‘
printed_list = [‘‘.join([c for c in line]) for line in printed_map]
for i line in enumerate(printed_list):
output_list[i] = line
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-07-22 02:35 chapter_18\
文件 1287 2018-07-22 02:35 chapter_18\q_learning_reprint.py
文件 939 2018-07-22 02:35 chapter_18\q_learning.py
文件 2088 2018-07-22 02:35 chapter_18\env.py
文件 282 2018-07-22 02:35 chapter_18\README.md
文件 1166 2018-07-22 02:35 chapter_18\.gitignore
相关资源
- python +MYSQL+HTML实现21蛋糕网上商城
- python pygame 自制飞机大战游戏(加入
- Deep Learning Cookbook_ practical recipes to g
- django+mysql家具购物网站,包含部署教
- 正方教务系统新版sql注入漏洞利用工
- deeplearningPID
- deep learning with python 中文版
- Introduction to machine learning with python (
- Learning Data Mining With Python book 代码及数
- Introduction to Machine Learning with Python.p
- mysqlclient-1.3.13-cp36-cp36m-win32.whl
- Deep Learning for Natural Language Processing
- 基于hadoop的电影推荐系统源码.zip
- 书城购物开发web项目
- 模仿瓜子二手车的python网站
- Deep Learning With Python - Jason Brownlee
- Python-RLSeq2Seq用于SequencetoSequence模型的
- ScrapyMySQL爬取链家网中北京地区租房信
- Python-神经网络模型能够从音频演讲中
- 《深度学习Deep Learning with Python 2017》
- Learning Data Mining with Python - Second Edit
- 《深入浅出Python机器学习》源程序.
- 《强化学习导论》第二版源代码(p
- 基于协同过滤的电影推荐系统 python
- pymssql-2.1.3-cp34-cp34m-win32.whl
- Practical Machine Learning and Image Processin
- pycharm pymssql python3.6
- python+keras+deeplearning
- 基于Python的深度学习
- Hands-On Unsupervised Learning Using Python.pd
评论
共有 条评论