DRL的学习-homework2:Deep Reinforcement Learning HW2: Policy Gradients

mac2026-08-10  6

my first time use MarkDown Editor

hw2_instructions.pdf1.作业介绍2.复习

hw2_instructions.pdf

1.作业介绍

此次作业的目标是去体验策略梯度算法以及它的方差,以及策略梯度减小反差的方法。你的目标是去动手建立一个既可以用在连续环境下又可以在离散环境下的策略梯度算法,并且实验方差减小策略(这包括 reward-to-go以及neural nerwork baselines)

2.复习

强化学习的目标是去学习一个使得目标函数最大的参数 θ ∗ \theta ^{*} θ

J ( θ ) = E τ ∼ π θ ( τ ) [ r ( τ ) ] J(\theta )=\mathbb{E}_{\tau \sim \pi_{\theta}(\tau)}[r(\tau)] J(θ)=Eτπθ(τ)[r(τ)]

J ( θ ) J(\theta) J(θ)是关于参数 θ \theta θ的目标函数; E τ ∼ π θ ( τ ) \mathbb{E}_{\tau\sim \pi_{\theta}(\tau)} Eτπθ(τ)表示的是从 π θ \pi_{\theta} πθ这个策略中得到的分布 π θ ( τ ) \pi_{\theta}(\tau) πθ(τ)中采样得到的 τ \tau τ的回报的期望。

此处策略中得到的分布也表示为:

p θ ( τ ) = p ( s 1 , a 1 , . . . , s T , a T ) = p ( s 1 ) π θ ( a 1 ∣ s 1 ) ∏ t = 2 T p ( s t ∣ s t − 1 , a t − 1 ) π θ ( a t ∣ s t ) p_{\theta}(\tau)=p(s_{1},a_{1},...,s_{T},a_{T})=p(s_{1})\pi_{\theta}(a_{1}|s_{1})\prod^{T}_{t=2}p(s_{t}|s_{t-1},a_{t-1})\pi_{\theta}(a_{t}|s_{t}) pθ(τ)=p(s1,a1,...,sT,aT)=p(s1)πθ(a1s1)t=2Tp(stst1,at1)πθ(atst) 这公式的意思就是从策略 π θ \pi_{\theta} πθ中得到一个 τ \tau τ的概率是从一开始产生 s 1 s_{1} s1的概率 p ( s 1 ) p(s_{1}) p(s1)不断乘上之后产生决策的条件概率的累积。

并且 r ( τ ) = r ( s 1 , a 1 , . . . , s T , a T ) = ∑ t = 1 T r ( s t , a t ) r(\tau)=r(s_{1},a_{1},...,s_{T},a_{T})=\sum^{T}_{t=1}r(s_{t},a_{t}) r(τ)=r(s1,a1,...,sT,aT)=t=1Tr(st,at) 策略梯度算法直接利用目标的梯度进行逼近 ▽ θ J ( θ ) = ▽ θ ∫ p θ ( τ ) r ( τ ) d τ = ∫ p θ ( τ ) ▽ θ l o g p θ ( τ ) r ( τ ) d τ \bigtriangledown_{\theta}J(\theta)=\bigtriangledown_{\theta}\int p_{\theta}(\tau)r(\tau)d\tau=\int p_{\theta}(\tau)\bigtriangledown_{\theta}logp_{\theta}(\tau)r(\tau)d\tau θJ(θ)=θpθ(τ)r(τ)dτ=pθ(τ)θlogpθ(τ)r(τ)dτ 这里其实用了 E τ ∼ π θ ( τ ) [ r ( τ ) ] = ∫ π θ ( τ ) r ( τ ) d τ \mathbb{E}_{\tau \sim \pi_{\theta}(\tau)}[r(\tau)]=\int\pi_{\theta}(\tau)r(\tau)d\tau Eτπθ(τ)[r(τ)]=πθ(τ)r(τ)dτ这个概率变量的期望的数学定义。并且在二三式的转换中使用了如下的公式 ▽ θ p θ ( τ ) = p θ ▽ θ p θ ( τ ) p θ ( τ ) = p θ ( τ ) ▽ θ l o g p θ ( τ ) \bigtriangledown _{\theta}p_{\theta}(\tau)=p_{\theta}\frac{\bigtriangledown_{\theta}p_{\theta}(\tau)}{p_{\theta}(\tau)}=p_{\theta}(\tau)\bigtriangledown_{\theta}logp_{\theta}(\tau) θpθ(τ)=pθpθ(τ)θpθ(τ)=pθ(τ)θlogpθ(τ) 这其实就是高数中的 ▽ x l o g f ( x ) = ▽ x f ( x ) x \bigtriangledown _{x}logf(x)=\frac{\bigtriangledown_xf(x)}{x} xlogf(x)=xxf(x)

在实际中,对于轨迹 τ \tau τ的期望可以被轨迹分布的N个采样近似: ▽ θ J ( θ ) ≈ 1 N ∑ i = 1 N ▽ θ l o g π θ ( τ i ) r ( τ i ) = 1 N ∑ i = 1 N ( ∑ i = 1 T ▽ θ log ⁡ π θ ( a i t ∣ s i t ) ( ∑ t = 1 T r ( s i t , a i t ) ) \bigtriangledown_{\theta}J(\theta)\approx\frac1N\sum_{i=1}^N\bigtriangledown_{\theta}log\pi_\theta(\tau_i)r(\tau_i)=\frac1N\sum^N_{i=1}(\sum^T_{i=1}\bigtriangledown_\theta\log\pi_\theta(a_{it}|s_{it})(\sum^T_{t=1}r(s_{it},a_{it})) θJ(θ)N1i=1Nθlogπθ(τi)r(τi)=N1i=1N(i=1Tθlogπθ(aitsit)(t=1Tr(sit,ait)) 这里我们看到策略 π θ \pi_\theta πθ是一个根据状态得到动作的概率分布。在一个agent-environment loop中,agent从策略 π θ ( ⋅ ∣ s t ) \pi_\theta(\cdot|s_t) πθ(st)中采样动作,并且环境做出相应的回报 r ( s t , a t ) r(s_t,a_t) r(st,at) 实际中我们会发现这个梯度的方差特别的大。

OK,就写到这里把,之后再说要不要补充,因为LaTex写起来太麻烦了,以后还是用ipad做一个手写笔记。 剩下的内容看这里把。

参考:https://zhuanlan.zhihu.com/p/32652178

最新回复(0)