Temporal-Difference Q-learning
Introduction
- Sarsa estimates the action values of a given policy
- Q-learning estimates the optimal action values
Algorithm
- the TD target in Q-learning is
- the TD target in Sarsa is
What does Q-learning do mathematically?
It aims to solve Bellman optimality equation in terms of action values:
Off-policy vs. On-policy
在TD learning的task中一般有两个policy:
- behavior policy:用来生成experience samples
- target policy:用来不断更新towards optimal policy
那么下面就可以定义on-policy和off-policy的概念:
- : behavior policy和target policy是一样的
- : behavior policy和target policy是不一样的
Advantages of off-policy learning
It can search for the optimal policy on the experience samples generated by any other policy(behavior policy).
举例说明就是:考虑这样一种情况:我们的behavior policy是比较随机的(说好听点叫 exploratory ,比较倾向于去探索的),但是我们的target policy是比较稳定的(说好听点叫 exploitative ,比较倾向于去利用已有的信息)
- 如果这个时候用on-policy的方法去更新的话很可能会导致我们的policy不能继续优化了(因为用target policy生成的experience是比较稳定单一的结果)
- 但是如果用off-policy的方法去更新的话(此时是用behavior policy去生成丰富多样的experience),我们就仍可以继续去搜索最优的policy。
Sarsa and MC are on-policy
- Sarsa aims to evaluate a given policy by solving
- MC aims to evaluate a given policy by solving where is the return from time .
- is the behavior policy and the target policy in both cases.
Q-learning is off-policy
- Q-learning aims to solve the BOE
- the algorithm is which requires .
- the behavior policy is the one for generating in , which can be any policy.
Implementation
Version 1
Version 2
off-policy的优点其实是包括了exploration在里面,我们用 exploratory(random) 的behavior policy 去生成experience samples即可,这样我们就可以把上面的算法的-greedy的部分去掉,因为我们已经有了exploration的部分了。
Version 3
上面的算法例子非常清晰的包括了policy evaluation和policy improvement两个部分,但实际上我们发现压根就不需要把policy improvement部分写出来,因为在policy evaluation部分我们就直接得用greedy的方法去更新q值了(即只要有Q table的存在我们就可以不断更新下去),而且上面的版本的并没有写出是如何得到的,实际上在Sutton的书里6.5小结给出了更清晰的算法描述(用上一步得到的Q的greedy作为,这样再加一个-greedy decay我们就可以实现模型的从一开始的 exploration 慢慢转向 exploitation),因此再将其改动一下:
解释
w.r.t. = with respect to,这里的意思是说我们在选择action的时候是根据Q值来选择的(或者翻译成关于)。这里如果用数学来表示就是:
这里的就是我们的behavior policy,select action就是指从中采样即可。
这样做有几个优点:
- we have relatively exploration(random) behavior policy: last step’s Q
- we also have relatively exploitation(greedy) target Policy: current step’s Q
- 通过-greedy decay(随着的decay,),我们可以逐渐从exploration转向exploitation,实现了一个丝滑的转换
- 我们现在依然是off-policy的,因为我们的behavior policy和target policy是不一样的,依然保持之前的优点
- 但其实也可以一直保持一个比较小的(或者迭代到最后不不让其收敛到0,加一个小小的bias就行),这样就可以一直保持exploration的能力(就是-greedy sample的Q,而就是的Q)