Worked examples — Model-based RL overview
This page is the "drill ground" for Model-based RL overview. The parent note built the ideas: learn a model (a cheap simulator), then plan inside it. Here we hit every kind of case the topic can throw at you, one worked example per case, so you never meet a scenario you have not seen solved.
Before we start, some symbols we will lean on constantly, defined in plain words right here so you never have to flip back:
The scenario matrix
Every problem in model-based RL falls into one of these cells. The examples below fill all of them.
| Cell | What makes it special | Example |
|---|---|---|
| A. Clean linear fit | Data exactly obeys a linear rule, noise-free | Ex 1 |
| B. Noisy fit | Data has noise; least-squares averages it | Ex 2 |
| C. Degenerate data | Not enough / redundant data → weights undetermined | Ex 3 |
| D. Planning, deterministic | Search action sequences in a known/learned model | Ex 4 |
| E. Planning, stochastic | Next state is a distribution; use expected value (Bellman) | Ex 5 |
| F. Limiting case | Behaviour as (greedy) vs (far-sighted) | Ex 6 |
| G. Compounding error | A wrong model, error grows with horizon | Ex 7 |
| H. Real-world word problem | Robot/thermostat framed in English | Ex 8 |
| I. Exam twist (Dyna count) | Sample-efficiency arithmetic: real vs imagined data | Ex 9 |
Prerequisites we reuse: Markov Decision Process, Bellman Equation, Model Predictive Control (MPC), Dyna Architecture, Sample Efficiency, Uncertainty and Ensembles in RL.
Cell A — Clean linear fit
- Write one equation per sample. Sample 1: . Sample 2: . Why this step? The model must reproduce the observed for the inputs it saw — that is literally what "fit" means.
- Solve the second equation. . Why? It has only one unknown, so it pins immediately.
- Back-substitute into the first. . Why? Now both weights are known.
- Loss. Predictions: ✓ and ✓. Using the loss above with : . Why? Squared error means a perfect simulator — the model reproduces both transitions exactly.
Verify: matches the true rule everywhere. Plan to minimise ⇒ pick , driving state to . Consistent. ✓
Cell B — Noisy fit
- Write the loss. With samples, . Why this step? Same least-squares loss as above, now with the constant prediction standing in for .
- Minimise: set derivative to zero. . Why? The minimum of a smooth bowl-shaped (parabola) loss is where its slope is . That is why we use the derivative here and not, say, sorting — squared error is smooth and convex, so calculus finds the exact bottom.
- Solve. . Why? The mean of the readings. Least squares → the mean is the noise-averaging estimate.
Verify: Mean . True value ; our estimate is close, the bias just reflects this small noisy sample. Loss at is — nonzero because data is noisy, unlike Ex 1. ✓
Cell C — Degenerate data
- Write the equation. , i.e. . Why this step? Each sample gives one constraint; we have one sample.
- Count freedom. Two unknowns, one equation ⇒ infinitely many solutions: all fit with zero loss. Why? This is the degenerate/underdetermined case. Zero training loss does not mean a correct model — a warning the parent's "model errors" theme cares about.
- Consequence for planning. predicts (ignores state); predicts . On a new input they disagree: vs . Why? Degenerate fits generalise unpredictably — this is exactly where an ensemble flags "I don't know."
Verify: Plug : model , model . Both have zero training loss yet disagree by . Underdetermined confirmed. ✓
Cell D — Deterministic planning (MPC)

- Read the rollout tree in Figure s01. The single cyan dot on the left is . Each branch is one candidate first action , moving to a step-1 state; each branch then continues to a step-2 state. Every full left-to-right path is one imagined trajectory . Why this step? Planning = imagining futures with , paying zero real steps. The tree lays out all futures we are comparing at once.
- Follow the amber branch in Figure s01: sequence . This is the thick amber path that drops straight onto the dashed line and stays there. Numerically , . Cost . Why? We sum the per-step costs; so nothing is shrunk. The amber path touches the target line at both steps ⇒ zero cost, which is why the figure highlights it.
- Follow a cyan branch in Figure s01: sequence . (one unit above the dashed line), . Cost — the path reaches target only on the second step, so it pays on the way. Why? A slower descent spends a step away from the target, so it accumulates cost the amber path avoided.
- Compare all paths. The amber path is the only one sitting on the dashed target line at both steps, so it has the minimum cost . Why? MPC picks the lowest-cost imagined trajectory — visually, the path hugging the target line longest.
- Execute only (the first edge of the amber path), then re-plan from the real next state. Why re-plan? To correct compounding model error (see Ex 7) — the core MPC discipline.
Verify: With true dynamics : , then . Real cost , matching the imagined cost. Model was exact so plan is exact. ✓
Cell E — Stochastic planning (Bellman with a distribution)
- Assemble the backup rule. Because the outcome is a distribution, we cannot use one ; we average the landing values weighted by their probabilities. This gives Why this step? When is chance (not our choice), the right tool is the expectation — a probability-weighted mean — not a max over outcomes. A max would pretend we get to pick the coin's result.
- Plug numbers. . Why? Each landing value multiplied by its probability, then discounted by .
- Compute. .
Verify: Expected next value ; times gives . It sits correctly between the pure-outcome values and . ✓
Cell F — Limiting cases of the discount
- Discounted return formula: . Why this step? Return sums rewards, each future one shrunk by ; here is step-0 reward, step-1 reward.
- : , . P wins. Why? kills all future terms — the agent is purely greedy, only matters.
- : , . Q wins. Why? counts the future fully — patience pays.
- Break-even: set , i.e. . Why? Below prefer P, above prefer Q — the discount is the knob for near-vs-far trade-offs.
Verify: At : . Tie confirmed. At : , Q wins as claimed. ✓
Cell G — Compounding model error

- Trace the true rollout (cyan flat line in Figure s02). With , for all — nothing moves, so the cyan line sits flat on . Why this step? Establish ground truth to measure error against; the flat cyan line is the "reality" reference.
- Trace the imagined rollout (amber rising line in Figure s02). , so — the amber line climbs by every step, pulling away from the flat cyan line. Why? Each step adds the same bias; the errors accumulate, they do not cancel.
- Read the error gap. In Figure s02, the white double-arrows at measure the vertical gap between amber and cyan: , , . Formally . Why? Because the same is added every step and never cancels, the total drift is just summed times — this is why long horizons are dangerous even with a nearly-good model.
- State the growth law. The error grows linearly in : . This is the parent's "" rule — small per-step , but long magnifies it, as the widening arrows show. Why? It names the pattern so you can predict drift for any horizon without re-simulating.
- Fix. Keep short and re-plan (MPC, Ex 4), or use an ensemble to stop trusting the model where it disagrees. Why? Short horizons cap ; re-planning resets the imagined state to the true one each cycle.
Verify: , , . Error grows linearly in exactly as predicted. ✓
Cell H — Real-world word problem
- Net change per minute . Why this step? The leak is part of the learned dynamics — the model already includes it, so we plan against reality, not a fantasy where heat is free.
- Try : , . Cost . Why? Evaluate this candidate plan fully inside the model before committing anything.
- Try : , . Cost . ✅ Why? This plan lands exactly on target at step 2, so its second-step penalty is zero.
- Try : , . Cost . Why compare? MPC picks the lowest-cost imagined trajectory; wins.
- Execute , re-measure the real temperature, re-plan. Why? Only the first action is committed; re-measuring corrects any leak-model error next cycle.
Verify: cost ; final temp hits target. Units: temperature squared error (), consistent throughout. ✓
Cell I — Exam twist: Dyna sample-efficiency arithmetic
- Update budget stays fixed: update-transitions needed. Why this step? Convergence depends on total learning signal, whether real or imagined.
- Ratio real:total . Why? Each real transition spawns imagined ones ⇒ total per real step.
- Real interactions . Why? We divide the total updates by updates-per-real-step. This is the sample-efficiency payoff — imagined data amplifies scarce real data.
- Speed-up in real data . Why? Comparing real steps needed with vs without the model gives the amplification factor.
Verify: updates. Real interactions vs ⇒ fewer real steps. ✓
Recall Which cell is which — quick self-test
Ex 1 hits cell ::: A (clean linear fit, zero loss) Ex 3 hits cell ::: C (degenerate / underdetermined data) Ex 5 hits cell ::: E (stochastic planning via expectation) Ex 7 hits cell ::: G (compounding model error, grows like ) Ex 9 hits cell ::: I (Dyna sample-efficiency arithmetic)