The policy gradient theorem gives the gradient of the expected return with respect to policy parameters — enabling direct optimization of the policy.
Objective: J(θ)=Eπθ[G0] - maximize expected return
The theorem:
∇θJ(θ)=Eπθ[∇θlogπθ(a∣s)⋅Qπθ(s,a)]
Derivation intuition:
- ∇θlogπθ(a∣s) = direction to increase probability of action a in state s
- Qπθ(s,a) = how good action a actually was
- The product: increase probability of good actions, decrease probability of bad ones
- The expectation: average over the states and actions the policy visits
Why this is important:
- Works for continuous action spaces (unlike value-based methods that need argmax)
- Can learn stochastic policies (useful for partially observable environments)
- Directly optimizes the objective (no need for a value function, though one helps → Actor-Critic Methods )
Derivation (log-derivative trick): the key identity is ∇θP=P∇θlogP, which lets the gradient pass through the sampling distribution. In trajectory form with J(θ)=Eτ∼πθ[R(τ)]:
∇θJ(θ)=τ∑∇θP(τ∣θ)R(τ)=Eτ∼πθ[∇θlogP(τ∣θ)R(τ)]=Eτ∼πθ[t∑∇θlogπθ(at∣st)R(τ)]
The transition dynamics drop out of ∇θlogP(τ∣θ) because they don't depend on θ — only the policy terms survive.
Baselines: subtracting a baseline b(s) from Q: ∇θJ∝E[∇logπ⋅(Q(s,a)−b(s))] — this doesn't change the expectation but reduces variance. It stays unbiased because b depends only on the state: Ea∼π[∇θlogπθ(a∣s)b(s)]=b(s)∇θ!∑aπθ(a∣s)=b(s)∇θ1=0. The optimal baseline is approximately V(s), giving the Advantage Function .
See also: REINFORCE , Advantage Function , Proximal Policy Optimization (PPO)