research29 min studyLesson 645 in Engineering

Replay priorities: correct the actual sampling distribution

Derive proportional sampling and importance weights while preserving transition identity, support, and the limited meaning of fixed-buffer correction.

On this page

What you’ll understand

  • Calculate proportional replay probabilities and fixed-buffer importance weights.
  • Distinguish full correction from partial or normalized weighting.
  • Prevent priority updates from targeting an overwritten replay slot.

Replay changes which stored experiences influence the next update. Prioritized replay intentionally samples some items more often, so treating the minibatch as uniform data changes its expected contribution. The original prioritized experience replay paper describes priorities, sampling exponents, and importance weights, while Ape-X places replay in a distributed actor-learner architecture. We derive a fixed-buffer, with-replacement sampling example. That narrow correction does not make stale behavior on-policy, solve every bootstrap bias, or guarantee convergence of nonlinear reinforcement learning.

Define the population and the probability used to sample it

A replay item needs an immutable logical identity, behavior provenance, episode and timestep links, boundary masks, and any recurrent or multistep context required by the learner. Capacity management may store these in a ring, but a physical slot is not a permanent item identity. Give each slot reuse a generation or equivalent identity so a delayed priority update cannot modify a new item that replaced the sampled one. Record the sampling probability and population size associated with the draw, because priorities and the population can change before the learner returns its update.

In proportional prioritized replay, a positive priority raised to an exponent determines relative sampling mass. A small positive priority floor can preserve support for low-error items, but the actual probability must include every implemented mixture, partition, or sequence-sampling rule. A two-stage distributed sampler needs the product or otherwise derived final probability, not just its local leaf weight. Sequence priorities, duplicate handling, and sampling without replacement require their own probability model. State the population being corrected: uniform stored transitions is different from uniform episodes or the current policy’s state distribution.

P(i)=piα∑j=1Npjα,wi=(NP(i))−βP(i)=\frac{p_i^\alpha}{\sum_{j=1}^{N}p_j^\alpha},\qquad w_i=(NP(i))^{-\beta}
For a fixed N>0 item buffer, priorities pi>0, α≥0, and 0≤β≤1, P is the with-replacement sampling probability and w the unnormalized importance weight toward a uniform-item target. Priorities may derive from absolute TD error plus a positive floor, but that choice is part of the algorithm.↔ Scroll wide equations horizontally.

Full fixed-buffer correction has a precise scope

At beta one, unnormalized weights can recover the uniform fixed-buffer expectation of a specified contribution when sampling probabilities are correct and positive. Beta below one leaves a different expectation. Large inverse probabilities can increase variance, motivating partial correction or other controls, but those choices change the estimator. A common deterministic normalization by the maximum buffer weight rescales the whole expected update rather than preserving its original magnitude; a minibatch-dependent normalization can add further bias. Do not call all normalized implementations exactly unbiased merely because their exponent reaches one.

This algebra concerns replay selection, not all sources of RL error. The stored data may come from old policies, TD targets may use approximations, and bootstrap learning can couple the contribution to the parameters and target network. A fixed-buffer identity does not supply missing action support or repair an incorrect terminal mask. Inspect priority distributions, effective sampling probabilities, item age, duplicate rate, and task mixture. A large TD error can reflect an informative surprise, noise, or corrupted data; repeatedly replaying it does not automatically improve the intended task.

Ei∼P[wifi]=1N∑ifi(β=1)\mathbb E_{i\sim P}[w_if_i]=\frac1N\sum_i f_i\qquad(\beta=1)
This exact identity uses unnormalized weights, a fixed complete buffer, positive known draw probabilities, and fixed finite contributions fi. It establishes a uniform-buffer expectation only; normalized, clipped, stale, or different sampling schemes require their own analysis.↔ Scroll wide equations horizontally.

Test replay identity and estimator arithmetic together

Use a tiny buffer with distinguishable values to check the sampler and expected weighted contribution independently from a neural-network learner. Test overwrite races, duplicate draws, priority-update retries, and sequence boundaries. If a learner updates priorities after an item has been evicted, reject or safely ignore the stale identity rather than assign the error to the new occupant. Track admission and eviction policy as well as priorities: the population itself determines which experiences can ever be sampled. A sampler cannot recover a missing task distribution solely by weighting the items that remain.

The probability lab illustrates one item’s hypothetical draw frequency. Reset, explicitly set p=0.25 and n=20, predict the expected count, then Play or Step. Compare a fresh Reset with p=0.5 and n=20 explicitly set; means are five and ten. These known independent binary trials do not implement a replay tree, changing priorities, slot generations, or importance weighting, and playback does not draw random minibatches. Use the actual fixed-buffer arithmetic to validate correction rather than infer it from the animated bars.

Normalized weights can change the update magnitude

A fixed two-item buffer has priorities [1,3] and exponent alpha one. Contributions are f=[2,0]. Compute the unweighted replay expectation, full unnormalized correction toward uniform items, and the effect of dividing all weights by their buffer maximum.

  1. Sampling probabilities are [0.25,0.75]. Unweighted expected contribution is 0.25×2=0.5, while the uniform-buffer target is (2+0)/2=1.

  2. With beta one, weights are [2,2/3]. Weighted expectation is 0.25×2×2=1, matching the fixed uniform-buffer target under the stated sampling assumptions.

  3. The maximum weight is two. Dividing all weights by it gives [1,1/3] and expected contribution 0.5. This deterministic common rescaling preserves relative weights but does not preserve the original expected magnitude of one.

The result

The exact unnormalized correction gives one. A normalized implementation needs its scale and any additional estimator effects stated explicitly.

Explore the model

Interactive lab

Interactive lab · probability

One item’s draw probability is only a sampling-count model

Use separate Reset → explicitly set BOTH p and n → predict → Play/Step runs for (.25,20) and (.5,20), with means five and ten. This exact binomial model has no replay population, priority updates, importance weights, or random minibatch playback.

One item’s draw probability is only a sampling-count modelThese are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Current readings: Mean · np: 5; Variance · np(1−p): 2.5; Total probability: 1. All parameters are adjustable with the labeled controls below.03581000.070.150.220.3Successes kP(X = k)k = 0 · P = 9.77e-4
Exact probabilityHighlighted outcomeMean np
Mean · np
5
Variance · np(1−p)
2.5
Total probability
1
t = 0 s

These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forNonuniform sampling and estimator correction are separate pieces of the replay contract.

Check your understanding

A delayed learner returns a priority update for physical slot seven after that slot was overwritten. What should identify the target?

Try it yourself

A fixed three-item buffer has priorities [1,1,2], alpha one, and contributions [3,0,0]. Compute probabilities, beta-one unnormalized weights, and expected corrected contribution. What target does this correct?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Normalize the four total priority units, then use 1/(N×P) for each item.

Compare with the solution

Probabilities are [0.25,0.25,0.5], and weights are [4/3,4/3,2/3]. The weighted expectation is 0.25×(4/3)×3=1, equal to the uniform stored-item mean. This corrects only the fixed-buffer sampling distribution under the with-replacement, positive-probability assumptions. It does not make the stored policy current, remove target approximation, repair a missing episode boundary, or reproduce data already excluded by admission or eviction. Any weight clipping or normalization needs separate accounting.

Take it with you

  • Store actual sampling probabilities and immutable replay item identity.
  • Full unnormalized importance weighting has a fixed-buffer expectation contract.
  • Replay correction does not remove every off-policy or bootstrap-learning bias.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.