前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >R2D2算法Buffer数据结构复现

R2D2算法Buffer数据结构复现

作者头像
用户1908973
发布2019-08-09 13:50:32
1K0
发布2019-08-09 13:50:32
举报
文章被收录于专栏:CreateAMindCreateAMind

R2D2: Recurrent Replay Distributed DQN

R2D2算法介绍:

https://mp.weixin.qq.com/s/KoFuCePBNPCXGWKpAy_wjw

算法的核心要点:

• Stored state: Storing the recurrent state in replay and using it to initialize the network at training time. This partially remedies the weakness of the zero start state strategy, however it may suffer from the effect of ‘representational drift’ leading to ‘recurrent state staleness’, as the stored recurrent state generated by a sufficiently old network could differ significantly from a typical state produced by a more recent version.

• Burn-in: Allow the network a ‘burn-in period’ by using a portion of the replay sequence only for unrolling the network and producing a start state, and update the network only on the remaining part of the sequence. We hypothesize that this allows the network to partially recover from a poor start state (zero, or stored but stale) and find itself in a better initial state before being required to produce accurate outputs.

普通强化学习Buffer:

Buffer存储的是(s, a, r, d, s')序列,数据一般为两维,第一维为batch_size,第二维为各自的维数(比如 obs_dim, act_dim), 设置Buffer的大小后进行队列存储,随机采样训练强化学习模型。

R2D2算法Buffer:

R2D2算法Buffer比普通Buffer多一维,存储的是固定长度的一段(s, a, r, d, s')序列,第一维为batch_size,第二维为序列的长度(比如 Lb+Lt),第三维为各自的维数(比如 obs_dim, act_dim), 设置Buffer的大小后进行队列存储,随机采样训练强化学习模型。

Buffer的实例化:

数据的收集:

在规定好Buffer的结构以后,改造与环境交互产生的数据使之与Buffer匹配。这里使用python库中提供的队列作为数据收集的临时存放的数据结构:

在环境reset的情况下,没有‘Burn-in’数据,可以采用生成np.zeros数据进行代替:

Lb表示‘Burn-in’数据的长度,Lt表示‘Training'数据的长度,它们的区别是是否产生强化学习Loss信号以及是否用于更新RNN网络。每隔Lt步存储一次,把队列里的数据存到Buffer里:

另外,在环境返回done=True后,需要reset,数据流将终止,同样采用生成np.zeros数据进行填满序列Lt,保存的data01用于记录数据是真实的数据(用True表示)还是np.zeros数据(用False表示)。

完整代码详见:

https://github.com/createamind/DRL/blob/master/spinup/algos/sac1_rnn/sac1_rnn.py

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-08-05,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 CreateAMind 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
对象存储
对象存储(Cloud Object Storage,COS)是由腾讯云推出的无目录层次结构、无数据格式限制,可容纳海量数据且支持 HTTP/HTTPS 协议访问的分布式存储服务。腾讯云 COS 的存储桶空间无容量上限,无需分区管理,适用于 CDN 数据分发、数据万象处理或大数据计算与分析的数据湖等多种场景。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档