CS294-112 Deep Reinforcement Learning Notes



  • 不是太会玩这里的 latex,先放在 GitHub Pages 上维护了

    Assignments on GitHub



  • TOC

    • 什么是 / 为什么是 “强化学习”?
    • 线性二次调节器(LQR)
    • 了解世界
      • ==DAgger==
    • 独当一面
      • Markov 决策过程
      • ==策略梯度==

    什么是 / 为什么是 “强化学习”?

    What? And why?

    maximize r\text{maximize } r

    问题解释:假设你在玩 地球OL,如何成为人生赢家?

    • 我们受现实制约:sSs \in \mathbb{S}
      • 而且时常我们无法得知事情的真相:os or oso \subset s \text{ or } o \sim s
    • 我们能做的事情有限:aAa \in \mathbb{A}
    • 我们心里对自己有数:s,a,sτ,brs, a, s' \Rightarrow_{\tau, b} r
    • 我们能与环境互动! s,aπ,pss, a \Rightarrow_{\pi, p} s'

    0_1532159003913_agent-environ-reward.jpg

    • 类似于人类的学习机制
      • “如果好吃你就多吃点”:if r, then p(srr)\text{if } r^\star \uparrow, \text{ then } \uparrow p(s\vert_{r \approx r^\star})
    • 一种可能的达成 GAI 的途径

    线性二次调节器

    Linear Quadratic Regulator

    • 最优设计算法
      • 控制论
    • 世界模型:xt+1=f(xt,ut)=Ft[xt ut]+ft\mathbf{x}_{t+1} = f(\mathbf{x}_t, \mathbf{u}_t) = \mathbf{F}_t \begin{bmatrix} \mathbf{x}_t \ \mathbf{u}_t \end{bmatrix} + \mathbf{f}_t

      允许包含高阶项 x˙,x¨,\dot{x}, \ddot{x}, \cdots

    • 评判标准:c(xt,ut)=12[xt ut]TCt[xt ut]+[xt ut]Tctc(\mathbf{x}_t, \mathbf{u}_t) = \frac{1}{2} \begin{bmatrix} \mathbf{x}_t \ \mathbf{u}_t \end{bmatrix}^T \mathbf{C}_t \begin{bmatrix} \mathbf{x}_t \ \mathbf{u}_t \end{bmatrix} + \begin{bmatrix} \mathbf{x}_t \ \mathbf{u}_t \end{bmatrix}^T \mathbf{c}_t
    • 目标:minτc\min_\tau \sum c
      • 注意对 x\mathbf{x} 递归带入 ff

    0_1532159082964_lqr-psudocode.png

    • iterative LQR:如果不能线性,就用泰勒展开
      • 是的,对轨迹上每个点展开

    了解世界

    Learn about the world

    Version 1.0
    1. 采集数据 D=(x,u,x)i\mathcal{D} = { (\mathbf{x}, \mathbf{u}, \mathbf{x}')_i }
    2. 从数据 D\mathcal{D} 学习世界模型 fminfif(xi,ui)x2f \leftarrow \min_f \sum_i \lVert f(\mathbf{x}_i, \mathbf{u}_i) - \mathbf{x}' \rVert^2

    Version 1.0 出了什么问题?

    想想巴甫洛夫的狗...

    • D0,:=(ring bell and food,)\mathcal{D}_0 , := { (\text{ring bell and food}, \cdots})
    • fD0=(bell=food)f_{\mathcal{D}_0} = (\text{bell} = \text{food})
    • πD0=(if bell, then go to front door for food)\pi_{\mathcal{D}_0} = (\text{if bell, then go to front door for food})

    被训练集教坏的模型!

    • D\mathcal{D} 并不能代表 S\mathbb{S},因为 xDS\mathbf{x}_{\mathcal{D}} \subset \mathbb{S}

    Version 2.0 - DAgger

    Data Aggregation

    1. 初始化 π0\pi_0
    2. π0\pi_0 采集数据 D\mathcal{D}
    3. D\mathcal{D} 学习 ff
    4. 更新 π\piπi\pi_i
    5. πi\pi_i 采集数据 Di\mathcal{D}_i
    6. [DAgger] D:=DDi\mathcal{D} := \mathcal{D} \cup \mathcal{D}_i
    7. 回到步骤 3,直至收敛

    独当一面

    Be the master of yourself

    Markov Decision Process

    π(s):=argmaxasPa(s,s)(Ra(s,s)+γV(s))\pi(s) := \arg \max_a { \sum_{s'} P_a(s, s') ( R_a(s, s') + \gamma V(s') ) }

    V(s):=sPπ(s)(Rπ(s)(s,s)+γV(s))V(s) := \sum_{s'} P_{\pi(s)} ( R_{\pi(s)}(s, s') + \gamma V(s') )

    from WikiPedia


    评价方法
    • 策略表现:η(π)=E[tγtrt]\eta(\pi) = \mathbb{E} [ \sum_t \gamma^t r_t ]
    • 状态评分:Vπ(s)=E[tγtrts0=s]V_\pi(s) = \mathbb{E} [ \sum_t \gamma^t r_t | s_0 = s ]
    • 状态-动作评分:Qπ(s,a)=E[tγtrts0=s,a0=a]Q_\pi(s, a) = \mathbb{E} [ \sum_t \gamma^t r_t | s_0 = s, a_0 = a ]

    γ\gamma 为衰减因子


    策略梯度
    Prolicy Gradient

    maximize E[Rπθ]\text{maximize } \mathbb{E} [ R | \pi_\theta ]

    基本思路
    • 让好的轨迹更容易发生
    • 让好的动作更容易发生
    • 改善不好的动作

    0_1532159402030_policy-gradient.png

    f(x)f(x) 替换为我们需要的任务目标

    g^:=θEτ[R(τ)]=Eτ[θlogp(τθ)R(τ)]\hat{g} := \nabla_\theta \mathbb{E}_\tau [ R(\tau) ] = \mathbb{E}_\tau [ \nabla_\theta \log{p(\tau | \theta)} R(\tau) ]

    • fRf \rightarrow R
    • xτ:=(s0,a0,r0,s1,a1,r1,,sT1,aT1,rT1,sT)x \rightarrow \tau := (s_0, a_0, r_0, s_1, a_1, r_1, \cdots, s_{T-1}, a_{T-1}, r_{T-1}, s_T)

    g^:=θEτ[R(τ)]=Eτ[θlogp(τθ)R(τ)]\hat{g} := \nabla_\theta \mathbb{E}_\tau [ R(\tau) ] = \mathbb{E}_\tau [ \nabla_\theta \log{p(\tau | \theta)} R(\tau) ]

    现在研究 p(τθ)p(\tau | \theta)

    • 在当前策略 πθ\pi_\theta 下,当前关注的轨迹 τ\tau 发生的概率

    0_1532159536706_trajectory-probability.png


    g^:=θEτ[R(τ)]=Eτ[R(τ)tθlogπθ(atst)]\hat{g} := \nabla_\theta \mathbb{E}_\tau [ R(\tau) ] = \mathbb{E}_\tau [ R(\tau) \sum_t \nabla_\theta \log{\pi_\theta(a_t | s_t)} ]

    现在需要定义 R(τ)R(\tau)

    • Q函数 / 状态-动作评分

      Qπ,γ(s,a)=Eπ[r0+γr1+γ2r2+s0=s,a0=a] Q_{\pi, \gamma}(s, a) = \mathbb{E}_\pi [ r_0 + \gamma r_1 + \gamma^2 r_2 + \cdots | s_0 = s, a_0 = a ]

    • 状态评分

      Vπ,γ(s)=Eaπ[Qπ,γ(s,a)] V_{\pi, \gamma}(s) = \mathbb{E}_{a \sim \pi} [ Q_{\pi, \gamma}(s, a) ]

    • 进步评分

      • 在状态 ss 时采取动作 a=π(s)a=\pi(s) 所能产生的评分提升

        Aπ,γ(s,a)=Qπ,γ(s,a)Vπ,γ(s)A_{\pi, \gamma}(s, a) = Q_{\pi, \gamma}(s, a) - V_{\pi, \gamma}(s)


    取其中一种形式

    • Q函数
    • reward-to-go
    • 平均基准评分

    得到

    g^=θEτ[R]Eτ[t=0T1θlogπθ(atst)(t=tT1γttrtb(st))]\hat{g} = \nabla_\theta \mathbb{E}_\tau[R] \approx \mathbb{E}_\tau \bigg[ \sum_{t=0}^{T-1} \nabla_\theta \log{\pi_\theta(a_t | s_t)} \bigg( \sum_{t' = t}^{T-1} \gamma^{t' - t} r_{t'} - b(s_t) \bigg) \bigg]

    其中

    • b(st)E[rt+γrt+1+γ2rt+2++γT1trT1]b(s_t) \approx \mathbb{E} [ r_t + \gamma r_{t+1} + \gamma^2 r_{t+2} + \cdots + \gamma^{T-1-t} r_{T-1} ]

    构建算法流程

    1. 初始化策略网络参数 θ\theta,评价基准 bb
    2. (训练循环)
      1. 在环境 pp 中跑当前策略 π\pi 得到轨迹数据 τ\tau
        • 离散:atM(πθ(st),pa)a_t \sim \mathrm{M}\big( \pi_\theta(s_t), \mathbf{p}_a \big)
        • 连续:atN(πθ(st),σ)a_t \sim \mathrm{N}\big( \pi_\theta(s_t), \sigma \big)
      2. 对轨迹 τ\tau 中每一步 tt 计算
        • 环境评分 Rt=t=tT1γttrtR_t = \sum_{t'=t}^{T-1} \gamma^{t'-t} r_{t'}
        • 策略进步评价 A^t=Rtb(st)\hat{A}_t = R_t - b(s_t)
      3. 更新评价基准 bargminbtτRtb(st)2b \leftarrow \arg \min_b \sum_{t \in \tau} \lVert R_t - b(s_t) \rVert^2
        • 即将进步评价(的期望)归零
      4. 使用计算的策略梯度 g^\hat{g} 更新策略网络参数 θ\theta
        • 离散:losst:=xent(at,πθ(st))A^t\mathrm{loss}_t := \mathrm{xent}\big( a_t , \pi_{\theta}(s_t) \big) \cdot \hat{A}_t
        • 连续:losst:=logπθ(atst)A^t\mathrm{loss}_t := - \log{\pi_\theta(a_t | s_t)} \cdot \hat{A}_t

 

Copyright © 2018 bbs.dian.org.cn All rights reserved.

与 Dian 的连接断开,我们正在尝试重连,请耐心等待