5.2.14Deep & Advanced RL

Model-based RL overview

2,105 words10 min readdifficulty · medium1 backlinks

What exactly is "the model"?

WHAT the model gives you: a cheap simulator. WHY we want it: to plan / generate synthetic experience. HOW we get it: either it's given (rules of chess known exactly) or it's learned from data by supervised regression.


Two flavours of using a model


Deriving the learned model as regression (from scratch)

We never dump a formula. Let's build it.

Step 1 — What do we observe? Data tuples D={(si,ai,si,ri)}\mathcal{D}=\{(s_i,a_i,s'_i,r_i)\} collected by acting. Why this step? Because a model must be trained on real cause→effect samples.

Step 2 — Choose a target. We want a function f^θ(s,a)\hat f_\theta(s,a) that predicts ss'. The natural learning objective is to make predictions match reality. Using a Gaussian noise assumption s=f(s,a)+εs' = f(s,a)+\varepsilon, εN(0,σ2I)\varepsilon\sim\mathcal N(0,\sigma^2 I), maximum likelihood becomes least squares. Why this step? Gaussian MLE ⇔ minimize squared error — this is where the loss comes from, not magic.


Deriving planning: why a model buys you value

Once you have P^,r^\hat P,\hat r, planning uses the same Bellman idea as model-free — but computed internally.

For continuous control we often use trajectory optimization / MPC: from current s0s_0, search action sequence a0:Ha_{0:H} maximizing t=0H1γtr^(s^t,at),s^t+1=f^(s^t,at),\sum_{t=0}^{H-1}\gamma^t\,\hat r(\hat s_t,a_t),\quad \hat s_{t+1}=\hat f(\hat s_t,a_t), execute only a0a_0, then re-plan. WHY re-plan every step? To correct for compounding model error (steel-man below).


The canonical loop

Figure — Model-based RL overview

Worked examples


Common mistakes (steel-manned)


80/20 — the 20% that gives 80%


Feynman

Recall Explain to a 12-year-old

Imagine you're learning a video game. A model-free kid just keeps pressing buttons until they win — takes forever and loses many lives. A model-based kid first figures out the rules ("if I jump here I land there"), then plays the level in their imagination to test plans, and only presses the buttons once they've thought it through. They waste far fewer real lives. The danger: if their imagined rules are a little wrong, their imagined plan can be totally wrong — so they only trust their imagination a few steps ahead, then look at the real screen again.


Flashcards

What two things does an environment model predict?
The transition P^(ss,a)\hat P(s'\mid s,a) (next state) and the reward r^(s,a)\hat r(s,a).
Core trade-off of model-based vs model-free RL?
MBRL uses more computation (planning/imagining) to achieve higher sample efficiency (fewer real environment interactions).
Where does the least-squares model-fitting loss come from?
From maximum likelihood under a Gaussian next-state noise assumption; log-likelihood reduces to 12σ2sf^θ(s,a)2-\frac{1}{2\sigma^2}\|s'-\hat f_\theta(s,a)\|^2.
Why predict Δs=ss\Delta s = s'-s instead of ss' directly?
The change is small and stable to regress (states change slowly), avoiding large-magnitude near-identity targets; you add ss back after.
What is the #1 failure mode of learned MBRL?
Compounding model error over long rollouts — small per-step errors accumulate, so plans are made against a wrong "fantasy" model.
Two remedies for compounding model error?
Short planning horizons with frequent re-planning (MPC) and model ensembles / uncertainty estimation.
What is Dyna's key idea?
Use the learned model to generate synthetic (imagined) transitions and run extra value/policy updates on them, amplifying scarce real data.
In MPC, why execute only the first action of the optimized sequence?
To re-plan from the true observed next state each step, correcting for model inaccuracies.
Difference between "model given" and "model learned" settings?
Given = exact rules known (e.g. chess/AlphaZero), only planning is hard; learned = fit dynamics from data (e.g. robotics), adding model-error problems.
Bellman optimality equation used for planning inside a model?
V(s)=maxa[r^(s,a)+γsP^(ss,a)V(s)]V^*(s)=\max_a[\hat r(s,a)+\gamma\sum_{s'}\hat P(s'\mid s,a)V^*(s')].

Connections

  • Model-free RL — the alternative family (learn policy/value directly).
  • Dyna Architecture — integrating learning, planning, and acting.
  • Model Predictive Control (MPC) — plan, execute first action, re-plan.
  • Bellman Equation — the recursion planning relies on.
  • MuZero and Dreamer — value-aware / latent world models.
  • Sample Efficiency — the metric MBRL optimizes.
  • Markov Decision Process — the formal object being modeled.
  • Uncertainty and Ensembles in RL — combating compounding error.

Concept Map

strategy A

strategy B

first learns or uses

predicts

predicts

combine to build

combine to build

enables

imagine cheaply

source: rules known

source: fit from data

Gaussian MLE gives

risk over rollouts

RL agent learns by trial and error

Model-free RL

Model-based RL

Environment model of MDP

Transition P s' given s,a

Reward r s,a

Cheap simulator

Planning via Bellman

Sample efficiency

Model given e.g. AlphaZero

Model learned by regression

Compounding model errors

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, RL me do raaste hote hain. Model-free matlab bina soche button dabate raho jab tak game aata nahi — bahut saari real koshish (aur galtiyan) lagti hain. Model-based RL me pehle hum environment ka ek model seekhte hain: yaani "agar main state ss me action aa karun to next state ss' kya hoga aur kitna reward milega". Ek baar yeh model ready ho gaya, to hum apne dimaag ke andar hi (imagination me) plan bana sakte hain — real world ko touch kiye bina. Isi wajah se MBRL sample-efficient hota hai: real data kam chahiye, computation zyada.

Model kaise seekhte? Simple — yeh ek supervised regression problem ban jaati hai. Data collect karo (s,a,s,r)(s,a,s',r), aur ek function fit karo jo ss' predict kare. Chota trick: direct ss' ki jagah Δs=ss\Delta s = s'-s predict karo, kyunki state dheere-dheere badalti hai, to yeh chhoti quantity fit karna easy aur stable hota hai. Loss square error aata hai kyunki Gaussian noise assume karo to maximum likelihood exactly least-squares ban jaata hai — koi jaadu nahi.

Ab planning: model ke andar hi Bellman equation ya MPC chala do — future ke reward ka sum maximize karne wali action sequence dhundo, sirf pehla action execute karo, phir real next state se dobara plan karo (re-plan).

Sabse bada danger yaad rakhna: model error compound hota hai. Har step ki chhoti si galti H steps me badi ban jaati hai, to agar aap 50 step aage tak imagination pe bharosa karoge to plan galat fantasy pe ban jaayega. Isiliye short horizon rakho, baar-baar re-plan karo, aur model ka ensemble use karke uncertainty samjho. Yaad rakho: LEARN, then DREAM, then DO.

Go deeper — visual, from zero

Test yourself — Deep & Advanced RL

Connections