TL;DR
Agents that learn from a replay memory usually sample old experience uniformly at random, so a rare, informative transition is replayed no more often than a boring one. Schaul and colleagues sample transitions with probability that grows with their temporal-difference error, the size of the surprise between the agent's prediction and its updated estimate. They keep the sampling unbiased in the long run with importance-sampling weights that are annealed to full strength by the end of training. Added to DQN and Double DQN, the method improved the median score across the 49 original Atari games from 48 percent to 106 percent of human level, and it beat uniform replay on 41 of those 49 games.
Builds on: Experience Replay, Deep Q-Network, Temporal-Difference Learning, Importance Sampling · Leads to: later replay methods and the Rainbow combination of value-learning improvements (see Rainbow: Combining Improvements in Deep Reinforcement Learning)
Why it mattered
Most deep reinforcement learning agents trained on images or simulators keep a replay memory, because reusing old experience is cheap and stabilises learning. This paper changed one line of that pipeline, the rule for choosing which stored experience to replay, and got a large gain on the standard Atari suite. The authors report that the boost is complementary to Double Q-learning, so the two can be combined. The prioritized Double DQN agent set a new state of the art on Atari when it appeared, and the paper reports that, on aggregate, learning is about twice as fast.
The idea spread because it costs little. The paper reports a 2 to 4 percent increase in running time for the rank-based variant, and the same sampling idea reappears in many later agents.
History
Experience replay itself is older than deep learning. The paper credits Lin (1992) for the idea of reusing stored transitions. The Deep Q-Network (Mnih and colleagues, 2013 and 2015) made it central to deep reinforcement learning. DQN sampled its memory uniformly and revisited each transition about eight times on average. Earlier work had already used prediction error to decide where to focus effort, notably prioritized sweeping in planning, and this paper adapts that idea to model-free learning with sampled transitions.
The problem
A DQN agent stores its experience in a sliding window of recent transitions and replays them uniformly at random. Two things go wrong. First, a transition the agent already predicts well is replayed as often as a transition that is badly wrong, so most updates teach little. Second, rare, valuable experience, such as the single success in a long chain of failures, is replayed only a few times before it leaves the window.
The paper's motivating example makes the cost concrete. In the Blind Cliffwalk task with states, a random sequence of actions reaches the reward with probability , and the one useful transition is hidden among highly redundant failures. Replaying the transitions in a good order can learn it in exponentially fewer updates than uniform replay needs.
How it works
We trace a tiny replay memory with three transitions, each with a stored error. The transition's priority is the size of its last TD error, . For this trace we use the simplest choice: priority equals , and the exponent is 1.
- Store with a priority. Each new transition enters the memory with the largest priority seen so far. This makes sure every transition is replayed at least once before its error is known. Check: if the largest priority so far is 2.0, a new transition gets 2.0.
- Compute each priority. Suppose three stored transitions have last errors , and . Their priorities are these values.
- Turn priorities into probabilities. Divide each priority by the total, . The sampling probabilities are about 0.038, 0.192 and 0.769. Check: they sum to 1.
- Sample a minibatch. Draw transitions from these probabilities. The high-error transition is drawn about 77 percent of the time, and the low-error one about 4 percent.
- Update and refresh the priority. After a learning step on a sampled transition, its priority is set to its new TD error. Transitions that become well predicted drop in priority and are replayed less often.
- Correct the bias. Replaying surprising transitions more often changes the distribution the updates come from, so each update is scaled by an importance-sampling weight. The weight is largest for rarely drawn transitions, and the scaling is reduced to keep updates stable (the math section gives the formula).
Here is the loop in the full agent, from Algorithm 1 in the paper:
flowchart LR A["Act and store transition with max priority"] --> B["Every K steps: sample minibatch by priority"] B --> C["Compute TD error and IS weight"] C --> D["Update network with weighted TD error"] D --> E["Set each sampled priority to its new |TD error|"] E --> A
Two implementation points make this practical with a million stored transitions. The rank-based variant keeps the memory in an approximately sorted binary heap, which is a tree-shaped array where the largest value sits at the top, and samples from fixed segments. The proportional variant keeps a sum-tree, where each parent stores the sum of its children, so a sampling value can be found by walking down the tree in logarithmic time.
The math
Let the memory hold transitions with priorities . The two variants are defined as follows.
Step 2 in symbols: the priorities
The proportional variant sets , where is a small positive constant so that a zero error still gives a non-zero chance. The rank-based variant sets , where is the position of transition when the memory is sorted by from largest to smallest.
Step 3 in symbols: the sampling probability
The probability of sampling transition is
The exponent sets how much prioritization is used. With every transition has the same probability, which is uniform replay. With the probability is proportional to the priority. The paper's tuned values are for rank-based and for proportional.
Step 5 in symbols: the priority update
After a transition is replayed and its new TD error is computed, its priority is set to (plus in the proportional variant). The TD error is
which is the Double DQN form: the online network chooses the next action and the target network scores it.
Step 6 in symbols: the importance-sampling correction
Each sampled transition gets the weight
which fully undoes the non-uniform sampling when . The paper's Algorithm 1 uses the equivalent form and divides by the largest weight in the minibatch, so the weights only scale updates downward. The weighted TD error replaces in the update.
The schedule for starts at a value and rises linearly to 1 at the end of training:
where is the current step and is the total number of steps.
Worked examples
Use three transitions with priorities , and , so , , , and .
- The total is .
- The probabilities are , , and .
- Raw weights are . For transition 1: . For transition 2: . For transition 3: .
- The largest raw weight is , so divide every weight by it.
- The normalised weights are , and .
Interpretation: the rarely drawn transition 1 keeps full weight, and the frequently drawn transition 3 is scaled down to a twentieth. Its update is still applied, but its share of the total change is smaller.
The Atari setup in the paper keeps a sliding window of transitions and performs one minibatch update of 32 transitions for each 4 new transitions.
- Each update samples 32 transitions.
- There is one update per 4 new transitions, so there are samples per new transition on average.
- This matches the paper's statement that every transition is replayed about 8 times in the uniform baseline.
- The proportional variant uses . At 25 percent of training, , so .
- At the midpoint, . At the end, .
Interpretation: early in training the correction is weak, so learning is faster. By the end the correction is complete, so the final solution is unbiased.
The text reports median normalised scores across the 49 original games (random play is 0 percent, human is 100 percent). Plain DQN has a median of 48 percent, and DQN with rank-based prioritized replay has a median of 106 percent.
- The gain in median is percentage points.
- For Double DQN over 57 games, the median rises from 111 percent to 128 percent.
- The gain is percentage points.
- The mean over 57 games rises from 418 percent to 551 percent, a gain of 133 points. The paper warns that one game, Video Pinball, dominates the mean, so the median is the safer number.
- The paper's learning-speed summary says rank-based prioritization reaches Double DQN's median-of-maximum score at 47 percent of total training time, and proportional at 38 percent.
Try it: a run uses 200 million frames of training, as in the paper's learning curves. At 47 percent of training, how many frames have been seen, and why is the median gain over plain DQN larger than the gain over Double DQN? Answer: million frames. The gain over plain DQN is larger because plain DQN starts from a weaker baseline (48 percent) than Double DQN (111 percent), so there is more room to improve.
Results
All numbers come from the paper's text and captions. The Atari learning curves are single training runs, and the headline comparisons use human-starts evaluation.
- Atari, DQN baseline (49 games). Prioritized replay improves the score on 41 of 49 games. The median normalised score rises from 48 to 106 percent.
- Atari, Double DQN baseline (57 games). The median rises from 111 to 128 percent and the mean from 418 to 551 percent. The paper names games such as River Raid, Seaquest and Surround that reach human level for the first time.
- Learning speed. The paper summarises learning speed as equivalence points, the fraction of training at which the prioritized variant matches the Double DQN baseline. For the maximum-score curve these are 47 percent (rank-based) and 38 percent (proportional). For the mean-score curve they are 41 and 43 percent. Section 4 states that learning is about twice as fast on aggregate.
- Cliffwalk (Figures 1 and 2). The oracle and the prioritized variants learn with far fewer updates than uniform replay, with differences of several orders of magnitude on a log scale. This is the paper's evidence that order matters.
- Class-imbalanced MNIST (Section 6). With 99 percent of the examples for digits 0 to 4 removed, uninformed prioritized sampling beats uniform sampling on the test set and approaches the uniform baseline that was told the imbalance. The paper presents this in its Section 6 extensions, alongside other ideas.
Common mistakes and tradeoffs. It is tempting to think that replaying high-error transitions more often always helps. The paper's finding is that the bias it creates must be corrected near convergence, and that it matters most at the end of training. It is tempting to think that the TD error is the true measure of what an agent can learn. In fact the paper says the TD error is only a proxy for expected learning progress, and it is unreliable when rewards are noisy; its Appendix A discusses alternatives, such as priorities based on how much the weights change and asymmetric treatment of positive and negative errors, as possible improvements. It is tempting to think that the two variants differ a lot. The paper finds they usually perform similarly, and it suspects the reward and error clipping used by DQN is why.
When to use prioritized replay: a learner that reuses a large stored memory and can afford the extra bookkeeping, with a training signal whose error is informative. When not to use it: when the memory is small enough that uniform sampling already covers everything, when rewards are very noisy so that errors mostly measure noise, or when the extra storage and tree updates are too costly. Alternatives include the staleness bonus and the hybrid sampling that the paper discusses in its appendix, and the off-policy correction it describes in Section 6.
Reading guide
- Abstract and Section 1. The two problems with uniform replay, and the idea of replaying important transitions more often. Needs Experience Replay and Deep Q-Network.
- Section 2 (Background). Read it for context on prioritized sweeping and TD error as a priority. Needs Temporal-Difference Learning.
- Section 3.1 (Motivating example). Figure 1 and Figure 2 show the Blind Cliffwalk. Needs Q-Learning for the update used there.
- Section 3.2 (Prioritizing with TD error). The greedy priority and its failure modes. Needs Bellman Equation for the TD error.
- Section 3.3 (Stochastic prioritization). Equation 1 and the two variants. Needs Priority Queue and Binary Tree for the implementation paragraphs. Work Example 1 alongside.
- Section 3.4 (Annealing the bias). The importance-sampling weights. Needs Importance Sampling and the schedule for .
- Section 4 (Atari experiments) and Algorithm 1. The results. Needs Double Q-Learning and Deep Reinforcement Learning with Double Q-Learning for the baseline.
- Sections 5 to 7 and the appendices. Discussion, extensions, and implementation details. Read Appendix B.2.1 for the heap and sum-tree.
Check yourself
QuestionIn one or two sentences, why does the paper need importance-sampling weights if it wants prioritized replay to learn the right values?Show answer
Prioritized sampling replays some transitions more often than their natural frequency, so the average update no longer matches the true expectation under the environment. The importance-sampling weights scale each update by the inverse of how much it was over-sampled, which removes that bias when . The paper anneals toward 1 so that early learning is faster and the final solution is unbiased.
QuestionThree transitions have priorities 1, 2 and 5 under proportional prioritization with and . What is the probability of sampling the transition with priority 5?Show answer
The total is , so the probability is , or 62.5 percent.
QuestionA new transition enters the memory before its TD error is known. Why does the paper give it the largest priority seen so far?Show answer
A transition that has never been replayed has no measured error, so it could be wrongly ignored if it started with a low priority. Giving it the maximum priority guarantees that every transition is replayed at least once before the agent relies on its error.
QuestionA Double DQN run uses 200 million frames, and the rank-based variant reaches the equivalence point at 47 percent of training on the maximum-score curve. Roughly how many frames is that, and what does the number mean?Show answer
million frames. It means the prioritized agent reaches the median score that the Double DQN baseline reaches over its whole run, about halfway through training, so prioritized replay learns faster in frames.
QuestionA game designer uses prioritized replay for a bandit-like problem where each episode lasts one step and rewards are very noisy. Name one reason the paper's method may fit poorly, using the paper's own discussion.Show answer
The paper says the TD error can be a poor estimate when rewards are noisy, because high error may just reflect noise. Its own appendix notes the TD error ignores inherent stochasticity, which is the situation here. The designer should consider the alternatives the paper discusses, or check whether uniform replay already works.
Sources
- Schaul, Quan, Antonoglou, Silver, "Prioritized Experience Replay," arXiv:1511.05952, 2015. https://arxiv.org/abs/1511.05952
- van Hasselt, Guez, Silver, "Deep Reinforcement Learning with Double Q-learning," arXiv:1509.06461, 2015. https://arxiv.org/abs/1509.06461