Policy Gradient Theorem

2 min read

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]J(\theta) = \mathbb{E}{\pi\theta}[G_0] - maximize expected return

The theorem:

∇θJ(θ)=Eπθ[∇θlog⁡πθ(a∣s)⋅Qπθ(s,a)]\nabla_\theta J(\theta) = \mathbb{E}_{\pi_\theta}\left[\nabla_\theta \log\pi_\theta(a|s) \cdot Q^{\pi_\theta}(s,a)\right]

Derivation intuition:

  • ∇θlog⁡πθ(a∣s)\nabla_\theta \log\pi_\theta(a|s) = direction to increase probability of action aa in state ss
  • Qπθ(s,a)Q^{\pi_\theta}(s,a) = how good action aa 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 arg⁡max⁡\arg\max)
  • 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∇θlog⁡P\nabla_\theta P = P \nabla_\theta \log P, which lets the gradient pass through the sampling distribution. In trajectory form with J(θ)=Eτ∼πθ[R(τ)]J(\theta) = \mathbb{E}_{\tau \sim \pi_\theta}[R(\tau)]:

∇θJ(θ)=∑τ∇θP(τ∣θ) R(τ)=Eτ∼πθ ⁣[∇θlog⁡P(τ∣θ) R(τ)]=Eτ∼πθ ⁣[∑t∇θlog⁡πθ(at∣st) R(τ)]\nabla_\theta J(\theta) = \sum_\tau \nabla_\theta P(\tau|\theta)\,R(\tau) = \mathbb{E}_{\tau \sim \pi_\theta}\!\left[\nabla_\theta \log P(\tau|\theta)\,R(\tau)\right] = \mathbb{E}_{\tau \sim \pi_\theta}\!\left[\sum_t \nabla_\theta \log\pi_\theta(a_t|s_t)\,R(\tau)\right]

The transition dynamics drop out of ∇θlog⁡P(τ∣θ)\nabla_\theta \log P(\tau|\theta) because they don't depend on θ\theta — only the policy terms survive.

Baselines: subtracting a baseline b(s)b(s) from QQ: ∇θJ∝E[∇log⁡π⋅(Q(s,a)−b(s))]\nabla_\theta J \propto \mathbb{E}[\nabla\log\pi \cdot (Q(s,a) - b(s))] — this doesn't change the expectation but reduces variance. It stays unbiased because bb depends only on the state: Ea∼π[∇θlog⁡πθ(a∣s) b(s)]=b(s)∇θ!∑aπθ(a∣s)=b(s)∇θ1=0\mathbb{E}_{a \sim \pi}[\nabla_\theta \log\pi_\theta(a|s)\,b(s)] = b(s)\nabla_\theta!\sum_a \pi_\theta(a|s) = b(s)\nabla_\theta 1 = 0. The optimal baseline is approximately V(s)V(s), giving the Advantage Function .

See also: REINFORCE , Advantage Function , Proximal Policy Optimization (PPO)

Linked from