How do you derive the REINFORCE policy-gradient estimator, and why does subtracting a baseline not introduce bias?

Reinforcement learning, Policy gradients
Level L3 Intermediate. Length Long. Nature Mat Mathematical.

What's being asked

Whether you can use the log-derivative trick, handle trajectory probabilities, and argue about variance reduction.

Key idea

Let πθ(a∣s) be the policy (the probability of action a in state s), τ a trajectory and Gt the reward-to-go from step t. Then ∇θJ=Eτ∼πθ[∑t∇θlog⁡πθ(at∣st) Gt]. The environment dynamics drop out of ∇θlog⁡pθ(τ), and Ea∼πθ[∇θlog⁡πθ(a∣s) b(s)]=0, so a baseline b(s) that depends only on the state is unbiased.

Steps

  1. Define the expected return J(θ)=Eτ∼pθ[R(τ)], where R(τ) is the total reward of trajectory τ.
  2. Use ∇θpθ(τ)=pθ(τ)∇θlog⁡pθ(τ) (the log-derivative trick) to move the gradient inside the expectation. This matters because an expectation can be estimated by sampling.
  3. Expand log⁡pθ(τ)=log⁡ρ(s0)+∑t[log⁡πθ(at∣st)+log⁡P(st+1∣st,at)], where ρ is the start-state distribution and P gives the transition probabilities. Only the policy terms depend on θ.
  4. Use causality to replace R(τ) with the reward-to-go Gt: an action cannot affect rewards that came before it.
  5. Show that the baseline term vanishes: ∑aπθ(a∣s) ∇θlog⁡πθ(a∣s)=∇θ∑aπθ(a∣s)=∇θ1=0. This works for any b(s), because it can be taken outside the sum over a.
  6. Note that a good baseline, such as the value function V(s), reduces variance. This leads to actor-critic methods and advantage estimates.

Common mistakes

How long your answer should be

One page; 8–10 minutes.

Last checked on 4 December 2026.

Read this

Previous in Reinforcement learning: For a sampled transition, r=1, γ=0.99, and the next state s′ has online-network values Qθ(s′,⋅)=(2.0,3.0,2.5) and target-network values Qθ−(s′,⋅)=(2.8,2.2,3.4). Compute the target used by DQN and by double DQN. Why does the max in DQN cause over-estimation, and how does double DQN reduce it?
Next in Reinforcement learning: Derive the Bellman expectation equation for Vπ. How does the Bellman optimality equation for V∗ differ, and why can the first be solved as a linear system but not the second?