(可选) Policy Gradient Theorem
在这个可选章节中,我们将研究如何区分目标函数,我们将使用该目标函数来近似策略梯度。
让我们首先回顾一下不同的公式
- 目标函数
- 轨迹的概率(假设动作来自πθ):
所以我们有∇θJ(θ)=∇θ∑τP(τ;θ)R(τ)
我们可以将总和的梯度重写为梯度的总和=∑τ∇θ(P(τ;θ)R(τ))=∑τ∇θP(τ;θ)R(τ)因为R(τ)不依赖于θ
然后我们将总和中的每一项乘以P(τ;θ)P(τ;θ)(这是可能的,因为它 = 1)=∑τP(τ;θ)P(τ;θ)∇θP(τ;θ)R(τ)
我们可以进一步简化,因为P(τ;θ)P(τ;θ)∇θP(τ;θ)=P(τ;θ)P(τ;θ)∇θP(τ;θ).
因此,我们可以将总和重写为P(τ;θ)P(τ;θ)∇θP(τ;θ)=∑τP(τ;θ)P(τ;θ)∇θP(τ;θ)R(τ)
然后我们可以使用导数对数技巧(也称为 似然比技巧 或 REINFORCE 技巧),这是微积分中的一个简单规则,意味着∇xlogf(x)=f(x)∇xf(x)
所以给定我们有P(τ;θ)∇θP(τ;θ)we transform it as∇θlogP(τ∣θ)
So this is our likelihood policy gradient∇θJ(θ)=∑τP(τ;θ)∇θlogP(τ;θ)R(τ)
Thanks for this new formula, we can estimate the gradient using trajectory samples (we can approximate the likelihood ratio policy gradient with sample-based estimate if you prefer).∇θJ(θ)=m1∑i=1m∇θlogP(τ(i);θ)R(τ(i))where eachτ(i)is a sampled trajectory.
But we still have some mathematics work to do there: we need to simplify∇θlogP(τ∣θ)
We know that
Whereμ(s0)is the initial state distribution andP(st+1(i)∣st(i),at(i))is the state transition dynamics of the MDP.
We know that the log of a product is equal to the sum of the logs∇θlogP(τ(i);θ)=∇θ[logμ(s0)+t=0∑HlogP(st+1(i)∣st(i)at(i))+t=0∑Hlogπθ(at(i)∣st(i))]
We also know that the gradient of the sum is equal to the sum of gradient∇θlogP(τ(i);θ)=∇θlogμ(s0)+∇θt=0∑HlogP(st+1(i)∣st(i)at(i))+∇θt=0∑Hlogπθ(at(i)∣st(i))
由于 MDP 的初始状态分布和状态转移动态都不依赖于θ,因此这两项的导数都为 0。所以我们可以移除它们
由于∇θ∑t=0HlogP(st+1(i)∣st(i)at(i))=0并且∇θμ(s0)=0 ∇θlogP(τ(i);θ)=∇θ∑t=0Hlogπθ(at(i)∣st(i))
我们可以将和的梯度重写为梯度的和∇θlogP(τ(i);θ)=∑t=0H∇θlogπθ(at(i)∣st(i))
因此,用于估计策略梯度的最终公式是∇θJ(θ)=g^=m1∑i=1m∑t=0H∇θlogπθ(at(i)∣st(i))R(τ(i))
< > 在 GitHub 上更新