【发布时间】:2019-03-31 18:36:00
【问题描述】:
我试图在 Keras 中实现一个 q-learning 算法。根据文章,我发现了这些代码行。
for state, action, reward, next_state, done in sample_batch:
target = reward
if not done:
#formula
target = reward + self.gamma * np.amax(self.brain.predict(next_state)[0])
target_f = self.brain.predict(state)
#shape (1,2)
target_f[0][action] = target
print(target_f.shape)
self.brain.fit(state, target_f, epochs=1, verbose=0)
if self.exploration_rate > self.exploration_min:
self.exploration_rate *= self.exploration_decay
变量sample_batch 是包含来自收集的数据的样本state, action, reward, next_state, done 的数组。
我还发现了下面的q-learning公式
为什么等式(代码)中没有- 符号?我发现np.amax 返回数组的最大值或沿轴的最大值。当我打电话给self.brain.predict(next_state) 时,我得到[[-0.06427538 -0.34116858]]。那么它在这个方程中起到了预测的作用呢?随着我们前进,target_f 是当前状态的预测输出,然后我们还通过这一步将奖励附加到它上面。然后,我们在当前的state(X) 和target_f(Y) 上训练模型。我有几个问题。 self.brain.predict(next_state) 的作用是什么,为什么没有减号?为什么我们在一个模型上预测两次?前self.brain.predict(state) and self.brain.predict(next_state)[0]
【问题讨论】:
标签: python keras deep-learning reinforcement-learning q-learning