Post

广义优势估计:High-dimensional Continuous Control Using Generalized Advantage Estimation

针对策略梯度优势估计的问题「高方差variance、高偏差bias」提出统一框架GAE来平滑地处理variance和bias之间的平衡。

广义优势估计:High-dimensional Continuous Control Using Generalized Advantage Estimation

参考文档

# High-Dimensional Continuous Control Using Generalized Advantage Estimation

1. 背景:优势函数估计的问题所在

策略梯度可以直接优化累计奖励: Policy gradient methods are an appealing approach in reinforcement learning because they directly optimize the cumulative reward.

策略梯度存在两个主要问题:

  1. 样本效率:the large number of samples typically required
  2. 稳定的策略提升: the difficulty of obtaining stable and steady improvement despite the nonstationarity of the incoming data

考虑un-discounted Policy Optimization问题,最大化累计奖励:

\[\sum_{t=0}^{\infty}r_t\]

策略梯度算法通过策略梯度来调整策略网络参数来提升策略,从而实现上述最大化累计奖励的目标:

\[g:=\nabla_{\theta}\mathbb{E}[\sum_{t=0}^{\infty}r_t]\]

策略梯度进一步推导为:

\[g=\mathbb{E}[\sum_{t=0}^{\infty}\Psi_t\nabla_{\theta}log\pi_{\theta}(a_t|s_t)]\]

其中$\Psi_{t}$可以是以下几种形式:

  • $\sum_{t=0}^{\infty}r_t$:轨迹的累计奖励
  • $\sum_{t’=t}^{\infty}r_{t’}$:动作$a_t$后的总奖励(return to go)
  • $\sum_{t’=t}^{\infty}r_{t’} - b(s_t)$:减去baseline
  • $Q^{\pi}(s_t,a_t)$:动作值函数
  • $\color{red}A^{\pi}(s_t,a_t) = Q^{\pi}(s_t,a_t) - V^{\pi}(s_t)$:优势函数
  • $r_t + V^{\pi}(s_{t+1}) - V^{\pi}(s_t)$:TD residual

折扣版本的优势函数(Advantage Function):

状态值函数:

\[V^{\pi, \gamma}(s_t) = \mathbb{E}_{s_{t+1}:\infty,a_{t}:\infty}[\sum_{l=0}^{\infty}\gamma^lr_{t+l}]\]

动作值函数:

\[Q^{\pi, \gamma}(s_t, a_t) = \mathbb{E}_{s_{t+1}:\infty,a_{t+1}:\infty}[\sum_{l=0}^{\infty}\gamma^lr_{t+l}]\]

对于状态$s_t$下动作$a_t$折扣优势函数定义为:

\[\color{red}A^{\pi,\gamma}(s_t, a_t) = Q^{\pi,\gamma}(s_t, a_t) - V^{\pi,\gamma}(s_t)\]

强化学习实际应用中通过神经网络去估计价值函数$V_{\phi}(s_t)$,然后结合实际交互得到的奖励去估算动作的优势函数。

方法一(MC:高方差High Variance):$\hat{A_t} = r_t + \sum_{l=t+1}^{\infty}\gamma^lr_{t+1}-V_{\phi}(s_{t})$

  • 使用用实际交互得到的奖励近似估算动作值价值$Q(s_t, a_t)=r_t + \gamma r_{t+1}+\gamma ^2r_{t+2}+…$会因为环境随机性而波动很大,导致估计的方差很大。

方法二(TD:高偏差High Bias):$\hat{A_t} \approx \delta_{t}= r_t + \gamma V_{\phi}(s_{t+1})-V_{\phi}(s_{t})$

  • 使用单步的TD误差近似优势函数,方差会小但是偏差会变大,因为它只考虑了一步的奖励。

方法三(GAE: 平衡bias和variance):

  • 本文提出的方法,它结合了 MC 和 TD 的优点,在偏差和方差之间取得了更好的平衡。

总结一下:

  • 用长轨迹的回报估计优势,方差高、偏差低
  • 用单步的TD误差估计优势,方差低、偏差高

2. GAE的核心思想:偏差与方差的权衡

GAE(γ, λ)和TD(λ)的区别:

  1. GAE(γ, λ):估计的是优势函数(动作$a_t$比策略的默认动作「平均值」好还是差)
  2. TD(λ):估计的是状态值函数或动作值函数

GAE提出一个统一的框架,可以在偏差和方差之间进行平滑地权衡:

\[\color{green}\hat{A}_t^{GAE(\gamma,\lambda)} = \sum_{l=0}^{\infty}(\gamma\lambda)^l\delta_{t+l}^V\]

其中TD误差项$\delta_t^V$定义如下:

\[\delta_{t}^V= r_t + \gamma V_{\phi}(s_{t+1})-V_{\phi}(s_{t})\]

TD误差也可以视为一个优势函数的估计

\[\begin{align} A^{\pi,\gamma}(s_t, a_t) &= \mathbb{E}_{s_{t+1}}[Q^{\pi,\gamma}(s_t, a_t) - V^{\pi,\gamma}(s_t)]\\ &= \mathbb{E}_{s_{t+1}}[r_t + \gamma V^{\pi,\gamma}(s_{t+1})-V^{\pi,\gamma}(s_{t})]\\ &= \mathbb{E}_{s_{t+1}}[\delta_t^{V^{\pi,\gamma}}] \end{align}\]

定义:
\(\hat{A}_t^{(1)}:=\delta_t^{V}=-V(s_t) + r_t + \gamma V(s_{t+1})\)
\(\hat{A}_t^{(2)}:=\delta_t^{V} + \gamma \delta_{t+1}^{V}=-V(s_t) + r_t + \gamma r_{t+1}+\gamma^2 V(s_{t+2})\)
\(\hat{A}_t^{(3)}:=\delta_t^{V} + \gamma \delta_{t+1}^{V} + \gamma ^2 \delta_{t+2}^{V}=-V(s_t) + r_t + \gamma r_{t+1} + \gamma^2 r_{t+2}+\gamma^3 V(s_{t+3})\)
\(\hat{A}_t^{(k)}:=\sum_{l=0}^{k-1}\gamma ^{l} \delta_{t+l}^{V}=-V(s_t) + r_t + \gamma r_{t+1} + \gamma^2 r_{t+2}+...+\gamma^k V(s_{t+k})\)
\(\hat{A}_t^{(\infty)}:=\sum_{l=0}^{\infty}\gamma ^{l} \delta_{t+l}^{V}=-V(s_t) + \sum_{l=0}^{\infty}\gamma^{l} r_{t+l}\)

上述多个公式都可以视为对优势函数的估计,当$k\rightarrow\infty$,偏差bias逐渐缩小。

广义优势函数估计定义为$GAE(\gamma,\lambda)$:

\(\begin{align} \hat{A}_t^{GAE(\gamma,\lambda)} &:=(1-\lambda)(\hat{A}_t^{(1)} + \lambda \hat{A}_t^{(2)}+\lambda^2 \hat{A}_t^{(3)}+...)\\ &:=\sum_{l=0}^{\infty}(\gamma\lambda)^l\delta_{t+l}^V\\ \end{align}\) 两个特殊的形式:

  • 当$\lambda=0$的时候$\hat{A}^{GAE(\gamma, 0)}=r_t+\gamma V(s_{t+1}) - V({s_t})$
  • 当$\lambda =1$的时候$\hat{A}^{GAE(\gamma, 1)}=\sum_{l=0}^{\infty}\gamma^{l}r_{t+l} - V({s_t})$

讨论: $\gamma$和$\lambda$都对于bias-variance的权衡发生作用

  1. $\gamma$主要决定了scale of the value function $V^{\pi,\gamma}$,$\lambda$对value function的scale没有影响

使用上述广义优势估计得到有偏差的策略梯度(biased estimator ):

\[g^{\gamma}\approx\mathbb{E}[\sum_{t=0}^{\infty}\hat{A}_t^{GAE(\gamma,\lambda)}\nabla_{\theta}log\pi_{\theta}(a_t|s_t)]=\mathbb{E}[\sum_{t=0}^{\infty}\sum_{l=0}^{\infty}(\gamma\lambda)^l\delta_{t+l}^V\nabla_{\theta}log\pi_{\theta}(a_t|s_t)]\]

当$\lambda=1$的时候取等号

3. 从reward shaping的角度来理解GAE

4. value function estimation

This post is licensed under CC BY 4.0 by the author.