A robot trained in simulation steps onto ice it never saw. A frozen policy keeps pushing as if the ground were firm, and it stumbles. An adaptive policy reads the ground from its last few steps and recovers within one or two.
Drag the ground severity and count the red footprints in each lane. Then we build the frozen policy and the small estimate it reads. Three ways make that estimate: a running sum, a learned module and a least-squares fit.
You need the closed loop from Lecture 1, a little Python and what an average is. We build the rest from zero.
Lecture 23 of 25 in Introduction to Robot Learning, CMU 16-831 (Spring 2024), taught by Guanya Shi. Slides on the course lectures page. Every idea is re-taught here in our own words and devices. Previous: Lecture 22, Safe RL. Next: Lecture 24, Foundation Models in Robotics.
Illustrative toy. Each step aims for a 1 m stride. The ground gain e is the metres moved per metre commanded: firm 1.0, mud 1 − 0.4 × severity, ice 1 − 0.65 × severity. A step that misses by more than 30% is a stumble. The adaptive robot moves its belief 35% of the way toward each step's measured gain.
Chapter 0
Count what it costs to learn on the spot, and see why adaptation must take a few steps, not a few hundred
You train a four-legged robot in a simulator overnight. It learns a clean trot on firm ground. You carry it outside, and it steps onto ice. Each push now moves the body less than the policy expects, so the feet slip. Then the ground turns to mud, then back to firm.
Why not stop and fine-tune the policy on the ice? Because the robot can fall on every step before it adapts, and a fall can break the hardware. Count the cost.
The curve is the chance of no fall after n unadapted steps. Set the fall chance per step, then slide how many steps the robot needs to adapt.
Illustrative numbers. Real fall risk depends on the gait and the ground; the shape of the curve is the point.
Work the number. Say each unadapted step has a 2% chance of a fall. The chance of no fall in n steps is 0.98 multiplied by itself n times. Fine-tuning that needs 300 steps survives 0.98300 = 0.2% of the time. A read-out that needs 5 steps survives 0.985 = 90% of the time.
The lecture's title has three words. Multi-task means one policy for many goals. Adaptive means one policy for physics it never trained on. Transferable means trained in simulation, working on the real robot. This lesson is mostly about the second word.
The symptom is a policy that walks in simulation and falls outdoors. To measure it, log the stride error on each ground type. The fix is not more training on the ice. It is a policy that reads the ground from its own recent steps.
Chapter 1
Split what changes into the world and the goal, and see why only one of them is hidden
The word adaptation hides two problems. Dynamics-wise adaptation means the physics changed: friction under a foot, a payload, a gust of wind. Task-wise adaptation means the goal changed: a new target, a new path, a new instruction. What matters is which change the robot can see.
The policy reads the goal g and pushes as if the ground gain were 1. Pick what changes, drag it, then watch where the robot lands.
Illustrative toy. The robot travels e × push, and the policy pushes g metres.
How does a hidden parameter enter the physics? Call the state at step t st and the action at. Call the hidden environment parameter et. The world's transition rule P draws the next state.
s-t-plus-one is drawn from P, given s-t, a-t and e-t.
The world takes the state s-t and the action a-t. It also uses e-t, which the robot cannot see. It returns the next state s-t-plus-one.
With made-up numbers: a stride command a-t of 1.0 m on firm ground, e-t = 1.0, moves the body about 1.0 m. The same a-t on ice, e-t = 0.6, moves it about 0.6 m. Same state and action, a different next state.
| Dynamics-wise | Task-wise | |
|---|---|---|
| What changes | The transition, the physics | The reward, the goal |
| The variable | e: wind, friction, payload | g: a target, a path, an instruction |
| Known at test time? | No: the robot must infer it | Usually yes, you tell it |
| Policy form | π(s, z), z an estimate of e | π(s, g) |
Task-wise adaptation is goal-conditioned RL, taught in full in Multi-Task & Goal-Conditioned RL. This lesson stays with the hidden physics. A third route skips adaptation: train one robust policy over many random physics (Lecture 21). It survives everywhere but walks every ground cautiously.
The symptom is a policy that handles new goals but falls on new floors. To measure it, test new goals and new grounds separately. The fix is to give the policy an estimate of e.
Chapter 2
Split the controller into a trained policy and a fast estimator, then step the loop to see which part moves
The robot cannot read e. So we give the policy a stand-in: a short vector z that says which world it is in. Two parts make the controller.
Call the last few states and actions the history ht. Then the whole controller is one line.
a-t equals pi of s-t and A of h-t.
Feed the history h-t to A to get z. Feed z and the state s-t to the frozen policy pi. Send the action a-t to the motors.
With made-up numbers: the last five strides moved 1.0, 1.0, 0.6, 0.6 and 0.6 m per metre commanded. A takes their average, z = 0.76. To move 1 m, the policy commands 1/0.76 = 1.32 m.
The ground turns to ice at step 4. Press Step and follow the dot. Watch which box changes its number and which never does.
Illustrative toy. A is the average of the measured gains in a five-step window. Chapter 7 replaces it with least squares.
The two parts face different limits. The policy is expensive to train and never touched in the field. The adaptation law is small and runs every few milliseconds. Zero-shot adaptation reads only this passive history, with no reward and no trials. Few-shot adaptation gets a few trials first. On hardware, trials cost falls.
The symptom is a twitchy gait: z swings with every noisy step. To measure it, plot z against the true ground in simulation. The fix is a longer window or a smoother A.
Chapter 3
Watch a proportional controller stop short in a steady wind, then add a running sum that estimates the wind and cancels it
Control theory solved a small version of this problem before neural networks. Take a quantity s that we want to hold at 0. Our push is a. An unknown steady wind e adds to every push, so s changes at the rate a + e.
A proportional controller pushes back in proportion to the error, a = −2s. At rest, s stops changing:
The wind wins a little, forever. With e = 0.6, s rests at 0.3.
Teal is s. Pick a controller and drag the wind. With the running sum on, the pink line is its wind estimate.
Illustrative toy: s changes at rate a + e, simulated in 0.02 s steps, gain κ = 1.
The fix keeps a running sum of past error. Call it êk, the controller's estimate of the wind at step k. Call its gain κ and the step length Δt. The push becomes a = −2s − ê.
e-hat-k-plus-one equals e-hat-k plus kappa times s-k times delta-t.
While s-k is not zero, add a little of it to e-hat at each step. The push grows until it cancels the wind. Then s-k is zero and e-hat stops moving, at e.
With made-up numbers: e = 0.6, κ = 1, Δt = 0.5 s, starting from the offset s = 0.3 with ê = 0. Then ê goes 0, 0.15, 0.30, 0.41, 0.49 while s goes 0.30, 0.30, 0.23, 0.15, 0.09. Both settle at ê = 0.6 and s = 0.
| Flavour | Idea | Must the estimate be true? |
|---|---|---|
| MIAC, model-identification adaptive control | Identify the system while it runs. | Yes: it aims for ê = e. |
| MRAC, model-reference adaptive control | Adapt until the system behaves like a reference model. | No: only the behaviour must match. |
Keep the MRAC row: an estimate only has to give the right action. RMA uses this in Chapter 6. Lecture 12 covers adaptive control itself.
The symptom is a sum that keeps growing while the motor is at its limit, then overshoots. To measure it, plot s and ê after a sudden change in wind. The fix is a smaller κ and a clamp on ê (anti-windup).
Chapter 4
Train on many tasks so that one small step fits a new one, and drag the starting point to see why it matters
The running sum came from a model. Contact with mud has no clean model, so we want to learn the adaptation itself. Meta-learning trains across many tasks so that a new task needs only a little data. Its rule, from Vinyals and colleagues: test and train conditions must match. If the robot must adapt from half a second of motion, train it to adapt from half a second.
Why can a little data be enough? Tasks share most of their structure, and the task-specific part lives in a few numbers. Pretraining learns the shared part once.
| Style | How it adapts | Trade-off |
|---|---|---|
| Black box | A network reads the task's small dataset and outputs the task's parameters. | Flexible; its guesses can be unreliable. |
| MAML | One gradient step from a learned starting point. | Uses the same optimizer at test time as in training. |
Call the shared starting parameters θ. Task i has its own loss Li. MAML takes one gradient step of size α on that task.
theta-i-prime equals theta minus alpha times the gradient with respect to theta of L-i of theta.
Start from theta. Find the direction that raises task i's loss L-i fastest. Step the other way by alpha. Meta-training moves theta so that this one step lands well on every task.
With made-up numbers: L-i = (θ − 1.2)2, so its gradient is 2(θ − 1.2). From θ = 0.8 with α = 0.25: θ′i = 0.8 − 0.25 × 2 × (0.8 − 1.2) = 1.0. The loss falls from 0.16 to 0.04.
Yellow rings are five tasks' best parameters. Drag the purple start θ. Each arrow is one step toward a task. Red gaps are what one step leaves.
Illustrative toy: five tasks with losses (θ − w)2, w = 0.4 to 1.2, step size 0.25.
RMA's adaptation module in Chapter 6 is a black-box adapter. When each task is a whole MDP, this is meta-RL, taught in full in Meta-Reinforcement Learning. Meta-learning a dynamics model, not a policy, is the root of Neural-Fly.
The symptom is fast adaptation on training tasks and slow adaptation on the real one. To measure it, hold out tasks and compare the one-step loss. The fix is a wider task spread, so the real task sits inside it.
Chapter 5
Train a teacher that sees the true physics, then copy it into a student that sees only the robot's own sensors
In simulation you know everything: the friction of each patch, the payload, the motor strength. On the real robot you know none of it. Teacher-student training, also called privileged learning, uses this gap.
For driving, Learning by Cheating (Chen and colleagues, 2019) trains a teacher that sees every car and light. Its student sees only the camera. For walking, the teacher sees contact, terrain, friction and pushes. The student sees proprioception.
How is the student trained? Take N simulated moments. Call the teacher's action πt(xi, ei) and the student's πs(xi, hi). The loss L is their average squared gap.
L equals one over N times the sum over i of, pi-s of x-i and h-i minus pi-t of x-i and e-i, squared.
For each moment i, run both policies. Subtract the teacher's action from the student's, square it, and average over N. Change the student to make L small.
With made-up numbers: the teacher outputs −0.5, 0.5 and 1.5 at three moments. The student outputs −0.4, 0.6 and 1.6. Each gap is 0.1, so L = (0.01 + 0.01 + 0.01)/3 = 0.01.
Pick a stage to see what each policy reads. Blue dots are the teacher's actions; the purple line is the student. Raise the history noise to hide the physics from the student.
Illustrative toy, the same as the Code Lab below. The teacher's action is 2e + 0.5, the history reads e plus noise, and the student is a least-squares line.
The symptom is a student that matches the teacher in training and drifts on its own rollouts. To measure it, score the student on the states it visits itself. The fix is to label those states with the teacher, as DAgger does (Imitation Learning).
Chapter 6
Learn a small code for the physics, learn to read that code from 50 steps of motion, then time the two loops
RMA (Kumar, Fu, Pathak and Malik, 2021) walks a quadruped on sand, mud and stairs it never saw. It is teacher-student with one change: the student copies a code, not an action.
Call that window of 50 state and action pairs ht. Phase 2 is a regression.
L equals the squared length of A of h-t minus mu of e-t.
Feed the history h-t to A to get z-hat. Feed the true e-t to mu to get the target z. Square the 8 differences, add them, and train A to make L small.
With made-up numbers on three of the 8 entries: z = (0.5, −0.2, 0.1) and z-hat = (0.4, −0.1, 0.1). L = 0.01 + 0.01 + 0 = 0.02.
| Tensor | Shape | What it is |
|---|---|---|
| e | (17,) | Privileged physics, simulation only. |
| z, z-hat | (8,) | The extrinsics: the only physics the policy sees. |
| state x | (30,) | Joint angles, joint speeds, body orientation. |
| h | (50, 42) | 50 steps of state (30) and action (12). |
| action | (12,) | Joint targets for 12 motors. |
Why a code and not the friction? z only has to make the policy act right. Two grounds that need the same gait can share one z. This is the MRAC idea from Chapter 3. On the A1 robot, A outputs z-hat at 10 Hz and π runs at 100 Hz on the newest z-hat.
The ground changes at 0.5 s. Purple ticks are policy steps; pink ticks are module updates. Set the module rate and its window, then read how long z-hat takes to catch up.
The 10 Hz and 100 Hz rates and the 50-step window are from RMA. The single code entry, its two values and the noise model are illustrative. Here z-hat is the window's average, plus noise that shrinks with window length.
The symptom is a jittery z-hat from a noisy IMU. To measure it, add sensor noise in simulation and plot the z-hat error against the gait error. The design itself is the fix: with 8 numbers and a smooth policy, a small z-hat error gives a small gait error. DATT (2023) instead has the student predict e directly.
Chapter 7
Fit one number to three noisy strides, then watch the estimate lock on as steps arrive
A robot commands a stride a and measures the motion y it gets. On this ground, y is a hidden gain e times a, plus sensor noise. Say e = 0.4: each metre commanded moves 0.4 m. The robot logs three steps.
| Step i | Command ai | Motion yi |
|---|---|---|
| 1 | 1.0 | 0.42 |
| 2 | 2.0 | 0.78 |
| 3 | 3.0 | 1.23 |
Which gain explains these steps best? Least squares picks the estimate ê that makes the sum of squared misses, Σ(yi − êai)2, smallest. Its slope in ê is zero at the best value:
e-hat equals the sum over i of a-i times y-i, divided by the sum over i of a-i squared.
Multiply each command a-i by its motion y-i and add them. Square each command and add those. Divide the first total by the second. That is e-hat.
From the table: the top is 1.0 × 0.42 + 2.0 × 0.78 + 3.0 × 1.23 = 5.67. The bottom is 1 + 4 + 9 = 14. ê = 5.67/14 = 0.405, within about 1% of the true 0.4.
Each Step adds one stride. Blue dots are the strides, the pink line is the fit, the warm dashed line is the truth. Raise the noise and watch the estimate wobble.
Illustrative toy. Commands are 1, 2 and 3 m, then random between 0.5 and 3 m. Noise is Gaussian.
Now act on it. To move 0.8 m, a policy that uses ê = 0.405 commands 0.8/0.405 = 1.98 m and moves 0.79 m. A policy that keeps the nominal gain of 1 commands 0.8 m and moves 0.32 m.
The symptom is an estimate that jumps when the robot barely moves. To measure it, watch Σai2: small commands carry little information. The fix is to keep the old estimate until enough motion has built up.
Chapter 8
Freeze a learned set of force shapes, fit three mixing numbers in flight, and see which ones a hover cannot find
A drone in strong gusts feels a force no one can write down. Neural-Fly (O'Connell, Shi and colleagues, Science Robotics, 2022) handles it with the split we keep meeting. It rests on two observations.
Offline, a network learns a basis φ(x): a few functions of the drone's state x. It trains on about 12 minutes of flight in six wind conditions. Its method, DAIML, uses an adversary to push wind information out of φ. The predicted force is φ(x) mixed by a short vector of wind coefficients ĉ: f-hat = φ(x)·ĉ.
In flight the drone measures the actual extra force f: the gap between the acceleration it commanded and the one it got. Call the estimated coefficients ĉ and the step size γ.
c-hat becomes c-hat plus gamma times, f minus phi of x dot c-hat, times phi of x.
Predict the force with the current c-hat. Subtract that from the measured f. Nudge each coefficient by gamma times the miss times its basis value. The basis phi never changes.
With made-up numbers: x = 0.5 and φ(x) = (1, 0.5, 0.25). True coefficients (0.6, −0.4, 0.2) give f = 0.45. From ĉ = 0 with γ = 0.25, ĉ becomes (0.113, 0.056, 0.028). The prediction miss drops from 0.45 to 0.30.
Teal is the tracking error. Pink bars are ĉ; warm ticks are the true coefficients. Fly a hover, then fly a path, and compare the bars.
Illustrative toy with a 3-function basis (1, x, x2). The update is recursive least squares, the update above with a gain per coefficient that shrinks as evidence builds up.
Neural-Fly's real law is composite adaptation: it also feeds in the tracking error, so the coefficients move to cut the miss on the path. The authors prove the closed loop is exponentially stable.
The symptom is a hover with zero error and wrong coefficients, then a miss on the first new manoeuvre. To measure it, compare ĉ against a fit on a varied flight. The fix is a varied path that excites every basis function.
Chapter 9
Run the whole loop on changing ground: set how fast the estimate moves and how fast the ground changes
This is the hero with every knob. The policy never changes. Only the belief ê moves, by a fraction α of the gap to each step's measured gain.
The top strip is the ground and the footprints. Below, warm dashed is the true gain and pink is the belief. Press Run, then change one knob at a time.
Illustrative toy, the hero's model at severity 0.6. Change rate 1.0 means a new ground about every 16 steps.
Work one transition with α = 0.35. The robot walks from firm ground onto ice with gain 0.61. The first ice step misses by 39%, a stumble. The belief moves to 1 + 0.35 × (0.61 − 1) = 0.86. The next step moves 0.61/0.86 = 0.71 m, a 29% miss, under the 30% line.
The symptom is stumbles even with adaptation on. To measure it, count stumbles per ground change. One per change is the price of noticing; more means α is too small or the ground changes too fast.
Chapter 10
Keep the terms, the numbers, the core loop in code and the links in one place
Every method here has one shape. Train the expensive part once as a function of the hidden situation. Then estimate the hidden situation online from recent motion, and feed the estimate in.
| Method | Frozen part | Moving estimate |
|---|---|---|
| Running sum (Ch 3) | The controller gain | ê, a scalar wind |
| MAML (Ch 4) | The learned start θ | One gradient step |
| RMA (Ch 6) | Base policy π | z-hat, 8 numbers at 10 Hz |
| Neural-Fly (Ch 8) | Basis φ(x) | ĉ, a few wind coefficients |
| Term | One line | Number to remember |
|---|---|---|
| Dynamics-wise | s-t+1 drawn from P given s-t, a-t, e-t; e hidden. | Same stride: 1.0 m firm, 0.6 m ice |
| The design | a-t = π(s-t, A(h-t)). | Window 1, 1, 0.6, 0.6, 0.6: z = 0.76 |
| Running sum | ê grows by κ s Δt each step. | P alone rests at e/2 = 0.3 |
| MAML | θ′ = θ − α times the gradient of L-i. | 0.8 to 1.0; loss 0.16 to 0.04 |
| Distillation | Average squared gap, student to teacher. | Gaps of 0.1: L = 0.01 |
| RMA | A(h) regressed onto μ(e). | e 17, z 8, h 50 × 42; 10 Hz and 100 Hz |
| Least squares | ê = (Σa y)/(Σa2). | 5.67/14 = 0.405 |
| Neural-Fly | ĉ moves by γ times the miss times φ(x). | About 12 minutes of training flight |
pythonfrom collections import deque import numpy as np class AdaptiveWalker: def __init__(self, policy, window=50): self.policy = policy # frozen pi(s, z), trained once in simulation self.hist = deque(maxlen=window) # h: recent (command, motion) pairs def adapt(self): # A(h): least-squares read-out of the gain if len(self.hist) < 3: return 1.0 # nominal until there is evidence a, y = np.array(self.hist).T return (a @ y) / (a @ a) def act(self, s): z = self.adapt() # only this moves online return self.policy(s, z) def observe(self, command, motion): self.hist.append((command, motion))
This lesson follows Lecture 23, "Multi-Task, Adaptive and Transferable Robot Learning", of CMU 16-831 Introduction to Robot Learning, Spring 2024, taught by Guanya Shi. The slides are on the lectures page. The papers are RMA (Kumar, Fu, Pathak and Malik, 2021) and Neural-Fly (O'Connell and colleagues, 2022). Background: Learning by Cheating (2019), MAML (2017) and Matching Networks (2016).
Now press Present or Teach. Explain from memory the two kinds of adaptation, the running sum, the teacher and student, RMA's two phases and two rates, and what Neural-Fly freezes. Then go back to the two robots, push the severity up and say why only one lane stays green.