Prioritized experience replay (PER) is a technique in reinforcement learning that samples stored transitions from a replay buffer in proportion to how much the agent can learn from them, instead of uniformly at random. The usual measure of learning value is the magnitude of the temporal difference (TD) error, so surprising transitions are replayed more often than ones the agent already predicts well.
Introduced in 2015 as an extension of the Deep Q-network (DQN), PER improved both learning speed and final scores on the Arcade Learning Environment and became one of the six components of Rainbow DQN. It is used mainly with off-policy, value-based algorithms, although variants also appear in actor-critic methods for continuous control.
How prioritized experience replay selects transitions
PER assigns each stored transition a priority and samples transitions with probability proportional to that priority raised to an exponent. For transition i, the sampling probability is P(i) = p_i^α / Σ_k p_k^α, where α controls how strongly prioritization applies. With α = 0 sampling is uniform, and with α = 1 it follows priorities fully.
After the agent trains on a sampled batch, it recomputes the TD error of each transition and updates its priority. New transitions enter the buffer with the current maximum priority, which guarantees that every experience is replayed at least once before its priority is known. A small constant ε is added to priorities so that no transition ever reaches zero sampling probability.
The original work proposed two ways to turn TD errors into priorities. The table compares them.
| Variant | Priority definition | Strengths | Weaknesses |
|---|---|---|---|
| Proportional | Absolute TD error plus a small ε | Uses error magnitude directly, simple | Sensitive to outliers and reward scale |
| Rank-based | 1 divided by the rank in sorted TD errors | Robust to outliers, heavy-tailed sampling | Needs approximate sorting, ignores magnitude |
In practice, the proportional variant is the more widely implemented option, because a sum tree makes it efficient and reported performance of the two is similar on most benchmarks.
Correcting bias with importance sampling
Prioritized sampling changes the data distribution that the learner sees, which introduces bias into the expected gradient. Stochastic updates assume samples come from the same distribution as the expectation they estimate, so oversampling high-error transitions distorts the fixed point the value function converges to.
PER corrects this with importance-sampling weights w_i = (N · P(i))^(-β), normalized by the largest weight in the batch so that updates are only scaled down. The exponent β is annealed from about 0.4 to 1.0 over training, because unbiased updates matter most near convergence, while early learning tolerates bias in exchange for speed.
| Parameter | Typical value | Effect when increased |
|---|---|---|
| α (prioritization exponent) | 0.5 to 0.7 | Stronger focus on high-error transitions |
| β start (IS exponent) | 0.4 to 0.5 | Less bias early, slower initial learning |
| β end | 1.0 | Full bias correction at convergence |
| ε (priority offset) | 1e-6 to 1e-2 | More uniform sampling of low-error data |
| Buffer capacity | About 1 million transitions | More diverse but staler data |
The weights also reduce the effective step size for frequently sampled transitions, which stabilizes learning when large TD errors would otherwise produce large gradient steps.
Data structures behind efficient sampling
Naive prioritized sampling over a million transitions would be far too slow, so PER relies on a sum tree, a binary tree whose leaves hold priorities and whose internal nodes hold the sum of their children. Sampling and updating both take O(log N) time, which keeps replay overhead small relative to network training.
A common sampling scheme divides the total priority mass into k equal segments and draws one value from each, a form of stratified sampling that lowers variance within a batch. A companion min tree tracks the smallest priority, which is needed to compute the maximum importance weight for normalization.
Prioritized replay compared with other replay schemes
PER is one of several ways to make experience replay more sample-efficient. The comparison below places it among related approaches in the Reinforcement learning topic.
| Strategy | Selection rule | Typical use |
|---|---|---|
| Uniform experience replay | Every stored transition equally likely | Baseline DQN, simple off-policy agents |
| Prioritized experience replay | Proportional to TD error priority | Value-based deep RL, Rainbow DQN |
| Hindsight experience replay | Relabels goals of failed episodes | Sparse-reward, goal-conditioned tasks |
| Distributed prioritized replay | Shared prioritized buffer filled by many actors | Large-scale setups such as Ape-X |
| Combined experience replay | Always includes the newest transition | Very large buffers, fast-changing policies |
These strategies are often combined. For example, hindsight relabeling can feed a prioritized buffer, and distributed systems let actors compute initial priorities so that new data does not all enter at the maximum value.
Limitations and common mistakes
PER is not universally beneficial. Its gains are largest in value-based deep RL with sparse or rare informative events and smaller, sometimes negative, in dense-reward continuous control. Known issues include:
- Stale priorities: transitions not resampled keep outdated TD errors.
- Noise chasing: in stochastic environments, high TD error may reflect irreducible randomness rather than learnable signal.
- Forgetting the importance weights, which leaves the learner biased.
- Overfitting to a small subset of transitions when α is too high.
- Extra compute for priority updates, noticeable with small networks.
Practitioners therefore treat PER as a tunable component to validate, not a default improvement, and compare it against uniform replay under the same budget.
Put simply
Imagine a student reviewing old exam questions. Questions already answered well need little review. Questions that went badly deserve more practice. Prioritized experience replay applies that idea to a learning agent.
The agent keeps a large memory of past moments. It revisits the ones that surprised it most, because surprise means there is still something to learn. A small correction keeps this habit from skewing what the agent finally believes.
In practice
A research team trains a DQN agent on an Atari game in which points are rare and come only after long sequences of correct moves. With uniform replay and a buffer of 1 million transitions, the few rewarding transitions are sampled rarely, and the agent needs many millions of frames before its score improves.
The team switches to proportional PER with α = 0.6 and β annealed from 0.4 to 1.0, storing priorities in a sum tree. Rewarding transitions, which carry large TD errors, are now replayed far more often, and the value estimates propagate back through the preceding states. In their runs, the agent reaches the earlier score level in roughly half the environment frames, at the cost of about 10 percent more wall-clock time per training step.