PrioritizedSequenceReplay
SequenceReplayPrioritizedSequenceReplay(capacity: int = 1000000, alpha: float = 0.6, beta: float = 0.4, epsilon: float = 1e-06)Sequence replay that samples in proportion to a priority.
Parameters
capacityint= 1_000_000SequenceReplay, in transitions.alphafloat= 0.60 is uniform.betafloat= 0.41 over training; see anneal_beta.epsilonfloat= 1e-6Raises
ValueErroralpha or beta is negative, or epsilon is not
positive.Notes
Reference: Schaul, Quan, Antonoglou, and Silver, "Prioritized Experience Replay", ICLR, 2016 (arXiv:1511.05952).
with proportional priorities .
Prioritizes episodes, not individual transitions, because that is the unit this buffer stores and the unit a sequence model trains on. A chunk's priority is its episode's.
Two details from the paper are easy to leave out and both matter. A newly stored episode is given the largest priority seen so far, so that everything is replayed at least once before prioritization can bury it — Algorithm 1, line 6. And the weights are normalised by their maximum "so that they only scale the update downwards", which keeps the correction from inflating any gradient.
Examples
>>> from lucid.utils.rollout import PrioritizedSequenceReplay
>>> buffer = PrioritizedSequenceReplay(capacity=1000)
>>> buffer.alpha, buffer.beta
(0.6, 0.4)Used by 1
Constructors
1Instance methods
4Store an episode at the largest priority seen.
Parameters
episodeEpisodeSequenceReplay.add.Notes
Eviction can drop episodes off the front, so the priorities are re-laid after the base class has done its bookkeeping rather than tracked incrementally — the buffer is a list and the indices move.
Move beta linearly toward final.
Parameters
fractionfloat[0, 1].finalfloat= 1.0Notes
The correction matters most near convergence, so it is annealed in rather than applied at full strength from the start — the paper's argument is that early training is non-stationary anyway.
sample_prioritized(batch_size: int, length: int)Draw chunks in proportion to priority, with their weights.
Parameters
batch_sizeintSequenceReplay.sample.lengthintSequenceReplay.sample.Returns
PrioritizedBatchThe chunks, where they came from, and the correction weights.
Raises
ValueErrorRewrite the priorities of the episodes just trained on.
Parameters
indiceslist of intsample_prioritized.errorslist of float|delta|, the
temporal-difference error.Raises
ValueError