Skip to content
AI360Xpert
Beta

Model-Based Deep RL

The agent learns a small simulator of the world from real tries, then practices thousands of imagined moves inside it before each real move.

Ensemble mean 1.50 with epistemic variance 0.000267 below gate 0.05 is accepted into imagined training
Ensemble mean 1.50 with epistemic variance 0.000267 below gate 0.05 is accepted into imagined training

Why Does This Exist?

Model free control treats the world as a black box and needs millions of real tries. On hardware that means wear, time, and crashes. Each transition updates one value or gradient and throws away what it reveals about how the world moves.

Model based deep RL keeps that structure. It fits neural nets to transition and reward from the same real logs, then rolls out imagined trajectories on GPU. Supervised fitting is far cheaper than trial and error, so real samples drop by an order or more. This page shows the ensemble guard and one accepted imagined step. For the plain idea see model based RL, for the seeding trick see Dyna, and for pixel worlds see learning latent dynamics.

You need one idea first. Aleatoric noise is randomness in the world itself. Epistemic doubt is the model not knowing some region yet. Only the second one tells you to stop imagining.

Think of It Like This

A chess player thinking before touching a piece

A novice learns only from tournament games where every blunder costs a match. A stronger player pictures five replies ahead, drops bad lines in the head, and plays one tested move on the board.

When the pictured position feels unfamiliar, the strong player picks a safe solid line rather than a sharp trap built on a guess.

Where the analogy stops: chess rules are fixed and known. A world model starts with no physics and learns from noisy logs, so its imagined lines can invent moves that do not exist.

How It Actually Works

Let ss be state, aa action, and Denv\mathcal{D}_{\text{env}} real transitions (s,a,r,s′)(s, a, r, s'). Let p^θ(s′∣s,a)\hat{p}_\theta(s' \mid s, a) be the learned transition and r^ψ(s,a)\hat{r}_\psi(s, a) the learned reward. Many nets predict a Gaussian over the change:

p^θ(s′∣s,a)=N(s+μθ(s,a),Σθ(s,a))\hat{p}_\theta(s' \mid s, a) = \mathcal{N}(s + \mu_\theta(s, a), \Sigma_\theta(s, a))

Here μθ\mu_\theta is predicted mean change and Σθ\Sigma_\theta is predicted noise. Training minimizes Gaussian log loss on Denv\mathcal{D}_{\text{env}}.

One net hallucinates outside its data, and the policy chases the hallucination. The fix is a bootstrap ensemble of BB nets with different starts and data bags. Let μi\mu_i and σi2\sigma_i^2 be member ii mean and noise, with average mean μˉ\bar{\mu}:

  • Aleatoric noise: σˉ2=1B∑iσi2\bar{\sigma}^2 = \frac{1}{B} \sum_i \sigma_i^2, the world randomness.
  • Epistemic doubt: 1B∑i(μi−μˉ)2\frac{1}{B} \sum_i (\mu_i - \bar{\mu})^2, the member disagreement.

High disagreement means unknown ground. Short branching rollouts keep errors small: seed a real state from Denv\mathcal{D}_{\text{env}}, imagine only kk steps with kk from 1 to 15, store in Dmodel\mathcal{D}_{\text{model}}, and train the actor critic on a mix with most weight on imagined data plus some real anchor.

Worked example

Three nets see s=1.0s = 1.0 and a=0.5a = 0.5 and report means 1.481.48, 1.521.52, 1.501.50 with noise 0.0100.010, 0.0200.020, 0.0150.015:

  • Mean μˉ=(1.48+1.52+1.50)/3=1.50\bar{\mu} = (1.48 + 1.52 + 1.50) / 3 = 1.50.
  • Aleatoric σˉ2=(0.010+0.020+0.015)/3=0.015\bar{\sigma}^2 = (0.010 + 0.020 + 0.015) / 3 = 0.015.
  • Epistemic [(1.48−1.50)2+(1.52−1.50)2+0]/3=0.0008/3≈0.000267[(1.48 - 1.50)^2 + (1.52 - 1.50)^2 + 0] / 3 = 0.0008 / 3 \approx 0.000267.
  • Total 0.015+0.000267=0.0152670.015 + 0.000267 = 0.015267.

Gate τ=0.05\tau = 0.05. Since 0.0002670.000267 sits far below it, the imagined step (1.0,0.5,1.50)(1.0, 0.5, 1.50) joins Dmodel\mathcal{D}_{\text{model}}. The diagram shows the same three dots, the 1.50 mean, and the open gate.

Code

The snippet splits the same two uncertainties and applies the gate.

def ensemble_stats(means: list[float], noises: list[float]) -> tuple[float, float, float]:    """Mean, aleatoric noise, and epistemic disagreement."""    b = len(means)    mean = sum(means) / b    aleatoric = sum(noises) / b    epistemic = sum((m - mean) ** 2 for m in means) / b    return (round(mean, 4), round(aleatoric, 6), round(epistemic, 6))

if __name__ == "__main__":    print(ensemble_stats([1.48, 1.52, 1.5], [0.01, 0.02, 0.015]))    print(0.000267 < 0.05)
# -> expected output:(1.5, 0.015, 0.000267)True

Watch Out For

Rolling a thousand imagined steps and believing the fantasy

The symptom: imagined returns climb while the real robot falls on step one. Feeding each prediction back in compounds error about as k2k^2, so after 15 to 20 steps the states are unphysical yet the critic trusts them.

The fix: branch short runs from real states, schedule kk from 1 upward only as validation steadies, and cut any branch the moment epistemic disagreement passes your gate.

The Quick Version

  • Model based deep RL fits transition and reward nets with supervised loss, then trains the policy mostly on imagined rollouts.
  • A bootstrap ensemble splits world noise σˉ2\bar{\sigma}^2 from model doubt measured by member disagreement.
  • In the example the mean is 1.501.50, aleatoric 0.0150.015, epistemic 0.0002670.000267, total 0.0152670.015267.
  • Doubt below gate 0.050.05 accepts the step, while far regions spike doubt and halt the branch.
  • Short branches from real states bound drift, which is where the sample savings come from.