Post · 4 min read· pp. 92–94
Introduction
In reinforcement learning policy gradient methods, the goal is usually to maximize E[Rt], the expected value of return R at time step t, where Rt=∑k=0∞γkrt+k.
We have parameterized the policy π(a∣s;θ) and update the parameter θ so that E[Rt] is maximized.
Standard REINFORCE algorithm updates policy in the direction ∇θRtlogπ(at∣st;θ). That is to say, we have a loss function of $ -\log R_t \pi (a_t|s_t; \theta)$ and we are minimizing the loss.

But in order to mamixize E[Rt], why do we have to calculate the the derivatives for Rtlogπ(at∣st;θ)? It turns out that it is because ∇θRtlogπ(at∣st;θ) is an unbiased estimate of ∇θE[Rt], i.e., E[Rt∇θlogπ(at∣st;θ)]=∇θE[Rt].
Proof
We use the definition of expected value, because random variable Rt is dependent on at and it follows distribution π(at∣st;θ).
∇θE[Rt]=∇θ∫Rtπ(at∣st;θ)d(at)
Then we apply a special case of Leibniz Integral Rule, where
dxd∫abf(x,t)dt=∫ab∂x∂f(x,t)dt
We then have
∇θ∫Rtπ(at∣st;θ)d(at)=∫∇θ[Rtπ(at∣st;θ)]d(at)
Because Rt is dependent on at but not dependent on θ (Is it?). We have
∫∇θ[Rtπ(at∣st;θ)]d(at)=∫Rt∇θπ(at∣st;θ)d(at)
We apply an identity trick here
∫Rt∇θπ(at∣st;θ)d(at)=∫Rtπ(at∣st;θ)π(at∣st;θ)∇θπ(at∣st;θ)d(at)=∫Rtπ(at∣st;θ)∇θlogπ(at∣st;θ)d(at)
Because the random variable Rt∇θlogπ(at∣st;θ) also follows distribution π(at∣st;θ), we have
∫Rtπ(at∣st;θ)∇θlogπ(at∣st;θ)d(at)=E[Rt∇θlogπ(at∣st;θ)]
Therefore,
∇θE[Rt]=E[Rt∇θlogπ(at∣st;θ)]
This concludes the proof.
Generalization
More generally it is not hard to see that,
∇θE[f(z)]=E[f(z)∇θlogp(z;θ)]
Extension
We also use REINFORCE with baseline to reduce the variance of the estimate of ∇θE[Rt] while keeping the estimate unbiased.

In stead of using ∇θRtlogπ(at∣st;θ) as an unbiased estimate of ∇θE[Rt], we use ∇θ(Rt−v(st))logπ(at∣st;θ) as long as v(st) does not dependent on a.
To see why E[(Rt−v(st))∇θlogπ(at∣st;θ)]=∇θE[Rt], we have
∇θE[Rt]=∇θ∫Rtπ(at∣st;θ)d(at)=∇θ∫Rtπ(at∣st;θ)d(at)−∇θ∫v(st)π(at∣st;θ)d(at)
Where ∇θ∫v(st)π(at∣st;θ)d(at)=0.
Because v use different parameters other than θ and it is not dependent on a,
∇θ∫v(st)π(at∣st;θ)d(at)=v(st)∇θ∫π(at∣st;θ)d(at)=v(st)∇θ1=v(st)×0=0
Quick Proof to Leibniz Integral Rule
dxd∫abf(x,t)dt=dxd∫ab∫x∂x∂f(x,t)dxdt=dxd∫x∫ab∂x∂f(x,t)dtdx=dxd∫x(∫ab∂x∂f(x,t)dt)dx=∫ab∂x∂f(x,t)dt
Thanks to the guidance from my friend Guotu Li on this.
There is a statement or an assumption we made during the proof, that is Rt is not dependent on θ. It is because in this case Rt is a scala value instead of an output from the policy neural network.