A replay buffer holds N=4 transitions with absolute TD errors (4,2,1,1). Prioritised experience replay samples transition i with probability P(i)=piα/∑kpkα with pi=∣δi∣ and α=0.5. Compute the sampling probabilities and the importance-sampling weights wi=(NP(i))−β (normalised by their maximum) for β=1 and β=0.5. Why are the weights needed?

Reinforcement learning, Deep Q-networks
Level L4 Advanced. Length Medium. Nature Th+Mat Both.

What's being asked

Whether you can compute prioritised sampling probabilities and see that non-uniform sampling biases the gradient unless corrected.

Key idea

Prioritised replay samples transitions with a large TD error more often, which speeds up learning but changes the data distribution, so the gradient is biased. Multiplying each loss term by wi=(NP(i))−β undoes the bias, fully when β=1.

Steps

  1. Compute piα=pi=(2, 1.414, 1, 1). Their sum is 5.414.
  2. Probabilities: P=(0.369, 0.261, 0.185, 0.185). Check the sum: 0.369+0.261+0.185+0.185=1. With uniform replay each would be 0.25.
  3. Raw weights are 1/(NP(i)) for β=1. Normalising by the largest weight (that of the smallest P) gives wi=Pmin⁡/P(i)=(0.5, 0.707, 1, 1).
  4. For β=0.5, take square roots: w=(0.707, 0.841, 1, 1). A smaller β corrects less.
  5. Explain why weights are needed. The loss is meant to be an average over the buffer's distribution, 1N∑iℓi. If i is drawn with probability P(i), then E[1NP(i) ℓi]=1N∑iℓi, so the factor 1/(NP(i)) restores the unbiased average.
  6. Explain the choices. α=0 gives uniform sampling, and α=1 gives fully proportional sampling. β is annealed from a small value to 1 during training, because bias matters most near convergence. Weights are divided by the maximum to keep the update size stable.
  7. Add implementation facts. Priorities are stored in a sum-tree for O(log⁡N) sampling, new transitions get the maximum priority so that each is replayed at least once, and a small constant is added to ∣δ∣ so no priority is zero.

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: Sketch why UCB1 has regret growing only like O(ln⁡T). For a suboptimal arm i with gap Δi=μ∗−μi, how do you show that it is pulled about 8ln⁡T/Δi2 times at most, and what does this give for Δi=0.5 and T=1000?
Next 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?