Offline RL : Uncertainty Weighted Actor-Critic for Offline Reinforcement Learning

ICML 2021
paper
code
利用Q的方差作为权重估计,降低OOD数据的影响程度。

Intro

在离线强化学习中,目标是在不需要探索或交互的情况下,从静态数据集中学习。现有的基于Q学习和演员-评论家算法在处理分布外(OOD)行为或状态时存在困难,这可能导致价值估计中的重大错误,从而破坏训练的稳定性。

为了解决这个问题,提出了一种名为不确定性加权演员-评论家(UWAC)的新算法。UWAC背后的关键是检测到OOD行为-状态对,相应地减少它们在训练目标中的影响。这是通过一种实用的基于dropout的不确定性估计方法实现的,防止 Q 函数对OOD数据(高不确定性)过于乐观的学习。与现有的强化学习算法相比,这种方法几乎没有额外的开销。

Method

Uncertainty estimation through dropout

采用Monte-Carlo Dropout来计算Q值不确定性: 即在训练时对每个隐藏层网络输出加入Dropout,测试时也执行Dropout,然后对同一个数据连续T次预测,然后估计方差
V a r [ Q ( s , a ) ] ≈ σ 2 + 1 T ∑ t = 1 T Q ^ t ( s , a ) ⊤ Q ^ t ( s , a ) − E [ Q ^ ( s , a ) ] ⊤ E [ Q ^ ( s , a ) ] \begin{aligned}Var[Q(s,a)]\approx\sigma^2+\frac1T\sum_{t=1}^T\hat{Q}_t(s,a)^\top\hat{Q}_t(s,a)-E[\hat{Q}(s,a)]^\top E[\hat{Q}(s,a)]\end{aligned} Var[Q(s,a)]σ2+T1t=1TQ^t(s,a)Q^t(s,a)E[Q^(s,a)]E[Q^(s,a)]

其中Dropout源代码为

def forward(self, input, return_preactivations=False):
        h = input
        for i, fc in enumerate(self.fcs):
            h = fc(h)
            if self.layer_norm and i < len(self.fcs) - 1:
                h = self.layer_norms[i](h)
            h = self.hidden_activation(h)
            h = F.dropout(h,p=self.drop_rate)
        preactivation = self.last_fc(h)
        output = self.output_activation(preactivation)
        if return_preactivations:
            return output, preactivation
        else:
            return output

基于不确定性的策略表示为
π ′ ( a ∣ s ) = β V a r [ Q 0 π ′ ( s , a ) ] π ( a ∣ s ) / Z ( s ) ; Z ( s ) = ∫ a β V a r [ Q 0 π ′ ( s , a ) ] π ( a ∣ s ) d a \begin{gathered} \pi^{\prime}(a|s) =\frac\beta{Var\left[Q_0^{\pi^{\prime}}(s,a)\right]}\pi(a|s)/Z(s); \\ Z(s) =\int_{a}\frac{\beta}{Var\left[Q_{0}^{\pi^{\prime}}(s,a)\right]}\pi(a|s)da \end{gathered} π(as)=Var[Q0π(s,a)]βπ(as)/Z(s);Z(s)=aVar[Q0π(s,a)]βπ(as)da

Uncertainty Weighted Actor-Critic

加权后对Q函数进行如下优化
L ( Q θ ) = E ( s ′ ∣ s , a ) ∼ D E a ′ ∼ π ′ ( ⋅ ∣ s ′ ) [ E r r ( s , a , s ′ , a ′ ) 2 ] = E ( s ′ ∣ s , a ) ∼ D E a ′ ∼ π ( ⋅ ∣ s ′ ) [ β V a r [ Q θ ′ ( s ′ , a ′ ) ] E r r ( s , a , s ′ , a ′ ) 2 ] E r r ( s , a , s ′ , a ′ ) = Q θ ( s , a ) − ( R ( s , a ) + γ Q θ ′ ( s ′ , a ′ ) ) . \begin{aligned} &\mathcal{L}(Q_{\theta}) = \mathbb{E}_{(s^{\prime}|s,a)\sim\mathcal{D}}\mathbb{E}_{a^{\prime}\sim\pi^{\prime}(\cdot|s^{\prime})}\left[Err(s,a,s^{\prime},a^{\prime})^{2}\right] \\ &= \mathbb{E}_{(s^{\prime}|s,a)\sim\mathcal{D}}\mathbb{E}_{a^{\prime}\sim\pi(\cdot|s^{\prime})}\left[\frac{\beta}{Var\left[Q_{\theta^{\prime}}(s^{\prime},a^{\prime})\right]}Err(s,a,s^{\prime},a^{\prime})^{2}\right] \\ &Err(s,a,s',a')=Q_{\theta}(s,a)-\left(R(s,a)+\gamma Q_{\theta'}(s',a')\right). \end{aligned} L(Qθ)=E(ss,a)DEaπ(s)[Err(s,a,s,a)2]=E(ss,a)DEaπ(s)[Var[Qθ(s,a)]βErr(s,a,s,a)2]Err(s,a,s,a)=Qθ(s,a)(R(s,a)+γQθ(s,a)).
其中归一化因子被 β \beta β吸收。同样,对策略的优化为
L ( π ) = − E a ∼ π ′ ( ⋅ ∣ s ) [ Q θ ( s , a ) ] = − E a ∼ π ( ⋅ ∣ s ) [ β V a r [ Q θ ( s , a ) ] Q θ ( s , a ) ] \begin{aligned} \mathcal{L}(\pi)& =-\mathbb{E}_{a\sim\pi^{\prime}(\cdot|s)}\left[Q_\theta(s,a)\right] \\ &=-\mathbb{E}_{a\sim\pi(\cdot|s)}\left[\frac{\beta}{Var\left[Q_{\theta}(s,a)\right]}Q_{\theta}(s,a)\right] \end{aligned} L(π)=Eaπ(s)[Qθ(s,a)]=Eaπ(s)[Var[Qθ(s,a)]βQθ(s,a)]

伪代码

在这里插入图片描述

结果

在这里插入图片描述

  • 9
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值