From Pieces to a Planner
Introduction
Project introduction
From Pieces to a Planner
You have written every piece of a model-based agent on tiny linear models, including training pairs from episodes, a measure of how imagined rollouts drift, random shooting, one round of the cross-entropy method, and a cautious score that charges for disagreement between models.
In the notebook the same pieces drive a rover in a small yard, with a neural network as the world model. The pieces come already written there. You wire them into a controller that replans after every real step, tune how far ahead it plans, and compare the result with a model-free learner.
What you will see
The model is accurate on ground the random driver covered. After one imagined step it is off by about a thousandth, but after 40 steps the gap is about 70 times larger. With the same budget, CEM finds better plans than random shooting, and replanning every step recovers from a gust of wind that ruins a fixed plan.
Then the flag moves to the edge of the data. A single model believes the reward keeps rising past the flag, and the rover drives into a river it has never seen. Five models disagree beyond the data; a planner that subtracts their disagreement stays dry and stops about 0.16 from the flag. How much to subtract was tuned by trying several values on this job, and caution has a cost. Repeated on new data, the cautious planner stays dry every time but sometimes stops well short of the flag.
Plan in imagination, act, repeat
real step 1Dashed lines are imagined plans. The blue one predicts the most reward, so the rover takes its first step, then imagines again.
How the notebook is organized
01
Learn the world
Random driving, training pairs, a neural model, and rollout drift.
02
Plan inside it
Random shooting, CEM, replanning, the horizon, and a model-free comparison.
03
Stop the cheating
The river, the step where the model went wrong, and two fixes.
Drive a rover by imagination
Run the whole investigation in the browser, about 50 minutes.