如何在 RL 中获取 Q 值 - DDQN
How to get Q Values in RL - DDQN
我不确定如何获取 DDQN 的 Q 值。
DQN为普通网络,TAR目标网络。
q_values = self.DQN.predict(c_states) # DQN batch predict Q on states
dqn_next = self.DQN.predict(n_states) # DQN batch predict Q on next_states
tar_next = self.TAR.predict(n_states) # TAR batch predict Q on next_states
我主要找到了2个版本:
版本 1:
q_values[i][actions[i]] = (rewards[i] + (GAMMA * np.amax(tar_next[i])))
版本 2:
act = np.argmax(dqn_next[i])
q_values[i][actions[i]] = (rewards[i] + (GAMMA * tar_next[i][act]))
哪个是正确的?为什么?
版本 1 链接:
https://github.com/keon/deep-q-learning/blob/master/ddqn.py
https://pythonprogramming.net/training-deep-q-learning-dqn-reinforcement-learning-python-tutorial
版本 2 链接:
https://github.com/germain-hug/Deep-RL-Keras/blob/master/DDQN/ddqn.py
https://jaromiru.com/2016/11/07/lets-make-a-dqn-double-learning-and-prioritized-experience-replay/
编辑:
非常感谢,澄清这一点
Q-learning:
q_values[i][actions[i]] = (rewards[i] + (GAMMA * np.amax(tar_next[i])))
SARSA:
act = np.argmax(dqn_next[i])
q_values[i][actions[i]] = (rewards[i] + (GAMMA * tar_next[i][act]))
编辑:2020 年 3 月重新开放
抱歉,我必须重新打开那个问题。可能是我理解错了什么,但是下面的资料显示我的Version 2 (SARSA) 是Double Q Learning?
第 158 页:双 Q 学习
http://incompleteideas.net/book/RLbook2018.pdf
这是 Q-learning(有 max 运算符的版本)与 SARSA(没有 max 的版本)。
简而言之,您使用电子贪婪策略收集样本:这是您的行为(或探索)策略。您要学习的策略称为 "target",可以不同。
在 Q-learning 中,您使用 max 运算符,因此您的目标是根据贪婪(目标)策略选择的。这称为 off-policy learning,因为你学习了一个策略(目标)和一个不同的策略(行为)收集的样本。
对于 SARSA,没有最大值,因此在实践中,您只需使用行为策略选择的样本中的操作。这是符合策略的,因为目标和行为是相同的。
看你喜欢哪个,不过我觉得Q-learning更常见(DQN用的是Q-learning)
阅读更多相关内容
What is the difference between Q-learning and SARSA?
http://incompleteideas.net/book/RLbook2018.pdf
为 DDQN 编辑
SARSA 和 Q-learning 是两种不同的算法。
在 DDQN 中你有两个目标 Q,和两个目标策略,所以算法仍然是 off-policy(采样策略是 e-greedy,target policies 是贪婪的),而 SARSA 是 on-policy(目标策略 = 采样策略)。
DDQN 中的技巧是您在 TD 目标中使用 Q2(第二个评论家)上的最大运算符来更新 Q1(第一个评论家),反之亦然。 但是仍然有最大值,所以它仍然是 off-policy。相反,SARSA 符合政策。
DDQN有多个版本,例如一些使用Q1和Q2的最小值。这里有一些参考资料
感谢您的帮助和这里的信息leosimmons,我找到了困惑的根源:
此处使用的 Bellman 方程 Bellman equation - link 3 遵循以下方程:
value = reward + discount_factor * target_network.predict(next_state)[argmax(online_network.predict(next_state))]
原始(vanilla)DQN Bellman equation - link 2中的贝尔曼方程是:
value = reward + discount_factor * max(target_network.predict(next_state))
The difference is that, using the terminology of the field, the second
equation uses the target network for both SELECTING and EVALUATING the
action to take whereas the first equation uses the online network for
SELECTING the action to take and the target network for EVALUATING the
action. Selection here means choosing which action to take, and
evaluation means getting the projected Q value for that action. This
form of the Bellman equation is what makes this agent a Double DQN and
not just a DQN and was introduced in 3.
1 https://medium.com/@leosimmons/double-dqn-implementation-to-solve-openai-gyms-cartpole-v-0-df554cd0614d
2 https://storage.googleapis.com/deepmind-media/dqn/DQNNaturePaper.pdf
3 https://arxiv.org/pdf/1509.06461.pdf
这里解释得很好:
https://youtu.be/ILDLT97FsNM?t=331
我不确定如何获取 DDQN 的 Q 值。
DQN为普通网络,TAR目标网络。
q_values = self.DQN.predict(c_states) # DQN batch predict Q on states
dqn_next = self.DQN.predict(n_states) # DQN batch predict Q on next_states
tar_next = self.TAR.predict(n_states) # TAR batch predict Q on next_states
我主要找到了2个版本:
版本 1:
q_values[i][actions[i]] = (rewards[i] + (GAMMA * np.amax(tar_next[i])))
版本 2:
act = np.argmax(dqn_next[i])
q_values[i][actions[i]] = (rewards[i] + (GAMMA * tar_next[i][act]))
哪个是正确的?为什么?
版本 1 链接:
https://github.com/keon/deep-q-learning/blob/master/ddqn.py
https://pythonprogramming.net/training-deep-q-learning-dqn-reinforcement-learning-python-tutorial
版本 2 链接:
https://github.com/germain-hug/Deep-RL-Keras/blob/master/DDQN/ddqn.py
https://jaromiru.com/2016/11/07/lets-make-a-dqn-double-learning-and-prioritized-experience-replay/
编辑: 非常感谢,澄清这一点
Q-learning:
q_values[i][actions[i]] = (rewards[i] + (GAMMA * np.amax(tar_next[i])))
SARSA:
act = np.argmax(dqn_next[i])
q_values[i][actions[i]] = (rewards[i] + (GAMMA * tar_next[i][act]))
编辑:2020 年 3 月重新开放
抱歉,我必须重新打开那个问题。可能是我理解错了什么,但是下面的资料显示我的Version 2 (SARSA) 是Double Q Learning?
第 158 页:双 Q 学习 http://incompleteideas.net/book/RLbook2018.pdf
这是 Q-learning(有 max 运算符的版本)与 SARSA(没有 max 的版本)。
简而言之,您使用电子贪婪策略收集样本:这是您的行为(或探索)策略。您要学习的策略称为 "target",可以不同。
在 Q-learning 中,您使用 max 运算符,因此您的目标是根据贪婪(目标)策略选择的。这称为 off-policy learning,因为你学习了一个策略(目标)和一个不同的策略(行为)收集的样本。
对于 SARSA,没有最大值,因此在实践中,您只需使用行为策略选择的样本中的操作。这是符合策略的,因为目标和行为是相同的。
看你喜欢哪个,不过我觉得Q-learning更常见(DQN用的是Q-learning)
阅读更多相关内容
What is the difference between Q-learning and SARSA?
http://incompleteideas.net/book/RLbook2018.pdf
为 DDQN 编辑
SARSA 和 Q-learning 是两种不同的算法。
在 DDQN 中你有两个目标 Q,和两个目标策略,所以算法仍然是 off-policy(采样策略是 e-greedy,target policies 是贪婪的),而 SARSA 是 on-policy(目标策略 = 采样策略)。
DDQN 中的技巧是您在 TD 目标中使用 Q2(第二个评论家)上的最大运算符来更新 Q1(第一个评论家),反之亦然。 但是仍然有最大值,所以它仍然是 off-policy。相反,SARSA 符合政策。
DDQN有多个版本,例如一些使用Q1和Q2的最小值。这里有一些参考资料
感谢您的帮助和这里的信息leosimmons,我找到了困惑的根源:
此处使用的 Bellman 方程 Bellman equation - link 3 遵循以下方程:
value = reward + discount_factor * target_network.predict(next_state)[argmax(online_network.predict(next_state))]
原始(vanilla)DQN Bellman equation - link 2中的贝尔曼方程是:
value = reward + discount_factor * max(target_network.predict(next_state))
The difference is that, using the terminology of the field, the second equation uses the target network for both SELECTING and EVALUATING the action to take whereas the first equation uses the online network for SELECTING the action to take and the target network for EVALUATING the action. Selection here means choosing which action to take, and evaluation means getting the projected Q value for that action. This form of the Bellman equation is what makes this agent a Double DQN and not just a DQN and was introduced in 3.
1 https://medium.com/@leosimmons/double-dqn-implementation-to-solve-openai-gyms-cartpole-v-0-df554cd0614d
2 https://storage.googleapis.com/deepmind-media/dqn/DQNNaturePaper.pdf
3 https://arxiv.org/pdf/1509.06461.pdf
这里解释得很好: https://youtu.be/ILDLT97FsNM?t=331