Topics: Reinforcement Learning
This note is the proof of the Log-Derivative trick used in policy gradients in RL:
∇θP(τ∣θ)=P(τ∣θ).∇θlog[P(τ∣θ)]
τ : trajectory of states and actions
θ : parameters of the actor network
Let
y=P(τ∣θ)
z=log[P(τ∣θ)]
Then
dθdlog[P(τ∣θ)]=dθdz=dydz⋅dθdychainruledθdlog[P(τ∣θ)]=d(P(τ∣θ))dlog[P(τ∣θ)]⋅dθd(P(τ∣θ))dθdlog[P(τ∣θ)]=d(P(τ∣θ))dlog[P(τ∣θ)]⋅dθd(P(τ∣θ))dθdlog[P(τ∣θ)]=P(τ∣θ)1⋅dθd(P(τ∣θ))dxdlog(x)=x1∇θlog[P(τ∣θ)]=P(τ∣θ)1⋅∇θP(τ∣θ)∇θP(τ∣θ)=P(τ∣θ).∇θlog[P(τ∣θ)]
- https://spinningup.openai.com/en/latest/spinningup/rl_intro3.html
- https://davidmeyer.github.io/ml/log_derivative_trick.pdf