Prioritized Sweeping
Spend planning backups where the Bellman error is largest, then chase the surprise backward through predecessors instead of sampling at random.
Why Does This Exist?
Model based planning should be cheaper than real experience, but uniform planning wastes the savings. Dyna samples stored state action pairs at random for its simulated backups. In a maze with hundreds of states, almost every sampled pair already agrees with its successor, so the Bellman error is zero and the backup changes nothing. Worse, when the agent first finds the goal, that news must travel backward one random hit at a time. Crossing steps by luck takes on the order of state space size to the draws.
Moore and Atkeson (Machine Learning, 1993), with Peng and Williams arriving independently, replaced luck with a queue. Priority is absolute Bellman error with discount and current estimates . Pop the largest , apply the backup, then look up every predecessor pair that leads into the changed state and queue those whose anticipated error clears a threshold . One surprise ripples home in a focused wave, and planning stops early when the queue empties. For the plan versus learn split behind this, read planning and learning.
Think of It Like This
Repair crews sent upstream from the burst main
A water main bursts downtown. Random patrols would keep checking quiet suburbs while pressure collapses block by block. Nobody runs a grid that way.
Dispatch queues jobs by urgency, fixes the burst first, then walks upstream: which feeder valves push water into the fixed block, and how far are their gauges off now. Those feeders jump the queue next, then their feeders after them. Quiet streets never get a truck. A threshold keeps tiny pressure wobbles off the board entirely so crews are not dispatched for noise.
Where it stops: water flows continuously while sweeping walks a discrete predecessor graph built from past transitions, and crews cannot set a full backup rate of the way a deterministic model backup can. The queue plus upstream chase carries over.
How It Actually Works
The agent keeps a forward model mapping each tried pair to its reward and next state , plus a predecessor registry listing every pair known to land in . Both grow from real steps. Priority is the absolute one step error above. Pairs with enter a max heap; a pair already queued keeps the larger of old and new priority. Each planning iteration pops the max, applies with step , then scores every predecessor in as and queues those above .
Worked example
Chain goal, one action right, , , . The model already knows and with reward , all at .
Goal discovery: the agent takes , gets , lands terminal. Error , so queues at .
Backup 1: pop , set . Predecessor scores and queues at .
Backup 2: pop , set . Predecessor scores and queues at .
Backup 3: pop , set . No predecessors remain, the queue empties, planning halts. Final values match the diagram. Uniform Dyna would need hundreds of random draws to land this exact backward order.
Code
The snippet replays the three priorities with the standard library only.
gamma = 0.9
q3 = 0.0 + (10.0 + gamma * 0.0 - 0.0)print(round(q3, 4)) # -> 10.0
q2 = 0.0 + (0.0 + gamma * 10.0 - 0.0)print(round(q2, 4)) # -> 9.0
q1 = 0.0 + (0.0 + gamma * 9.0 - 0.0)print(round(q1, 4)) # -> 8.1Each print matches the hand derived chain , , with decay factor per hop.
Watch Out For
Threshold set blind to reward scale
The symptom is either a heap that never drains or a wave that dies after one hop. Near zero admits numerical dust in stochastic graphs and heap costs dominate runtime; oversized kills the geometrically decaying wave () before it reaches the start, so distant states never hear about the goal.
Scale to rewards, around times the reward range, and cap planning steps per real step. In stochastic tasks keep expected transitions rather than overwriting with the last sample, or noise spikes keep requeueing phantom urgency.
The Quick Version
- Priority is absolute Bellman error, and a max heap always serves the most wrong pair next.
- A predecessor registry turns each backup into new queue entries one step upstream.
- The plus 10 goal crosses three states in exactly three backups: , , .
- Threshold prunes settled pairs so planning halts when there is nothing worth fixing.
- Uniform Dyna needs hundreds of draws for the same cascade that sweeping aims directly.