最终回归
然后,玩扼要采取一个动作,称作 A。在象棋中,玩扼要移动一个棋子。而在 Catch 游戏中,这代表着将篮子向左、向右移动,或是保持在当前地位。据此,会获得一些嘉奖 R 和一个新状况 S’。
玩游戏的时刻,我们会产生很多「经历」,包含以下几个部分:
- 初始状况,S
- 采取的动作,A
- 获得的嘉奖,R
- 下一状况,S’
这些经历就是我们的练习数据。我们可以将估算 Q(S,A)的问题定义为回归问题。为懂得决这个问题,我们可以应用神经收集。给定一个由 S 和 A 构成的输入向量,神经收集须要能猜测 Q(S,A)的值等于目标:R + γ * max Q(S’,A’)。
如不雅我们能很好地猜测不合状况 S 和不合行动 A 的 Q(S,A),我们就能很好地切近亲近 Q 函数。请留意,我们经由过程与 Q(S,A)雷同的神经收集估算 Q(S’,A’)。
练习过程
给定一批经历 <S,A,R,S’>,其练习过程如下:
- 对于每个可能的动作 A’(向左、向右、不动),应用神经统??测预期将来嘉奖 Q(S’,A’);
- 选择 3 个预期将来嘉奖中的最大年夜值,作为 max Q(S’,A’);
- 计算 r + γ * max Q(S’,A’),这就是神经收集的目标值;
- 应用损掉函数(loss function)练习神经收集。损掉函数可以计算猜测值离目标值的距离。此处,我们应用 0.5 * (predicted_Q(S,A)—target)² 作为损掉函数。
在游戏过程中,所有的经历都邑被存储在回放存储器(replay memory)中。这就像一个存储 <S,A,R,S’> 对的简单缓存。这些经历回放类同样能用于预备练习数据。让我们看看下面的代码:
- class ExperienceReplay(object):
- """
- During gameplay all the experiences < s, a, r, s’ > are stored in a replay memory.
- In training, batches of randomly drawn experiences are used to generate the input and target for training.
- """
- def __init__(self, max_memory=100, discount=.9):
- """
- Setup
- max_memory: the maximum number of experiences we want to store
- memory: a list of experiences
- discount: the discount factor for future experience
- In the memory the information whether the game ended at the state is stored seperately in a nested array
- [...
- [experience, game_over]
- [experience, game_over]
- ...]
- """
- self.max_memory = max_memory
- self.memory = list()
推荐阅读
Tech Neo技巧沙龙 | 11月25号,九州云/ZStack与您一路商量云时代收集界线治理实践 传统小IDC存活将更难,那么必>>>详细阅读
本文标题:深度强化学习入门:用TensorFlow构建你的第一个游戏AI
地址:http://www.17bianji.com/lsqh/39071.html
1/2 1