Merge branch 'master' of github.com:datawhalechina/easy-rl

This commit is contained in:
qiwang067
2023-01-23 19:32:32 +08:00
4 changed files with 170 additions and 40 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,46 +1,151 @@
## Asynchronous Methods for Deep Reinforcement Learning
## Asynchronous Methods for Deep Reinforcement Learning(深度强化学习的异步方法)
[论文地址](https://arxiv.org/abs/1602.01783)
作者Volodymyr MnihAdrià Puigdomènech BadiaMehdi MirzaAlex GravesTim HarleyTimothy P. LillicrapDavid SilverKoray Kavukcuoglu
本文贡献在于提出一种异步梯度优化框架在各类型rl算法上都有较好效果其中效果最好的就是asynchronous advantage actor-critic, A3C
单位Google DeepMindMontreal Institute for Learning Algorithms MILA, University of Montreal
- **Motivation(Why)**:基于经验回放的drl算法在一些任务上效果较差可以采用其他的方式来使用数据训练网络
- **Main Idea(What)**:使用异步并行的方式让多个agent与环境进行交互当某一个agent交互完计算梯度后就交给global进行更新更新完再同步给这个agent其他agent做同样的操作。
会议International Conference on Machine LearningICML 2016
这里给张李宏毅老师的讲解图:
论文地址https://arxiv.org/abs/1602.01783
![image-20221109213901773](https://gitee.com/xyfcw/CloudPictures/raw/master/img/image-20221109213901773.png)
论文贡献:提出一种异步梯度优化框架,在各类型强化学习算法上都有较好效果,其中效果最好的就是异步优势演员-评论员Asynchronous advantage actor-critic A3C
- **Motivation(Why)**神经网络与强化学习算法相结合可以让算法更有效但稳定性较差。通常的做法是使用经验回放来去除数据的相关性让训练更加稳定。但这个方法有两个缺点一是需要较多的内存和算力二是只适用于异策略off-policy强化学习算法。
- **Main Idea(What)**:本文提出使用异步并行的方法来代替经验回放技术,这种方法不仅可以去除数据相关性,所需资源较少,并且可以应用于多种类型强化学习方法。
框架思想较为简单,但优点很多:
### Asynchronous RL Framework异步强化学习架构
1. 适用范围广on/off policy、离散/连续型任务均可使用
本文将异步架构用于四种强化学习算法上一步Sarsa一步Q学习$n$ 步Q学习以及优势演员-评论员advantage actor-critic A2C。这里可以看到此架构对于同/异策略、基于价值/策略的强化学习算法均适用。
2. 多个agent采样数据减少数据相关性训练更稳定
异步框架有两大特点:
3. 不需要经验回放让框架不局限于off-policy同时减少内存算力消耗
1. 只使用一台带有多核CPU的机器不需要GPU。这种方式可以减少机器间的通信成本并且可以用Hogwild! 的方式进行训练。
2. 多个行动者actor/worker并行可以采取不同的策略与环境互动让数据关联性减弱从而不需要经验回放技术这使得框架可以用于同策略方法并且训练时间与行动者数量近似线性关系。
4. 相较分布式所需资源更少不用gpu使用一台多核cpu机器时间更短
先来聊聊Hogwild! ,这是框架的核心,不清楚的可参考[知乎讲解](https://zhuanlan.zhihu.com/p/30826161),下图来源此文:
![image-20221109221145358](https://gitee.com/xyfcw/CloudPictures/raw/master/img/image-20221109221145358.png)
本文使用hogwild! 方法来更新梯度,不清楚的可参考[知乎讲解](https://zhuanlan.zhihu.com/p/30826161),下图来源此文:
这里举个栗子假设网络有100个参数worker $i$传来的梯度更新了40个参数后worker $j$传来的就开始更新了,当$i$更新完后前面的一些参数被$j$被覆盖掉了,但不要紧,$i$更新完了照样把当前更新后参数同步给$i$,这就是异步的意思。
接下来介绍四种异步算法:
![image-20221109221145358](https://gitee.com/xyfcw/CloudPictures/raw/master/img/image-20221109221145358.png)
#### Asynchronous one-step Q-learning异步一步Q学习
![image-20230113230006360](https://gitee.com/xyfcw/CloudPictures/raw/master/img/image-20230113230006360.png)
- $\theta$ 和 $\theta^-$是共享的,任何线程可以修改
- 梯度累积是一个增加batch size的技巧并且可以减少覆盖其他线程更新的机会更新频率降低了
- $I_{target}$是同步两网络参数的间隔
- $I_{AsyncUpdate}$是线程更新共享参数$\theta$的间隔
这里举个栗子假设网络有100个参数worker i传来的梯度更新了40个参数后worker j就开始更新了当$i$更新完后前面的一些参数被j更新了被覆盖掉了但不要紧i更新完了照样把当前global参数同步给i这就是Asynchronous的意思。
#### Asynchronous one-step Sarsa异步一步Sarsa
A3C
与上面的异步一步Q学习相比只有目标价值target value变为了$r+\gamma Q(s^\prime,a^\prime;\theta^\prime)$,其余部分相同。
#### Asynchronous n-step Q-learning异步n步Q学习
![image-20230113231647918](https://gitee.com/xyfcw/CloudPictures/raw/master/img/image-20230113231647918.png)
- 一步法的缺点是 $r$ 只直接影响导致$r$产生的 $Q(s,a)$ 值,其他的$Q$值被间接影响。$n$步法得到的$r$可以影响前面$n$步的$Q$值,这使得通过$r$更新$Q$值更加有效。后文实验有关于两者的比较。
- 相较与一步法多了个线程专属参数$\theta^{\prime}$,这个参数在选取动作以及计算梯度的时候会使用,不受其他线程的影响,可以让训练更稳定。
#### Asynchronous advantage actor-criticA3C
![image-20221109234156910](https://gitee.com/xyfcw/CloudPictures/raw/master/img/202211092341970.png)
实验结果:
- 共享了演员,评论家两网络参数,每个线程也有自己专属的,其他的与$n$步Q学习基本一样
![image-20221110000219965](https://gitee.com/xyfcw/CloudPictures/raw/master/img/202211100002021.png)
### 实验
#### Atari游戏
在5个Atari游戏上比较算法训练速度
![image-20221110000219965](https://gitee.com/xyfcw/CloudPictures/raw/master/img/202211100002021.png)
- DQN用K40GPU异步方法用16核的CPU可以看到异步优于DQN并且$n$步方法是优于一步方法的A3C明显优于其他算法。
在57个Atari游戏上比较算法性能
![image-20230114134153685](https://gitee.com/xyfcw/CloudPictures/raw/master/img/image-20230114134153685.png)
- 把A3C与当时在Atari游戏上最好的一些算法进行比较可以看到A3C训练4天的性能强于其他算法训练8天的水平。
#### TORCS Car Racing SimulatorTORCS赛车模拟器
在比Atari游戏更难的赛车环境里检验异步算法性能
![image-20230114134919316](https://gitee.com/xyfcw/CloudPictures/raw/master/img/image-20230114134919316.png)
- 可以看到A3C也是明显优于其他算法。
#### Continuous Action Control Using the MuJoCo Physics Simulator使用MuJoCo物理模拟器进行连续动作控制
在Mujoco环境里检验A3C对于连续型动作状态任务的性能
![image-20230114145118141](https://gitee.com/xyfcw/CloudPictures/raw/master/img/image-20230114145118141.png)
- 在绝大多数任务上A3C在学习率learning rate在大范围变动下都有很好的表现。
#### Labyrinth迷宫
这是一个3D迷宫环境每一轮episode都会随机生成一个迷宫迷宫里有苹果和门智能体找到一个苹果得1分找到门得10分。找到门后智能体会被随机放到迷宫任意一个地方并且之前被找到的苹果会重新生成。一轮持续60秒结束后新的一轮重新开始。
这个环境需要智能体找到一种通用的策略因为每一轮迷宫都不一样这对智能体挑战较大但作者训练A3C后发现此算法能达到很好的效果。
#### Scalability and Data Efficiency可扩展性和数据效率
在Atari游戏上检验算法的训练时间和数据效率随着线程数变化会如何改变
![image-20230114151851212](https://gitee.com/xyfcw/CloudPictures/raw/master/img/image-20230114151851212.png)
- 作者提出用一个线程达到固定分数的时间除以$n$个线程达到分数的时间,来衡量算法通过增加线程的提速程度。结果表明训练速度会随着线程数的增加而提升,这证明异步框架可以很好地利用训练资源。
#### Robustness and Stability稳健性和稳定性
在5个Atari游戏中检验异步算法的稳健性和稳定性
A3C:
![image-20230114164256003](https://gitee.com/xyfcw/CloudPictures/raw/master/img/image-20230114164256003.png)
其他的三种异步算法:
![image-20230114164313044](https://gitee.com/xyfcw/CloudPictures/raw/master/img/image-20230114164313044.png)
- 结果表明所有的算法在学习率在大范围变化时都有较好的稳健性和稳定性。
### 总结
异步框架有几大优点:
- 效果好的同时所需资源较少
- 可以应用于同策略、异策略等多种强化学习算法
- 数据利用率高,稳定性较好
- 可以广泛结合其他算法的优点提升性能
### 参考资料
- [Hogwild!: A Lock-Free Approach to Parallelizing Stochastic Gradient Descent](https://arxiv.org/abs/1106.5730)
- [知乎讲解](https://zhuanlan.zhihu.com/p/310608740)
- [知乎讲解](https://zhuanlan.zhihu.com/p/136823256)
作者:汪聪
单位:武汉工程大学
研究方向:机器博弈,强化学习
联系方式xyfcw@qq.com

View File

@@ -20,7 +20,7 @@
| | Prioritized Experience Replay (**PER**) [[Markdown]](https://github.com/datawhalechina/easy-rl/blob/master/papers/DQN/Prioritized%20Experience%20Replay.md) [[PDF]](https://github.com/datawhalechina/easy-rl/blob/master/papers/DQN/PDF/Prioritized%20Experience%20Replay.pdf) | https://arxiv.org/abs/1511.05952 | |
| | Rainbow: Combining Improvements in Deep Reinforcement Learning (**Rainbow**) [[Markdown]](https://github.com/datawhalechina/easy-rl/blob/master/papers/DQN/Rainbow_Combining%20Improvements%20in%20Deep%20Reinforcement%20Learning.md) [[PDF]](https://github.com/datawhalechina/easy-rl/blob/master/papers/DQN/PDF/Rainbow_Combining%20Improvements%20in%20Deep%20Reinforcement%20Learning.pdf) | https://arxiv.org/abs/1710.02298 | |
| | A Distributional Perspective on Reinforcement Learning (**C51**) [[Markdown]](https://github.com/datawhalechina/easy-rl/blob/master/papers/Policy_gradient/A%20Distributional%20Perspective%20on%20Reinforcement%20Learning.md) [[PDF]](https://github.com/datawhalechina/easy-rl/blob/master/papers/Policy_gradient/PDF/A%20Distributional%20Perspective%20on%20Reinforcement%20Learning.pdf) | https://arxiv.org/abs/1707.06887 | |
| Policy -based | Asynchronous Methods for Deep Reinforcement Learning (**A3C**) [[Markdown]](https://github.com/datawhalechina/easy-rl/blob/master/papers/Policy_gradient/Asynchronous%20Methods%20for%20Deep%20Reinforcement%20Learning.md) | https://arxiv.org/abs/1602.01783 | |
| Policy -based | Asynchronous Methods for Deep Reinforcement Learning (**A3C**) [[Markdown]](https://github.com/datawhalechina/easy-rl/blob/master/papers/Policy_gradient/Asynchronous%20Methods%20for%20Deep%20Reinforcement%20Learning.md) [[PDF]](https://github.com/datawhalechina/easy-rl/blob/master/papers/Policy_gradient/PDF/Asynchronous%20Methods%20for%20Deep%20Reinforcement%20Learning.pdf) | https://arxiv.org/abs/1602.01783 | |
| | Trust Region Policy Optimization (**TRPO**) [[Markdown]](https://github.com/datawhalechina/easy-rl/blob/master/papers/Policy_gradient/Trust%20Region%20Policy%20Optimization.md) [[PDF]](https://github.com/datawhalechina/easy-rl/blob/master/papers/Policy_gradient/PDF/Trust%20Region%20Policy%20Optimization.pdf) | https://arxiv.org/abs/1502.05477 | |
| | High-Dimensional Continuous Control Using Generalized Advantage Estimation (**GAE**) [[Markdown]](https://github.com/datawhalechina/easy-rl/blob/master/papers/Policy_gradient/High-Dimensional%20Continuous%20Control%20Using%20Generalized%20Advantage%20Estimation.md) [[PDF]](https://github.com/datawhalechina/easy-rl/blob/master/papers/Policy_gradient/PDF/High-Dimensional%20Continuous%20Control%20Using%20Generalised%20Advantage%20Estimation.pdf) | https://arxiv.org/abs/1506.02438 | |
| | Proximal Policy Optimization Algorithms (**PPO**) [[Markdown]](https://github.com/datawhalechina/easy-rl/blob/master/papers/Policy_gradient/Proximal%20Policy%20Optimization%20Algorithms.md) [[PDF]](https://github.com/datawhalechina/easy-rl/blob/master/papers/Policy_gradient/PDF/Proximal%20Policy%20Optimization%20Algorithms.pdf) | https://arxiv.org/abs/1707.06347 | |
@@ -39,7 +39,12 @@
| | Soft Actor-Critic: Off-Policy Maximum Entropy Deep Reinforcement Learning with a Stochastic Actor (**SAC**) [[Markdown]](https://github.com/datawhalechina/easy-rl/blob/master/papers/Policy_gradient/Soft%20Actor-Critic_Off-Policy%20Maximum%20Entropy%20Deep%20Reinforcement%20Learning%20with%20a%20Stochastic%20Actor.md) [[PDF]](https://github.com/datawhalechina/easy-rl/blob/master/papers/Policy_gradient/PDF/Soft%20Actor-Critic_Off-Policy%20Maximum%20Entropy%20Deep%20Reinforcement%20Learning%20with%20a%20Stochastic%20Actor.pdf) | https://arxiv.org/abs/1801.01290 | |
| Multi-Agent | IQL | https://web.media.mit.edu/~cynthiab/Readings/tan-MAS-reinfLearn.pdf | |
| | VDN | https://arxiv.org/abs/1706.05296 | |
| | QTRAN | http://proceedings.mlr.press/v97/son19a/son19a.pdf | |
| | QMIX | https://arxiv.org/abs/1803.11485 | |
| | Weighted QMIX | https://arxiv.org/abs/2006.10800 | |
| | COMA | https://ojs.aaai.org/index.php/AAAI/article/download/11794/11653 | |
| | MAPPO | https://arxiv.org/abs/2103.01955 | |
| | MADDPG | | |
| Sparse reward | Hierarchical DQN | https://arxiv.org/abs/1604.06057 | |
| | ICM | https://arxiv.org/pdf/1705.05363.pdf | |
| | HER | https://arxiv.org/pdf/1707.01495.pdf | |