For the policy-gradient estimate g^=(R−b) ∇θlog⁡πθ(a), derive the constant baseline b∗ that minimises variance. Then take a one-state problem with π(a1)=σ(θ)=0.8, π(a2)=0.2, rewards R(a1)=1 and R(a2)=0. Compute b∗ and the variance for b=0, b∗ and b=E[R]. Is the average reward the best baseline?

Reinforcement learning, Policy gradients
Level L4 Advanced. Length Long. Nature Mat Mathematical.

What's being asked

Whether you can minimise the variance of the policy-gradient estimator over a baseline and see that the optimum is weighted by the squared score, not the plain mean reward.

Key idea

The mean of g^ does not depend on b, so minimising variance means minimising E∥g^∥2. This gives b∗=E[∥s∥2R]E[∥s∥2] with the score s=∇log⁡π(a), a reward average weighted by the squared score norm.

Steps

  1. Because E[(R−b)s]=E[Rs]−b E[s]=E[Rs] (the score has zero mean), the mean of g^ is ∇J for every b. Variance is E∥g^∥2−∥∇J∥2.
  2. Minimise f(b)=E[(R−b)2∥s∥2]. Differentiate: f′(b)=−2 E[(R−b)∥s∥2]=0, and this is convex in b, so b∗=E[∥s∥2R]/E[∥s∥2].
  3. The example. For π(a1)=σ(θ) the scores are s(a1)=1−σ=0.2 and s(a2)=−σ=−0.8. The true gradient is E[Rs]=0.8×1×0.2=0.16=σ(1−σ).
  4. Compute E[s2]=0.8×0.04+0.2×0.64=0.16 and E[s2R]=0.8×0.04×1=0.032. So b∗=0.032/0.16=0.2.
  5. Variances E[(R−b)2s2]−0.162. For b=0: 0.8×0.04−0.0256=0.0064. For b=0.8=E[R]: 0.8×0.04×0.04+0.2×0.64×0.64−0.0256=0.0832−0.0256=0.0576. For b∗=0.2: 0.8×0.64×0.04+0.2×0.04×0.64−0.0256=0.0256−0.0256=0.
  6. Interpret. At b∗=0.2 every sample gives (R−b)s=0.8×0.2=0.16 for a1 and (−0.2)(−0.8)=0.16 for a2, the exact gradient. The average reward 0.8 gives the largest variance of the three.
  7. Conclude. The average reward (or a state-value baseline V(s)) is a good, convenient choice, but it is not the variance minimiser. The optimum weights reward by ∥s∥2, so rare actions with big score norms count more. Zero variance here is special: one parameter and two actions.

Common mistakes

How long your answer should be

A page; 8–10 minutes.

Last checked on 4 December 2026.

Read this

Previous in Reinforcement learning: A duelling DQN has a value stream and an advantage stream. For one state, V=3 and A=(1,−1,3) for three actions. Compute Q using (a) Q=V+A, (b) Q=V+A−1∣A∣∑a′A(a′) and (c) Q=V+A−max⁡a′A(a′). Why is (a) not identifiable, and what do (b) and (c) fix?
Next in Reinforcement learning: A shaped reward is r′(s,a,s′)=r(s,a,s′)+γΦ(s′)−Φ(s) for some potential function Φ. Prove that the optimal policy does not change. If γ=0.9, Φ(s)=10 and Φ(s′)=20, what bonus does the agent get on the move s→s′, and what does the bonus sum to along a whole episode?