A two-armed bandit policy is π(a)=softmax(θ)a with θ=(0,0). The agent samples arm 1 and receives reward R=4. Using the REINFORCE update θ←θ+α(R−b)∇θlog⁡π(a) with α=0.1, what is the update (a) with baseline b=0 and (b) with b=2? What is the gradient of log⁡π, and how do you show that the score function has zero mean?

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

What's being asked

Whether you can compute ∇θlog⁡π for a softmax policy and see how a baseline reduces the size of updates without changing their expected direction.

Key idea

For a softmax policy, ∂log⁡π(a)∂θk=1[k=a]−π(k). Subtracting a baseline b that does not depend on the action leaves the expected gradient unchanged, because Ea[∇log⁡π(a)]=0.

Steps

  1. Write log⁡π(a)=θa−log⁡∑jeθj. Differentiating gives 1[k=a]−π(k).
  2. At θ=(0,0), π=(0.5,0.5). For the sampled arm 1, ∇θlog⁡π(1)=(1−0.5, 0−0.5)=(0.5,−0.5).
  3. (a) b=0: Δθ=0.1×4×(0.5,−0.5)=(0.2,−0.2).
  4. (b) b=2: Δθ=0.1×(4−2)×(0.5,−0.5)=(0.1,−0.1). The direction is the same, and the step is half as large.
  5. Zero mean of the score: ∑aπ(a)(1[k=a]−π(k))=π(k)−π(k)∑aπ(a)=0. Therefore E[b ∇log⁡π(a)]=b×0=0, so a constant baseline adds no bias.
  6. Explain the benefit. If every reward is positive, without a baseline every sampled action is pushed up, and the noise is large. A baseline near the average reward pushes up only the better-than-average actions.

Common mistakes

How long your answer should be

Half a page; 5 minutes.

Last checked on 4 December 2026.

Read this

Previous in Reinforcement learning: A tabular value function is V=0 for states A, B, C. One episode goes A → B → C → end with rewards 0,0,1. Use TD(λ) with accumulating traces, γ=0.9, λ=0.8 and α=0.1, and update every state at every step. What is V after the episode? How does this differ from TD(0)?
Next in Reinforcement learning: A trajectory of three steps has rewards (1,0,2) and critic values V(s0),V(s1),V(s2)=(3,2,1). The episode ends after step 3, so the next value is 0. With γ=0.9 and λ=0.5, what are the TD errors and the generalised advantage estimates A^0,A^1,A^2?