• 强化学习——策略梯度理解点


    策略梯度计算公式

    目的是最大化reward函数,即调整 θ ,使得期望回报最大,可以用公式表示如下
    J ( θ ) = E τ ∼ p ( T ) [ ∑ t r ( s t , a t ) ] \mathrm{J}(\theta)=\mathrm{E}_{\tau \sim p}(\mathcal{T})\left[\sum_{\mathrm{t}} \mathrm{r}\left(\mathrm{s}_{t}, \mathrm{a}_{\mathrm{t}}\right)\right] J(θ)=Eτp(T)[tr(st,at)]
    对于上面的式子, τ \tau τ 表示从从开始到结束的一条完整路径。通常,对于最大化问题,我们可以使用梯度上升算法来找到最大值,即
    θ ∗ = θ + α ∇ J ( θ ) \theta^{*}=\theta+\alpha \nabla \mathrm{J}(\theta) θ=θ+αJ(θ)
    所以我们仅仅需要计算 (更新) ∇ J ( θ ) \nabla J(\theta) J(θ) ,也就是计算回报函数 J ( θ ) J(\theta) J(θ) 关于 θ \theta θ 的梯度,也就是策略梯度,计算方法如下:
    ∇ θ J ( θ ) = ∫ ∇ θ p θ ( τ ) r ( τ ) d τ = ∫ p θ ∇ θ log ⁡ p θ ( τ ) r ( τ ) d τ = E τ ∼ p θ ( τ ) [ ∇ θ log ⁡ p θ ( τ ) r ( τ ) ]

    θJ(θ)=θpθ(τ)r(τ)dτ=pθθlogpθ(τ)r(τ)dτ=Eτpθ(τ)[θlogpθ(τ)r(τ)]" role="presentation" style="position: relative;">θJ(θ)=θpθ(τ)r(τ)dτ=pθθlogpθ(τ)r(τ)dτ=Eτpθ(τ)[θlogpθ(τ)r(τ)]
    θJ(θ)=θpθ(τ)r(τ)dτ=pθθlogpθ(τ)r(τ)dτ=Eτpθ(τ)[θlogpθ(τ)r(τ)]
    接着我们继续讲上式展开,对于 p θ ( τ ) \mathrm{p}_{\theta}(\tau) pθ(τ) ,即 p θ ( τ ∣ θ ) \mathrm{p}_{\theta}(\tau \mid \theta) pθ(τθ) :
    p θ ( τ ∣ θ ) = p ( s 1 ) ∏ t = 1 T π θ ( a t ∣ s t ) p ( s t + 1 ∣ s t , a t ) \mathrm{p}_{\theta}(\tau \mid \theta)=\mathrm{p}\left(\mathrm{s}_{1}\right) \prod_{t=1}^{\mathrm{T}} \pi_{\theta}\left(\mathrm{a}_{t} \mid \mathrm{s}_{\mathrm{t}}\right) \mathrm{p}\left(\mathrm{s}_{t+1} \mid \mathrm{s}_{t}, \mathrm{a}_{\mathrm{t}}\right) pθ(τθ)=p(s1)t=1Tπθ(atst)p(st+1st,at)
    取对数后为:
    log ⁡ p θ ( τ ∣ θ ) = log ⁡ p ( s 1 ) + ∑ t = 1 T log ⁡ π θ ( a t ∣ s t ) p ( s t + 1 ∣ s t , a t ) \log p_{\theta}(\tau \mid \theta)=\log p\left(s_{1}\right)+\sum_{t=1}^{T} \log \pi_{\theta}\left(a_{t} \mid s_{t}\right) p\left(s_{t+1} \mid s_{t}, a_{t}\right) logpθ(τθ)=logp(s1)+t=1Tlogπθ(atst)p(st+1st,at)
    继续求导:
    ∇ log ⁡ p θ ( τ ∣ θ ) = ∑ t = 1 T ∇ θ log ⁡ π θ ( a t ∣ s t ) \nabla \log p_{\theta}(\tau \mid \theta)=\sum_{t=1}^{T} \nabla_{\theta} \log \pi_{\theta}\left(a_{t} \mid s_{t}\right) logpθ(τθ)=t=1Tθlogπθ(atst)
    带入第三个式子,可以将其化简为:
    ∇ θ J ( θ ) = E τ ∼ p θ ( τ ) [ ∇ θ log ⁡ p θ ( τ ) r ( τ ) ] = E τ ∼ p θ [ ( ∇ θ log ⁡ π θ ( a t ∣ s t ) ) ( ∑ t = 1 T r ( s t , a t ) ) ] = 1 N ∑ i = 1 N [ ( ∑ t = 1 T ∇ θ log ⁡ π θ ( a i , t ∣ s i , t ) ) ( ∑ t = 1 N r ( s i , t , a i , t ) ) ]
    θJ(θ)=Eτpθ(τ)[θlogpθ(τ)r(τ)]=Eτpθ[(θlogπθ(atst))(t=1Tr(st,at))]=1Ni=1N[(t=1Tθlogπθ(ai,tsi,t))(t=1Nr(si,t,ai,t))]" role="presentation" style="position: relative;">θJ(θ)=Eτpθ(τ)[θlogpθ(τ)r(τ)]=Eτpθ[(θlogπθ(atst))(t=1Tr(st,at))]=1Ni=1N[(t=1Tθlogπθ(ai,tsi,t))(t=1Nr(si,t,ai,t))]
    θJ(θ)=Eτ(τ)[θlogpθ(τ)r(τ)]=Eτ[(θlogπθ(atst))(t=1Tr(st,at))]=N1i=1N[(t=1Tθlogπθ(ai,tsi,t))(t=1Nr(si,t,ai,t))]

    重要性重采样

    使用另外一种数据分布,来逼近所求分布的一种方法,算是一种期望修正的方法,公式是:
    ∫ f ( x ) p ( x ) d x = ∫ f ( x ) p ( x ) q ( x ) q ( x ) d x = E x ∼ q [ f ( x ) p ( x ) q ( x ) ] = E x ∼ p [ f ( x ) ]

    f(x)p(x)dx=f(x)p(x)q(x)q(x)dx=Exq[f(x)p(x)q(x)]=Exp[f(x)]" role="presentation" style="position: relative;">f(x)p(x)dx=f(x)p(x)q(x)q(x)dx=Exq[f(x)p(x)q(x)]=Exp[f(x)]
    f(x)p(x)dx=f(x)q(x)p(x)q(x)dx=Exq[f(x)q(x)p(x)]=Exp[f(x)]
    在已知 q q q 的分布后,可以使用上述公式计算出从 p 分布的期望值。也就可以使用 q q q 来对于 p 进行采样了,即为重要性采样。

  • 相关阅读:
    DataFunSummit:2023年智能风控技术峰会-核心PPT资料下载
    若依微服务版本集成积木报表
    TouchGFX之后端通信
    MySQL集群:双主模式
    Java面向对象16:接口的定义与实现
    视频一键转码:批量转换MP4视频的技巧
    C#自定义窗体更换皮肤的方法:创建特殊窗体
    MySQL—一条查询SQL语句的完整执行流程
    Unity Shader ASE基础效果思路与代码(一):遮罩、硬边溶解、光边溶解、UV扰动
    DRU-Net--一种用于医学图像分割的高效深度卷积神经网络
  • 原文地址:https://blog.csdn.net/weixin_42917352/article/details/125882984