How Many Planning Steps? Dyna-Q, Dyna-Q+ and Prioritized Sweeping Under Stale and Stochastic Tabular Models Altair-62N Stemma seed corpus https://github.com/mihir-chauhan/research-harness-papers/tree/main/papers/dyna-planning-under-model-error Abstract—Model-based agents trade sample efficiency hyperparameters. against the risk that the learned model is wrong. We study Index Terms—model-based reinforcement learning, Dyna- this trade-off in the smallest setting where it can be measured: Q, prioritized sweeping, model error, non-stationary environ- tabular Dyna-Q with a last-outcome model on 6x9 mazes ments, planning whose walls change mid-training (blocking, shortcut) or whose transitions are stochastic (slip 0.3), comparing reimplemented I. Introduction Q-learning, Dyna-Q, Dyna-Q+ and prioritized sweeping over 1–100 planning steps per real step, with 20 seeds for the main Model-based reinforcement learning (RL) turns experi- comparison and 10 for the sweeps. Planning clearly helps when ence into a model and then uses the model to generate the model is right (Dyna-Q beats Q-learning on the static maze, paired p = 1.6 × 10−6 ), and Dyna-Q+ recovers from extra updates. In Dyna [1] each real transition is followed a stale model and finds a shortcut where plain Dyna-Q does by n simulated updates drawn from the learned model, not, with its advantage growing with the number of planning so n is a dial between pure model-free learning (Q- steps. Under slip 0.3 the mean cumulative reward of Dyna-Q learning [2], n = 0) and heavy planning. The benefit is with a last-outcome model falls with n (from 86.1 at n = 1 sample efficiency; the cost is that every planning update to 41.5 at n = 100; paired p = 2.1 × 10−4 , 20 seeds). It is above Q-learning (49.0) at n = 1, 5 and 20 and shows no trusts the model. When the environment changes after detectable difference from it at n = 50 and n = 100 (paired the model was learned (a stale model) or the transitions p = 0.93 and 0.31). A control with a count-based (sampled- are stochastic while the model stores a single outcome outcome) model on the same seeds does not decline with n (a wrong model), more planning amplifies the error. The (107.5 at n = 1, 129.4 at n = 100); with α = 0.1 instead of 0.5 same tension drives modern deep model-based RL, where the last-outcome model on the stochastic maze still declines for n > 20 but stays above Q-learning at every n tried. We short rollouts [3] and probabilistic ensembles [4] are used could not test with this design whether Dyna-Q’s post-change to limit compounding model error [5], and where bench- reward on the blocking maze falls with n (the per-seed spread marking studies find large differences across algorithms exceeds the mean at every n ≥ 5). The Dyna-Q+ bonus weight and tasks [6]. must match the reward scale of this implementation: κ ≥ 0.01 The tabular case is the cleanest place to isolate the collapses performance (a mismatch we hypothesise, without testing it, comes from the bonus accumulating through the effect, and the blocking and shortcut mazes of Sutton’s untried-action self-loops; only four values of κ were tried). Dyna work motivate Dyna-Q+ [7] (an exploration bonus Without the untried-action initialisation Dyna-Q+’s post- for transitions not tried recently) as a remedy. Textbook change reward is lower than Dyna-Q+’s own on all five mazes comparisons are, however, illustrative curves: they do (paired p ≤ 4.4 × 10−4 ) and lower than plain Dyna-Q’s on the not sweep the number of planning steps, do not include static and stochastic mazes (p ≤ 1.3 × 10−4 ), with only non- significant trends against Dyna-Q on the other three. After stochastic dynamics, and do not report variability over correcting the predecessor bookkeeping of prioritized sweeping, seeds. This paper runs that controlled experiment on CPU. it is statistically indistinguishable from Dyna-Q in cumulative We ask how n trades early and post-change reward against and post-change reward at n = 10 on the static, blocking, model error for four reimplemented agents, and state five shortcut and stochastic-blocking mazes, and earns less on the falsifiable hypotheses (Sec. IV). Our contributions are stochastic maze (37.8 versus 71.0, paired p = 5.2 × 10−5 ); its higher reward in the first 500 steps depends on when the first an honest, small-scale measurement of the n-dependence goal is reached, and in a window of 500 steps after the first on five maze regimes with 10–20 seeds, a control that goal it is not significant on the static maze (paired p = 0.059). replaces the last-outcome model by a count-based one on All claims concern a small CPU study with fixed, untuned the stochastic mazes, an ablation and sensitivity study of the two Dyna-Q+ ingredients, and the report of what Altair-62N is the codename of an autonomous study, not a person. did not replicate: the design cannot test whether Dyna- Produced by the Stemma autonomous AI research pipeline; the topic Q’s post-change reward falls with n on the blocking maze, was chosen to cover the field. Every reported number comes from logged runs in the linked repository and every reference was checked and the Dyna-Q+ bonus weight needs to match the reward against arXiv, Crossref, DataCite or OpenAlex. scale of this implementation. The blocking and shortcut results and the benefit of planning on a static maze restate regimes with paired seeds; this paper provides a small one. Sutton’s [7] demonstrations with seeds and tests added. It is not a claim that none exists, only that our literature search (platform library, arXiv, Semantic Scholar, Ope- II. Related Work nAlex) did not return one. Dyna and tabular planning. Dyna [1] integrates learn- III. Method ing, planning and reacting by replaying simulated ex- perience from a learned model; prioritized sweeping [8] All agents are ϵ-greedy tabular learners (ϵ = 0.1) with orders planning updates by the size of the expected value step size α and discount γ. After each real transition change, propagating them to predecessors, to use less (s, a, r, s′ ) they apply the direct update [ ] data and time. Q-learning [2] is the model-free reference, Q(s, a) ← Q(s, a) + α r + γ max Q(s′ , b) − Q(s, a) , (1) and Kaelbling et al. [9] survey these methods and the b exploration problem they face. Dyna-Q+ and the block- with a zero bootstrap at the goal. Q-learning [2] stops ing/shortcut mazes originate in Sutton’s integrated Dyna there (n = 0). architecture [7]; we reimplement them from the published Dyna-Q [1] (the method under study) stores the last description. Brea [10] compares prioritized sweeping with observed outcome M(s, a) = (r, s′ ) and, per real step, episodic control, a context where a tabular model is again performs n planning updates: sample (s̃, ã) uniformly from useful. previously taken pairs, read (r̃, s̃′ ) = M(s̃, ã) and apply Model error and search control. van Hasselt et al. [11] the update above with that transition. Because M is ask when parametric models should be preferred over overwritten only when a pair is revisited, it is wrong after experience replay and argue that planning from an im- an environment change until the pair is retried, and it is perfect model is not obviously better than replay. Pan wrong in expectation under slip. et al. [12] study how the states from which the model Dyna-Q+ changes the planning target to is queried (search control) affect Dyna. In deep model- √ r̃ + κ τ (s̃, ã) + γ max Q(s̃′ , b), (2) based RL, MBPO [3] analyses how model error bounds b the useful rollout length, PETS [4] models uncertainty where τ is the number of real steps since the pair was with ensembles, and Moerland et al. [5] survey the area. last tried, and, the first time a state is visited, adds its Wang et al. [6] benchmark many such algorithms. untried actions to the model as self-loops with reward 0 Dyna with stochastic or imperfect models. Planning (“untried” initialisation), so planning can value them. We from a learned model that is wrong or has limited capacity use κ = 10−3 . has been studied for Dyna-style agents: Talvitie [13] on Prioritized sweeping [8] keeps a priority queue. After a self-correcting models, Holland et al. [14] on the effect real transition the pair is queued with priority p = |r + of planning shape in high-dimensional state spaces, and γ maxb Q(s′ , b)−Q(s, a)| if p > θ (θ = 10−4 ). Each of the n Abbas et al. [15] on selective Dyna-style planning under planning updates pops the highest-priority pair, updates it limited model capacity. We have read these only as far from the model, and for every predecessor (s̄, ā) of its state as needed to place our control: they concern models of (pairs whose current model outcome leads there) queues function-approximation agents, whereas we use a tabular it with its new priority if above θ. When a pair’s model model whose error is known by construction. That a deter- outcome is overwritten with a different successor, the pair ministic last-outcome model of a stochastic environment is removed from the predecessor set of the old successor. degrades with more planning and a model that stores the The queue is a heap without de-duplication: a pair can be outcome distribution does not is what one expects from queued several times, and every pop performs one backup the construction; our control measures its size on these from the current model and current Q values, whatever mazes (Table II) and is not offered as a result specialists the priority at which the entry was pushed. Planning stops did not have. The blocking and shortcut results and the early when the queue empties, so it can use fewer than benefit of planning on a static maze restate Sutton’s n updates; the number of backups actually performed is demonstrations [7] with seeds and tests added; what this recorded for every run. paper adds beyond them is limited to the slip variants, Count-based Dyna-Q (control). Used only in the control the control, the sweeps over n and κ and the Dyna-Q+ for H4 (Sec. V): the model keeps, for every pair, the ablation. number of times each outcome (r, s′ ) was observed and Evaluation practice. Agarwal et al. [16] argue that few- each planning update samples the outcome in proportion run RL comparisons should report uncertainty rather than to these counts, otherwise identical to Dyna-Q. Counts are point estimates; we report standard deviations, paired- never discounted, so after an environment change the old seed tests and the number of seeds, though not the interval outcomes keep their weight until they are outnumbered. estimators they propose. All four are reimplemented here from the original Gap. We found no study that sweeps the number descriptions (not the authors’ code); Dyna-Q+ and the of planning steps for Dyna-Q, Dyna-Q+ and prioritized mazes follow the description in [7]. Ablations of Dyna- sweeping together across stale, opportunity and stochastic Q+ switch off the bonus (κ = 0) and/or the untried initialisation by flags; with both off, the agent is exactly fixes both agent and environment randomness; Agent and Dyna-Q, which our runs confirm (identical rows). environment draw from one random stream, so until the first reward Q-learning and prioritized sweeping (whose IV. Experimental Setup planning draws no random numbers) follow the same Tasks. Five 6x9 mazes (start bottom, goal top right, trajectory in a seed, while Dyna-Q’s planning draws shift reward 1 on reaching the goal, then reset to start; every the stream; differences in reward over the first steps episode shares one continuing budget of steps). Static: a therefore mix the algorithm with the time of the first wall on row 2 with a gap at the right, T = 3000. Blocking: goal, which is why we also report the post-goal window. the gap is at the right until step 1000, then closes and a Tables show the mean over seeds, with the standard gap opens at the left, T = 3000. Shortcut: a longer path deviation where stated; figures show mean ± standard exists, and at step 3000 an additional shorter gap opens, error. Where a sweep table lists Q-learning or Dyna-Q on T = 6000. Stochastic: static layout, with probability 0.3 seeds 0–9, these are the main-comparison runs of those the chosen action is replaced by a uniformly random one. seeds. Tests are two-sided Welch and paired-seed t-tests Stoch. blocking: slip 0.3 and the blocking change together. from the harness (rh compare), uncorrected for the many Metrics. cum is the number of goal reaches over the comparisons. Hardware: one CPU core of a shared Apple- run, early over the first 500 steps, post after the change silicon laptop-class machine, pure Python. Per-run wall- (second half of the run for tasks without change) and late clock time is recorded in the registry (runtime_s, declared over the last 500 steps. Post-goal is the number of goal non-deterministic) and is not reported as a result. reaches in the 500 steps after the first goal reach of the run (clipped at the horizon; the clipped length is recorded), V. Results which does not depend on how long the initial random We go hypothesis by hypothesis (Table I, Table V, walk took. Backups is the number of planning updates Figs. 1–3). actually performed. Higher is better for all but backups, H1 (planning helps with a correct model): supported. which is reported only as a count. On the blocking and On the static maze Dyna-Q at n = 10 reaches the goal stochastic-blocking mazes the first 1000 steps are identical 200.2 times against 86.2 for Q-learning (paired p = 1.6 × to those of the static and stochastic mazes respectively, 10−6 ), and the early reward is higher (7.9 versus 1.6, paired so the early-reward values of these pairs of tasks are the p = 0.015, compare_main_early_reward.csv, but with a same data (they coincide in the tables). standard deviation larger than the mean, so the gap over Hypotheses. H1: on the static maze, planning raises the first 500 steps is only weakly resolved). Cumulative reward over Q-learning (refuted if Dyna-Q n=10 is not reward keeps rising with n up to 100 for Dyna-Q on this above Q-learning). H2: on the blocking maze, Dyna-Q’s task (Table V). In the 500 steps after the first goal, which post-change reward falls with n and Dyna-Q+ recovers removes the time to the first goal, Dyna-Q earns 37.4 better. H3: on the shortcut maze, Dyna-Q+ gets more against 1.2 for Q-learning on the static maze (paired p = post-change reward than Dyna-Q. H4: under slip, the 3.0 × 10−17 ). Q-learning is also far below the planners on benefit of planning shrinks or reverses at large n. H5: prior- the blocking and shortcut mazes. itized sweeping matches Dyna-Q on static tasks and shares H2 (stale model): first half not testable with this design, its staleness failure. The hypotheses and their refutation second half supported. The 10-seed sweep cannot resolve criteria were fixed before the final runs (BRIEF.md). whether Dyna-Q’s post-change reward on the blocking Protocol. Main comparison: n = 10 for the three maze falls with n. It is lowest at n = 1 and between planning agents, 20 seeds (0–19), 5 tasks. Sweep over n ∈ 17.8 and 29.6 for n ≥ 5 (Fig. 1), with per-seed standard {1, 5, 20, 50, 100}: 10 seeds (0–9), three planning agents, deviations of 33.2 to 42.2, larger than the means at every all tasks. Correct-model control for H4: stochastic and n ≥ 5: some seeds recover and others do not, and the stochastic-blocking mazes, n ∈ {1, 5, 20, 50, 100}, Dyna-Q natural measure, the fraction of seeds that recover as a with the last-outcome and with the count-based model, function of n, was not computed and would need more plus Q-learning, 20 seeds (0–19), for α = 0.5 and α = 0.1. seeds than we ran. We therefore neither support nor refute The prioritized-sweeping runs of the main comparison and the first half of H2. At small n the agent is simply slow, of the sweep were rerun after the predecessor bookkeeping which masks any staleness effect, so the model-induced was corrected (Sec. III); the earlier prioritized-sweeping damage is not separable from sampling noise at the n we rows are marked superseded in the registry and no result tried. A failure case is visible in the per-seed spread: Dyna- of this paper uses them. Dyna-Q+ ablation: 20 seeds Q’s blocking cumulative reward has a standard deviation at n = 10. Bonus sweep: κ ∈ {10−4 , 10−2 , 3·10−2 } plus of 39.9 around a mean of 64.5, with some seeds reaching the default 10−3 , all on seeds 0–9. Hyperparameters the goal rarely after the wall moves. Dyna-Q+ does recover (α = 0.5, γ = 0.95, ϵ = 0.1, κ = 10−3 , θ = 10−4 ) better: post-change reward 51.9 versus 28.2 for Dyna-Q at were fixed a priori and not tuned for any method, so n = 10 (paired p = 0.025, uncorrected), and its advantage there is no tuning budget and no held-out split; the grows with n (Fig. 1). Fig. 2 shows the Dyna-Q+ mean environments are fixed and results are over seeds. The seed curve rising more steeply after the change than Dyna-Q’s. TABLE I Main results, n = 10 planning steps, 20 seeds, mean ± std. Bold: best, underlined: second best per task and metric. “Dyna-Q” is the method under study; the others are reimplemented baselines. The early-reward values of the blocking and static rows (and of the stochastic and stochastic-blocking rows) are the same data, because those mazes are identical for the first 1000 steps. Post-goal: goals in the 500 steps after the first goal. Wall-clock time is not tabulated. Method Task cum_reward ↑ post_reward ↑ early_reward ↑ late_reward ↑ first_goal_step ↓ pre_reward ↑ post_goal_reward ↑ n Q-learning blocking 5.80 ± 6.62 1.50 ± 1.67 1.55 ± 1.19 0.25 ± 0.44 515.65 ± 760.07 4.30 ± 7.06 1.05 ± 1.50 20 Prioritized sweeping blocking 79.65 ± 37.72 25.20 ± 33.78 18.60 ± 12.68 10.85 ± 12.82 515.65 ± 760.07 54.45 ± 27.26 35.35 ± 11.11 20 Dyna-Q+ blocking 92.55 ± 14.34 51.85 ± 18.16 4.75 ± 6.54 23.75 ± 2.63 426.45 ± 168.97 40.70 ± 13.68 30.25 ± 8.57 20 Dyna-Q blocking 64.50 ± 39.90 28.25 ± 37.35 7.90 ± 10.56 11.05 ± 13.71 766.90 ± 788.22 36.25 ± 26.55 28.30 ± 12.43 20 Q-learning shortcut 115.10 ± 38.94 112.00 ± 38.78 0.30 ± 0.47 38.00 ± 10.55 1165.50 ± 1135.29 3.10 ± 2.00 0.95 ± 1.00 20 Prioritized sweeping shortcut 266.45 ± 45.62 166.20 ± 16.35 2.65 ± 5.70 28.85 ± 5.50 1165.50 ± 1135.29 100.25 ± 51.08 25.15 ± 6.05 20 Dyna-Q+ shortcut 315.90 ± 16.82 229.65 ± 8.29 0.05 ± 0.22 40.85 ± 2.21 1043.15 ± 353.15 86.25 ± 14.20 14.30 ± 5.48 20 Dyna-Q shortcut 256.75 ± 46.29 165.75 ± 2.00 1.80 ± 4.34 27.55 ± 0.83 1194.20 ± 826.61 91.00 ± 46.49 17.60 ± 2.64 20 Q-learning static 86.25 ± 55.72 75.65 ± 43.30 1.55 ± 1.19 34.40 ± 13.92 457.60 ± 580.67 10.60 ± 19.11 1.20 ± 1.47 20 Prioritized sweeping static 220.60 ± 49.98 127.75 ± 14.20 18.60 ± 12.68 44.10 ± 1.45 457.60 ± 580.67 92.85 ± 39.97 40.40 ± 3.50 20 Dyna-Q+ static 207.80 ± 12.59 124.95 ± 3.36 4.75 ± 6.54 41.25 ± 3.48 426.45 ± 168.97 82.85 ± 14.37 33.30 ± 7.22 20 Dyna-Q static 200.15 ± 48.53 128.40 ± 17.39 7.90 ± 10.56 44.15 ± 0.99 652.10 ± 562.45 71.75 ± 38.83 37.35 ± 5.17 20 Q-learning stochastic 49.05 ± 34.01 42.45 ± 28.32 1.10 ± 1.12 17.30 ± 10.19 501.30 ± 493.16 6.60 ± 7.03 1.20 ± 0.95 20 Prioritized sweeping stochastic 37.80 ± 11.38 21.75 ± 9.10 4.55 ± 4.62 5.25 ± 4.70 501.30 ± 493.16 16.05 ± 9.98 9.80 ± 4.91 20 Dyna-Q+ stochastic 65.60 ± 10.38 36.55 ± 7.10 4.05 ± 4.39 11.25 ± 5.30 386.75 ± 207.16 29.05 ± 8.05 12.40 ± 4.75 20 Dyna-Q stochastic 71.05 ± 28.76 46.10 ± 16.98 4.30 ± 4.95 15.40 ± 6.13 634.75 ± 678.76 24.95 ± 14.95 11.80 ± 5.64 20 Q-learning stoch_blocking 5.05 ± 4.15 2.35 ± 3.60 1.10 ± 1.12 0.70 ± 1.63 583.40 ± 644.51 2.70 ± 2.43 1.05 ± 0.94 20 Prioritized sweeping stoch_blocking 18.40 ± 10.49 8.60 ± 8.00 4.55 ± 4.62 2.95 ± 3.20 583.40 ± 644.51 9.80 ± 8.00 8.10 ± 4.60 20 Dyna-Q+ stoch_blocking 33.90 ± 8.72 18.40 ± 5.28 4.05 ± 4.39 7.70 ± 3.15 386.75 ± 207.16 15.50 ± 6.68 11.25 ± 4.69 20 Dyna-Q stoch_blocking 22.00 ± 15.71 8.20 ± 12.00 4.30 ± 4.95 4.00 ± 5.66 610.00 ± 647.41 13.80 ± 10.43 8.85 ± 5.87 20 TABLE II Correct-model control for H4 (20 seeds): mean cumulative reward of Dyna-Q with the last-outcome model and with the count-based model as a function of n, and paired-seed p-values (uncorrected) of each against Q-learning (n = 0 column) on the same seeds; for step sizes α = 0.5 and α = 0.1. alpha Task Model n=0 n=1 n=5 n=20 n=50 n=100 last-outcome mean 49.0 86.1 88.6 69.2 49.8 41.5 p vs Q 9.1 × 10−4 6.1 × 10−4 4.4 × 10−2 9.3 × 10−1 3.1 × 10−1 0.5 stochastic count-based mean 107.5 117.0 125.4 119.7 129.4 p vs Q 1.1 × 10−6 8.3 × 10−7 3.2 × 10−8 3.1 × 10−6 3.2 × 10−8 last-outcome mean 5.0 14.7 26.1 27.9 18.6 16.9 p vs Q 3.9 × 10−3 3.0 × 10−6 2.2 × 10−5 1.1 × 10−3 1.6 × 10−3 0.5 stoch blocking count-based mean 13.6 28.4 26.6 25.4 28.5 p vs Q 1.1 × 10−2 8.0 × 10−7 5.0 × 10−7 5.4 × 10−7 1.6 × 10−8 last-outcome mean 44.3 102.2 119.3 121.0 90.2 76.4 p vs Q 1.8 × 10−6 6.0 × 10−7 2.2 × 10−7 1.1 × 10−4 3.8 × 10−3 0.1 stochastic count-based mean 114.9 134.0 146.6 134.8 142.5 p vs Q 1.1 × 10−8 1.0 × 10−8 9.9 × 10−11 2.7 × 10−8 3.6 × 10−11 last-outcome mean 4.5 12.2 23.9 27.8 28.9 24.0 p vs Q 7.3 × 10−3 1.4 × 10−6 1.0 × 10−6 1.1 × 10−5 1.6 × 10−4 0.1 stoch blocking count-based mean 12.9 29.3 31.4 28.6 32.5 p vs Q 6.7 × 10−3 3.2 × 10−6 1.3 × 10−8 3.4 × 10−7 9.4 × 10−10 TABLE III TABLE IV Within-method paired p-value of cumulative reward at n = 1 Planning backups actually performed per run at n = 10 (mean over versus n = 100 (20 seeds, uncorrected). 20 seeds), against the nominal number. alpha Task last-outcome count-based Task Dyna-Q Prioritized sweeping horizon ×n 0.5 stochastic 2.1 × 10−4 5.3 × 10−3 0.5 stoch blocking 5.8 × 10−1 8.4 × 10−4 static 30000 15430 3000×10 0.1 stochastic 4.9 × 10−2 1.1 × 10−3 blocking 30000 24663 3000×10 0.1 stoch blocking 2.5 × 10−2 7.2 × 10−6 shortcut 60000 32628 6000×10 stochastic 30000 24997 3000×10 stoch blocking 30000 24176 3000×10 H3 (shortcut): supported. Dyna-Q+ obtains 229.7 post- change goals versus 165.8 for Dyna-Q (paired p = 1.9 × explanation is an inference from the reward counts. Before 10−18 ), and Dyna-Q’s value is nearly constant over seeds the change Dyna-Q+ is not ahead of Dyna-Q (registry and n ≥ 5, consistent with it never discovering the new gap pre-change means are close, with Dyna-Q’s spread much (Fig. 3); we did not log which path each agent used, so this larger), so its gain is post-change. TABLE V Cumulative reward of each agent as a function of n (10 seeds, mean). The n = 0 column is Q-learning on the same seeds. Task System n=0 n=1 n=5 n=20 n=50 n=100 Dyna-Q 188.8 205.1 208.7 215.8 234.8 static Dyna-Q+ 84.5 122.7 190.3 222.3 233.6 235.5 PS 214.4 217.8 222.9 219.9 217.8 Dyna-Q 27.7 58.7 58.4 74.1 78.7 blocking Dyna-Q+ 7.3 8.3 60.5 122.8 146.2 154.4 PS 57.1 62.0 65.5 101.9 87.6 Dyna-Q 210.6 280.0 278.7 272.6 272.3 shortcut Dyna-Q+ 123.9 165.2 278.3 332.4 355.2 356.3 PS 239.4 257.3 262.3 261.9 262.2 Dyna-Q 92.4 83.2 70.5 45.8 39.6 stochastic Dyna-Q+ 55.4 71.1 74.7 54.6 47.3 42.6 PS 92.3 69.1 30.5 15.0 15.0 static blocking shortcut stochastic stoch blocking 80 225 60 20 120 post reward 60 200 15 40 100 40 175 10 Q-learning (n=0) Dyna-Q 20 150 20 5 80 Dyna-Q+ Prioritized sweeping 125 0 0 100 101 102 100 101 102 100 101 102 100 101 102 100 101 102 planning steps n planning steps n planning steps n planning steps n planning steps n Fig. 1. Post-change reward (second half for tasks without a change) versus planning steps n; mean ± s.e. over 10 seeds. Dotted: Q-learning. Q-learning 300 Q-learning Dyna-Q Dyna-Q 80 Dyna-Q+ Dyna-Q+ 250 cumulative reward cumulative reward PS PS 60 200 150 40 100 20 50 0 0 0 500 1000 1500 2000 2500 3000 0 1000 2000 3000 4000 5000 6000 real steps real steps Fig. 2. Cumulative reward on the blocking maze (change at step Fig. 3. Cumulative reward on the shortcut maze (change at step 1000), n = 10, mean ± s.e. band over 20 seeds; dotted line: change 3000), n = 10; mean ± s.e. band over 20 seeds; dotted line: change point. point. H4 (stochastic): with the last-outcome model planning’s (p = 0.044), and no difference is detected at n = 50 benefit shrinks with n; a count-based model does not (p = 0.93) or n = 100 (p = 0.31), where the means are 49.8 shrink; harm relative to Q-learning is not shown for Dyna- and 41.5. The n ≥ 50 threshold is not a property of the Q. Table II gives the 20-seed correct-model control. On data: on the 10 seeds of the original sweep the advantage the stochastic maze at α = 0.5, Dyna-Q with the last- is already not detected at n = 5 (p = 0.10) and n = 20 outcome model falls in mean cumulative reward from 86.1 (p = 0.31), and only n = 1 is significant (p = 0.007); that at n = 1 to 41.5 at n = 100, and the within-method sweep’s n = 1 versus n = 100 test gives p = 0.002. We paired test of n = 1 against n = 100 gives p = 2.1 × 10−4 cannot say planning is worse than no planning for Dyna- (Table III). Against Q-learning (49.0) it is above at n = 1 Q, only that its advantage is detected for n ≤ 20 and not (p = 9.1 × 10−4 ), n = 5 (p = 6.1 × 10−4 ) and n = 20 for n ≥ 50 at 20 seeds. The count-based model, which represents the slip, does not decline on the same seeds: TABLE VI 107.5 at n = 1 and 129.4 at n = 100 (it rises, p = 5.3×10−3 Dyna-Q+ ablation, post-change reward, n = 10, 20 seeds, mean (standard deviation). “w/o both” is Dyna-Q. for n = 1 against n = 100), and it beats the last-outcome model at n = 100 (p = 5.0 × 10−12 ). With α = 0.1 the Variant blocking shortcut static stoch. stoch. blk last-outcome model is above Q-learning (44.3) at every n Dyna-Q+ 51.9 (18.2) 229.7 (8.3) 125.0 (3.4) 36.5 (7.1) 18.4 (5.3) Dyna-Q+ w/o bonus 36.8 (28.8) 168.2 (15.2) 124.3 (28.3) 50.8 (15.5) 13.1 (11.0) tried (largest p = 3.8 × 10−3 ), but still falls from 121.0 at Dyna-Q+ w/o untried 17.3 (23.3) 138.8 (81.3) 52.1 (58.1) 20.1 (16.5) 3.1 (6.4) Dyna-Q+ w/o both 28.2 (37.4) 165.8 (2.0) 128.4 (17.4) 46.1 (17.0) 8.2 (12.0) n = 20 to 76.4 at n = 100 and from n = 1 to n = 100 with p = 0.049; the count-based model again does not decline. The decline on the stochastic maze is therefore associated TABLE VII Sensitivity of Dyna-Q+ (n = 10, 10 seeds, mean) to the bonus with the last-outcome model at both step sizes, smaller at weight κ; the last column is Dyna-Q on the same seeds. the smaller one, and is not an artefact of heavy replay at α = 0.5 alone; the control is a sampled empirical model, Task (metric) 10−4 10−3 10−2 3·10−2 Dyna-Q not the exact slip distribution, and covers one slip level and blocking (post) 39.4 51.7 2.4 2.1 21.0 one layout. On the stochastic-blocking maze every Dyna-Q shortcut (post) 166.1 229.7 3.7 3.0 165.8 variant is above Q-learning at every n and both α (largest static (cum) 218.8 206.0 4.6 4.7 190.2 stochastic (cum) 86.7 66.9 9.2 9.8 78.4 p = 0.011, count-based model at n = 1, α = 0.5), the last-outcome model shows no detected decline at α = 0.5 (n = 1 against n = 100, p = 0.58), and the two models are not distinguishable at every n except n = 100 at α = 0.5 higher; we did not investigate why), 9.8 against 11.8 on (p = 0.014; Table II); absolute rewards there are small. the stochastic maze (p = 0.22) and not distinguishable on On the 10-seed sweep Dyna-Q+ also declines in means stochastic-blocking (p = 0.57). We therefore do not claim (71.1 at n = 1, 42.6 at n = 100, not distinguishable from an early-reward advantage for PS on the static, blocking Q-learning at any n), while prioritized sweeping, after the or stochastic mazes. PS performs fewer planning backups correction of its predecessor sets, falls much further, from than the nominal n per step because its queue empties 92.3 at n = 1 to 15.0 at n = 100, below Q-learning (55.4) (Table IV), and on the static maze its cumulative reward at n = 50 (p = 2.7 × 10−3 ) and n = 100 (p = 1.2 × 10−3 ). varies little with n while Dyna-Q’s rises (Table V); it also H5 (prioritized sweeping): no detectable difference on shares Dyna-Q’s failure to find the shortcut. four of five mazes; worse on the stochastic maze; the Where the method fails. Q-learning, Dyna-Q and PS early-reward advantage is not supported. All prioritized- are all poor on the stochastic-blocking maze; Dyna-Q with sweeping numbers are from the rerun with corrected the last-outcome model at large n on the stochastic maze predecessor sets. At n = 10 PS and Dyna-Q are not has no detectable advantage over Q-learning, and PS falls distinguishable on cumulative reward on the static (220.6 below it; and Dyna-Q+ at n = 1 is worse than Dyna-Q versus 200.2, paired p = 0.22), blocking (79.7 versus on the static maze (122.7 versus 188.8); we conjecture, 64.5, p = 0.24), shortcut (p = 0.56) and stochastic- without a control, that bonus-inflated planning values blocking (p = 0.40) mazes, or on post-change reward on mislead a model with few samples. blocking (25.2 versus 28.2, p = 0.78). On the stochastic VI. Ablations and Analysis maze PS earns less than Dyna-Q: cumulative 37.8 versus 71.0 (p = 5.2 × 10−5 ) and post-change 21.8 versus 46.1 Which part of Dyna-Q+ matters (Table VI). Removing (p = 2.1×10−5 ), so H5’s “matches Dyna-Q” does not hold the bonus lowers post-change reward on the shortcut under slip. With 20 seeds and large standard deviations maze (168.2 versus 229.7, paired p = 6.7 × 10−12 , com- only large effects are detectable, so the non-significant pare_abl_dynaq_plus_post_reward.csv), so the stale- comparisons are not evidence of equivalence. The early- transition bonus accounts for the shortcut gain, and the reward difference of PS (18.6 against 7.9 for Dyna-Q on bonus-free variant equals Dyna-Q there within noise (168.2 the static maze, paired p = 0.014) is confounded: before versus 165.8). On blocking the drop (36.8 versus 51.9) the first goal all Q values are zero and the agents differ is only a trend (paired p = 0.069). Removing only the only in whether planning draws from the shared random untried-action initialisation gives the lowest mean on every stream (Dyna-Q’s does, PS’s does not), and the mean task: with the bonus but without that initialisation the first-goal step is 457.6 for PS against 652.1 for Dyna-Q agent is worse than plain Dyna-Q on the static maze on the static maze. The blocking and static early-reward (52.1 versus 128.4, paired p = 7.0 × 10−6 ) and the rows are the same data (and so are the stochastic and stochastic maze (20.1 versus 46.1, paired p = 1.3 × 10−4 ; stochastic-blocking rows), so they are not independent compare_abl_ref_dynaq_post_reward.csv); on blocking, results. In the 500 steps after the first goal PS earns shortcut and stochastic-blocking the gaps to Dyna-Q are 40.4 against 37.4 on the static maze (p = 0.059), 35.4 trends only (p = 0.30, 0.16, 0.13). Against Dyna-Q+ against 28.3 on blocking (p = 0.11; for late first goals itself the variant without the untried-action initialisation this window can straddle the change at step 1000), 25.1 is lower on all five mazes (largest paired p = 4.4 × against 17.6 on the shortcut maze (p = 1.5 × 10−5 , PS 10−4 , compare_abl_dynaq_plus_post_reward.csv); the gaps to Dyna-Q reported above are against the Dyna-Q stochastic mazes, one slip level, 20 seeds and two step sizes reference. The two components are therefore not separable (α = 0.5, 0.1); it is not an exact model, was not run for improvements. We have not run the interaction in a Dyna-Q+ or prioritized sweeping, and does not cover other finer design. On the stochastic maze the bonus costs layouts or step sizes. The fraction of seeds that recover post-change reward (36.5 versus 50.8 without it, paired after the blocking change was not computed. We did not p = 0.002); a plausible reason, which we did not test, is log per-episode path choices, so mechanism statements that a transition looks stale only because it is noisy and (e.g. Dyna-Q never finds the shortcut) are inferences the bonus drives pointless re-exploration. from reward counts. A full study would add more mazes Bonus weight (Table VII). The default κ = 10−3 was and change times, larger grids, tuned hyperparameters fixed in advance and not tuned. At κ ≥ 10−2 Dyna-Q+ with a held-out protocol, interval estimators from the collapses√ on every task to a handful of goals. A single literature [16], and function approximation. bonus κ τ cannot outweigh the unit goal reward: τ cannot exceed the horizon, so at κ = 10−2 the bonus stays VIII. Conclusion below the goal reward at both horizons. A hypothesis that fits the implementation, which we did not test, is In tabular maze worlds, planning pays for itself when that untried actions enter the model as self-loops the model is right and its benefit shrinks when the model √ with is wrong in the way our setting makes it wrong: with last-tried time zero, so their bonus grows with τ from the start of the run and is bootstrapped through the self- a last-outcome model under 0.3 slip, more planning steps √ reduce Dyna-Q’s cumulative reward (within-method n = 1 loop, giving a fixed point of the order of κ τ /(1 − γ) that can exceed the value of the goal. If so, the collapse is a against n = 100, paired p = 2.1 × 10−4 , 20 seeds), and mismatch between κ, γ and the reward scale specific to its advantage over Q-learning is detected for n ≤ 20 this implementation rather than evidence of a narrow band but not at n = 50 and n = 100. A count-based model of good κ in general; we ran no intermediate κ between on the same seeds does not decline, so the decline goes 10−3 and 10−2 , no other γ and no variant with the bonus with the last-outcome model; it is smaller at α = 0.1 but in action selection. Smaller κ = 10−4 retains the static still present. Dyna-Q+ clearly improves the response to a and stochastic performance but loses most of the post- stale model and an opened shortcut, but its gain depends change advantage (the shortcut gain disappears; blocking on the untried-action initialisation, costs reward under falls between Dyna-Q and the default). We only sampled stochasticity, and collapses at κ ≥ 10−2 , which we read four values of κ. The n sweep (Table V, Fig. 1) is the as a reward-scale mismatch of this implementation that second sensitivity analysis: it is where the planning-step we did not probe with a finer sweep. Our design cannot trade-off of the title is read off. test whether Dyna-Q’s post-change reward falls with n on the blocking maze, and, after correcting its predecessor VII. Limitations bookkeeping, prioritized sweeping was not distinguishable This is a small study. Five hand-built 6x9 mazes, one from Dyna-Q in cumulative or post-change reward at fixed change time per task, one set of hyperparameters n = 10 on four of the five mazes and earned less on the per agent, 20 seeds for the main table and 10 for the stochastic maze; its apparent early-reward advantage did sweeps. Per-seed standard deviations are often a large not survive measuring from the first goal. These are results fraction of the mean (many seeds have a handful of for 20 and 10 seeds on five small mazes with untuned goals), so differences below roughly a quarter of the reimplementations; testing whether they carry over to mean are not resolved; p-values are uncorrected over larger tasks and learned stochastic models is the natural many comparisons and should be read as descriptive. next step. The baselines are our reimplementations from the original descriptions and textbook, not reference code, and details References (tie-breaking, how untried actions enter the model, the [1] R. S. Sutton, “Dyna, an integrated architecture for learning, priority threshold) can matter. We tuned nothing, which planning, and reacting,” ACM SIGART Bulletin, 1991. is fair across methods but means each may be far from its [Online]. Available: https://doi.org/10.1145/122344.122377 best: Dyna-Q+’s collapse at larger κ shows how strongly [2] C. J. C. H. Watkins and P. Dayan, “Q-learning,” Machine Learning, 1992. [Online]. Available: https://doi.org/10.1007/ this matters, and ϵ and α interact with n. We swept BF00992698 n only for Dyna-Q, Dyna-Q+ and PS and with n = 1 [3] M. Janner, J. Fu, M. Zhang, and S. Levine, “When to the early learning is so slow that the staleness effect Trust Your Model: Model-Based Policy Optimization,” 2019. in H2 is confounded, so H2’s first half is inconclusive [Online]. Available: https://doi.org/10.48550/arXiv.1906.08253 [4] K. Chua, R. Calandra, R. McAllister, and S. Levine, rather than disproved at larger scale. The sweeps use 10 “Deep Reinforcement Learning in a Handful of Trials using seeds, which leaves the stochastic-maze comparison with Probabilistic Dynamics Models,” 2018. [Online]. Available: Q-learning underpowered. The main agents store only the https://doi.org/10.48550/arXiv.1805.12114 [5] T. M. Moerland, J. Broekens, A. Plaat, and C. M. Jonker, last outcome. The correct-model control for H4 uses a “Model-based Reinforcement Learning: A Survey,” 2020. count-based sampling model without forgetting on the two [Online]. Available: https://doi.org/10.48550/arXiv.2006.16712 [6] T. Wang, X. Bao, I. Clavera, J. Hoang, Y. Wen, E. Langlois, S. Zhang, G. Zhang, P. Abbeel, and J. Ba, “Benchmarking Model-Based Reinforcement Learning,” 2019. [Online]. Available: https://doi.org/10.48550/arXiv.1907.02057 [7] R. S. Sutton, “Integrated Architectures for Learning, Planning, and Reacting Based on Approximating Dynamic Programming,” Machine Learning Proceedings 1990, 1990. [Online]. Available: https://doi.org/10.1016/ B978-1-55860-141-3.50030-4 [8] A. W. Moore and C. G. Atkeson, “Prioritized sweeping: Reinforcement learning with less data and less time,” Machine Learning, 1993. [Online]. Available: https://doi.org/10.1007/ BF00993104 [9] L. P. Kaelbling, M. L. Littman, and A. W. Moore, “Reinforcement Learning: A Survey,” Journal of Artificial Intelligence Research, 1996. [Online]. Available: https://doi. org/10.1613/jair.301 [10] J. Brea, “Is prioritized sweeping the better episodic control?” 2017. [Online]. Available: https://doi.org/10.48550/arXiv.1711. 06677 [11] H. van Hasselt, M. Hessel, and J. Aslanides, “When to use parametric models in reinforcement learning?” 2019. [Online]. Available: https://doi.org/10.48550/arXiv.1906.05243 [12] Y. Pan, H. Yao, A. massoud Farahmand, and M. White, “Hill Climbing on Value Estimates for Search-control in Dyna,” 2019. [Online]. Available: https://doi.org/10.48550/arXiv.1906.07791 [13] E. Talvitie, “Self-Correcting Models for Model-Based Reinforcement Learning,” arXiv preprint arXiv:1612.06018, 2016. [Online]. Available: https://arxiv.org/abs/1612.06018 [14] G. Z. Holland, E. J. Talvitie, and M. Bowling, “The Effect of Planning Shape on Dyna-style Planning in High-dimensional State Spaces,” arXiv preprint arXiv:1806.01825, 2018. [Online]. Available: https://arxiv.org/abs/1806.01825 [15] Z. Abbas, S. Sokota, E. J. Talvitie, and M. White, “Selective Dyna-style Planning Under Limited Model Capacity,” arXiv preprint arXiv:2007.02418, 2020. [Online]. Available: https://arxiv.org/abs/2007.02418 [16] R. Agarwal, M. Schwarzer, P. S. Castro, A. Courville, and M. G. Bellemare, “Deep Reinforcement Learning at the Edge of the Statistical Precipice,” 2021. [Online]. Available: https://doi.org/10.48550/arXiv.2108.13264