Lesson 19 of 21 in this unit
Improve a policy using imagined experience.
Fit dynamics, optimize actions inside that model, then test in the external simulator.
By the end: Separate collected data, model fitting, imagined trajectories, policy updates and external evaluation while comparing declared budgets.
Prerequisites and path options
Why learn this? Understand how a learned simulator can reduce environment interaction while introducing errors that policy optimization may exploit.
Start with something concrete.
Trying every action in a real machine can be expensive. A fitted simulator offers cheap practice, but what if its mistakes reward the wrong action?
Try the interactive modelA policy improves inside a learned model. What is still required?
Change one thing. Watch what follows.
Loading this browser experiment…
Understand what changed.
A shorter explanation, with the original worked examples available below. Both explain the same experiment and its limits.
Learn actions inside a model
Collect examples of what a force does to a cart, then fit a small prediction rule. A policy can try imagined trajectories inside that rule before it acts in the external simulator. The same data can support many imagined trials, but model errors can also steer learning toward bad actions.
Follow what changes
The lab starts two policies at zero weights. One learns using fitted dynamics; the other learns using the exact simulator. Both optimize the full trajectory cost and update their two weights together. The fitted dynamics stay fixed. After training, freeze both policies and compare actual externally executed outcomes with doing nothing.
Count the work
Equal policy updates are not equal total resource costs. Each update uses sixteen trajectories. At five steps that is eighty transition calls, paid either to the model or to the simulator. Collection, fitting and evaluation add different work. The displayed counts are not measured time.
Explain the limitation
Compare short and longer imagination at matched updates. A longer horizon may expose useful consequences or amplify model error. The tiny deterministic experiment is public practice, not a reproduction of a large research system or proof of independent proficiency.
Open the full worked examples, calculations and limitations
This is the same reference used in Technical mode. Expand it whenever you need the exact numbers, assumptions or further explanation.
Practice inside a prediction
Suppose each real trial costs time. You collect transitions, fit a model and use its predictions to try different actions. The attraction is reuse: one collection supports many imagined trajectories. The risk is that optimization discovers actions where the fitted model is misleading.
The lab reuses the exact velocity-first cart with 0.1-second intervals, mass 1 kg, linear drag 0.2 and optional quadratic drag 0.6. An affine delta model fits the 96 measured training transitions. It is not handed the plant coefficients. Its weights stay frozen during policy improvement.
What changes during learning?
A two-weight policy chooses force . Here x is position in metres, v is velocity in metres per second, and u is force in newtons; inputs use reference scales of 1 m and 1 m/s. The output always lies between −2 and +2 N. Initially both weights are zero, so no force is applied.
The objective averages after each predicted interval, using those reference units. The first term encourages reaching the origin; the second discourages residual speed; the third prices effort. These are declared design choices, not universal safety criteria.
For each weight, the optimizer evaluates the full trajectory cost at a small positive and negative perturbation. Their difference divided by twice the perturbation approximates the derivative. Both weights update from the same preceding policy, with rate 0.3 and bounds ±3. No imaginary state is silently replaced by a true state within a rollout.
A comparison with an explicit budget
One learner uses the fitted dynamics; another uses the exact simulator during optimization. They share four training starts, zero initialization, horizon and update count. Each update evaluates four candidate weight vectors, each on four starts: sixteen trajectories. At horizon five this is 80 transition calls per update. The simulator-trained comparator pays those calls to the environment; the imagined learner pays them to the model, plus initial data collection and fitting.
Both frozen policies then execute 20 exact intervals at two different public development starts. The initial zero policy is also evaluated. Evaluation uses 120 environment calls total. Fitting arithmetic and other overhead are additional; call counts are not measured time or claims of equal hardware cost.
Short imagination can still be wrong
Compare horizons five and fifteen at matched update counts. A longer rollout makes future consequences visible but also compounds model error. Gentle collection can leave action effects weakly represented. A lower imagined objective does not by itself support an external improvement claim.
The browser recomputes a bounded deterministic comparison, at most forty updates, on request. Exports retain recipes, policies, trajectories and counts. This two-weight experiment teaches the separation between data, model, policy and evaluator; it is not a reproduction of large latent actor–critic systems such as the named DreamerV3 paper.
Both methods use ten policy updates. Are their total resource costs necessarily equal?
Take this idea with you.
Imagination can reuse a learned model for policy improvement. Its value must be measured in external outcomes with data and compute accounted for.
Explore related topics and the topic map
How this topic connects
Explore this topic on the interactive mapUse these connections to review a foundation or choose where to go next. You can open any topic without completing the others.
What it builds on
- Plan briefly then observe again
Compare the benefit of observing and replanning with the work and errors added by a longer search horizon.
Fit dynamics, optimize actions inside that model, then test in the external simulator.
What it enables
- Compare families of world models
Compare research claims by their targets and evidence instead of treating realistic pictures or a model name as proof of useful control.