引用来自ShangtongZhang的代码chapter04/gird_world.py
grid_world(policy evaluation)
问题描述
4X4 网格:
左上角和右下角是终止状态(terminal state),如果action使得state跳转到外面了,就返回上次位置,所有的action造成的reward都是-1。
引入模块并定义常量
1 |
|
action控制代码
1 | # judge whether comes to terminal state |
绘制方格图
1 | def draw_image(image): |
进行policy evaluation,即计算value-state
1 | def compute_state_value(in_place=False): |
运行并显示评估结果
1 | def figure_4_1(): |
In-place: 142 iterations
Synchronous: 218 iterations