离线强化学习系列3(算法篇): 值函数约束-CQL算法详解与实现
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
[更新记录]论文信息:Conservative Q-Learning for Offline Reinforcement Learning]
[Code]
本文由UC Berkeley的Sergey Levine团队(一作是Aviral Kumar)于2020年提出,并发表在NIPS2020会议上。论文的主要思想是在值基础上增加一个regularizer,学习一个保守的Q函数,作者从理论上证明了CQL可以产生一个当前策略的真实值下界,并且是可以进行策略评估和策略提升的过程。从代码的角度上来说,本文的regularizer只需要20行代码即可实现,大幅提升了实验结果。同时作者也全部opensource了代码,非常推荐研究。
摘要:在CQL算法出来之前,离线强化学习中对于分布偏移问题的解决思路是将待优化策略的动作选择限制在离线数据集的动作分布上,从而避免分布外的动作出现Q值的过估计问题,进而减少了未知的动作在策略训练学习过程中的影响,这种方法被称为策略约束(Policy constraint),比如离线强化学习中的BCQ和BEAR算法。CQL尝试通过修改值函数的back up方式,在值的基础上添加一个regularizer,得到真实动作值函数的下界估计。实验表明,CQL的表现非常好,特别是在学习复杂和多模态数据分布的时候。
1、预备知识
1.1 sample error
离线数据集是通过使用行为策略采样得到的,是折扣的边缘状态分布,,采样的过程会因为状态动作对的采样不充分产生sample error。
1.2 Operator
关于对Bellman算子的理解和策略迭代过程可以参考这篇文章,通过Bellman算子理解动态规划
1.2.1 Bellman operator
1.2.2 Empirical Bellman operator
离线数据集无法包含所有动作的转移数据,因此只能用中包含的数据进行back up,用表示。
1.2.3 Optimal Bellman operator
1.3 策略迭代
1.3.1 策略评估
当前我们在优化这个策略的过程中,会得到对应策略的值函数,根据值函数估计策略的价值。
1.3.2 策略提升
通过在函数上取极大化,然后在这个函数上面做一个贪心的搜索来进一步改进它的策略。
2、算法框架
离线强化学习算法的关键在于避免因为分布偏移导致的 值过估计问题,CQL算法直接从值函数出发,旨在找到原本 值函数的下界估计,进而使用其去优化具有更加保守的policy value的策略。在离线数据集中采样状态 ,并且 的分布要能够和 匹配: 。基于这个思路,给Q函数添加正则项使得Q的估计值变的保守。
2.1 Q_1
Q函数的更新公式:
对于任意的策略,其中。
当足够大时,,如果, 也就没有sample error,, 为 的逐点下界。
2.2 Q_2
Q函数的更新公式:
令
此时得到的估计 不一定是真实Q值的下界,但是此时策略 的值是真实值函数的下界 。
2.3 CQL
在中,,也就是说需要与当前待提升策略相同,此时策略 的值是真实值函数的下界,相仿online中策略迭代的过程,直接将定义为能够最大化Q值的策略。
添加了正则化项,如果选择是当前策略和先验策略的KL散度,那么原式就是:
最优解决方法就是,其中是正则化因子,将带回原式就得到:
令,就得到了
2.4 策略提升
使用推导出的保守Q进行策略评估,能够使得提升后的策略值依然是保守的。 保证了,修改使得到变化尽可能小,这样引起的策略批偏移也就更小。
学习到的Q值下界是:
增加了Q估计值和真实值之间的距离,使得Q更加保守。
2.5 伪代码
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
- 如果是Q-learning模式:可以作为最终的策略
- 如果是Actor-Critic模式:需要使用SAC的训练方式额外训练actor
3、结果
Gym结果
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
D4RL结果
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Atari结果
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
4、代码实现
Github Github
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
参考文献
[1]. Aviral Kumar, Aurick Zhou, George Tucker, Sergey Levine:"Conservative Q-Learning for Offline Reinforcement Learning",2020;arXiv:2006.04779.
[2]. Conservative Q-Learning