One robot, one wind it was never told about, three ways to learn. In a wind of 0.4, the copied policy stops 0.20 short of each goal. The trial and error policy stops 0.07 short. The policy with a learned model lands on it.
Drag the wind up and switch between the three learners. Watch who still reaches the goals. Then we build each part of this bench from zero: the loop, the reward, the policy, the ladder of methods, the world model and the hierarchy.
You need what a probability is and a little Python. We build the rest from zero.
Lecture 2 of 25 in Introduction to Robot Learning (CMU 16-831), taught by Guanya Shi. Every idea is re-taught here in our own words and devices. It follows Lecture 1, What Is Robot Learning? Next: Lecture 3, an ML and deep learning refresher.
Illustrative toy. A point robot accelerates toward each goal while a steady wind pushes it right. Copy is a cautious controller cloned from calm-day demos (gain 2). React learned by trial in the wind (gain 6). Model estimates the wind from its own motion and cancels it. A goal counts when the robot stays within 0.05 of it for 1 s. All three learners run at once; the bars count goals reached since the wind was last set.
Chapter 0
Meet the animal that eats its own brain, and see why the skills we find easy are the hardest ones for a robot
The sea squirt is a small sea animal. As a larva it swims, with a simple eye, a tail and a tiny nervous system. When it finds a good rock, it glues its head down and never moves again. Then it digests most of its own brain.
The neuroscientist Daniel Wolpert tells this story to make one claim:
"We have a brain for one reason and one reason only, and that's to produce adaptable and complex movements."
Once the sea squirt stops moving, it has no use for a brain. So a brain is a controller: a system that turns what it senses into action, again and again, in a world that pushes back. Robot learning builds that controller for a machine.
Which is harder for a machine: chess, or lifting a strange spoon from a strange table? In 1988 Hans Moravec wrote that it is easy to make a computer play checkers like an adult. It is hard or impossible to give it the perception and mobility of a one-year-old. This is Moravec's paradox: what is hard for people is easy for machines, and what is easy for people is hard for machines.
Each dot is a skill, placed by how long evolution or culture has had to tune it. Pick a skill and read when machines caught up with people.
Ages are rough orders of magnitude, not dates. Animal nervous systems: about 600 million years. Eyes: about 500 million. Spoken language: perhaps 100,000 years. Chess: about 1,500. Machine milestones: Deep Blue beat the world chess champion in 1997; language models write fluent text in the 2020s; open-world dexterous movement is not solved.
The oldest skills sit at the left, and they are the ones machines still fail. A skill you do without thought hides hundreds of millions of years of tuning.
The symptom is a robot that fumbles a kitchen task. The tempting cause is weak hardware. The measurement is to let a person drive the same robot by remote control.
The lecture's example is Mobile ALOHA: about $32,000 and 16 degrees of freedom. Driven by a person, it does delicate kitchen work. Driven by its own policy, it fumbles. So the motors are fine. The fix is the algorithm that closes the loop from sensing to action, which is what this course teaches.
Chapter 1
Step through the loop that every method in the course runs, and find the arrow that makes it hard
A small robot cart sits on a track. A charging pad is three cells to its right. Each tick, the cart reads its position, picks a move, and the world answers. That is the whole picture, and Sutton and Barto put it in two boxes and two arrows.
The agent is the decision maker: the thing we build. The environment is everything else: the track, gravity, a person who kicks the cart. They take turns:
Press Step to run one turn of the loop. Press Kick to let the environment shove the cart, and watch the next action change.
Illustrative toy. The policy moves toward the pad. Reward is +1 on the pad and 0 elsewhere. A kick moves the cart two cells left.
Look at the kick. The agent never sees the future. It sees only where it is now, and it must answer that. The arrow that makes robot learning hard runs from the action back into the environment: your action decides the next state you must deal with. That makes it a control problem, not a prediction problem.
The symptom: a policy trained on logged drives scores well on the log and drifts off the road on the robot. The measurement: record the states the robot visits and compare them with the states in the log. The robot's own small errors take it to states the log never shows. The fix is to collect data under the robot's own policy, which Lecture 6 does with a method called DAgger.
Chapter 2
State the reward hypothesis, add up a return by hand, and watch a far-off fall shrink
A walking robot earns +1 for every step it stays upright and −10 when it falls. What is it trying to do? Sutton and Barto answer with the reward hypothesis: you can write every goal as one aim. Make the expected sum of one scalar reward as large as possible over time.
"Walk without falling" and "stack the blocks" each become one number per step. The agent does not chase the reward of this step. It chases the return: the sum of all future rewards, with later rewards counted a little less. A reward that comes later is worth less now, as a dollar next year is worth less than a dollar today.
Call the reward at step t rt. Call the shrink factor for one step of delay the discount, γ, a number between 0 and 1. Call the return G.
G equals the sum over t of gamma to the t, times r-t.
Shrink each reward r-t by gamma once for every step you wait for it. Add the shrunk rewards. The total is G.
The robot is upright for steps 0 to 7 and falls at step 8. With gamma 0.97, the eight +1 rewards add to 7.21. The fall counts −10 × 0.978 = −7.84. G = 7.21 − 7.84 = −0.63. With no discount, G is 8 − 10 = −2.
Outlined bars are the raw rewards. Filled bars are what each one counts after the discount. The line is the running return. Move gamma and the step of the fall.
Illustrative toy: +1 for each upright step, −10 at the fall, then the episode ends.
Lower gamma and the return turns positive. For this stream the sign flips at gamma 0.953. A short-sighted agent stops fearing a fall that is far away. Pay now or suffer later: that trade is the drama of every sequential decision.
The symptom: you pay +1 per upright step, and the robot learns to stand still forever. Standing never falls, so it collects every +1. The measurement: watch the rollouts, not only the return. The fix: reward what you want, such as forward progress per step.
Chapter 3
Trace the shapes from a camera image to one steering number, and fit the simplest policy from three demos
A car drives with a forward camera. Every tick, something must turn the picture into a steering angle. That something is the policy: the function the agent uses to pick an action from a state.
Call the state at tick t st and the action at. Call the policy π (pi). A neural network policy has weights θ (theta): the numbers training changes.
a-t equals pi-theta of s-t.
Give the policy pi-theta the current state s-t. It returns the action a-t. Run it again next tick on the new state.
A 224 × 224 colour image is 224 × 224 × 3 = 150,528 numbers. The policy maps those 150,528 numbers in to 1 number out, such as a steer of −0.3.
Read the shapes: (224, 224, 3) → (1,). Most pixels are sky and road. The policy must find the few that decide the steer, such as the lane lines. A humanoid adds the reverse problem: dozens of joints out, so the space of action sequences explodes.
The grid is a toy camera frame with a lane. Drag the car's offset from the lane centre. The lane pixels shift, and the policy turns that shift into one steering number.
Illustrative toy. The policy weighs each pixel column by its distance from the centre, finds the lane's centre, and steers against the offset with gain 0.8.
Drop the network. Let the state be the car's offset s, and let the policy be a line with slope w and intercept b. An expert gives N demos: pairs of a state si and the expert's action ai. Pick the line with the smallest loss L.
L equals one over N, times the sum over i of pi-theta of s-i minus a-i, squared.
For each demo, run the policy on s-i and subtract the expert's a-i. Square the gap. Average the squares over the N demos. Training picks the theta that makes L smallest.
With made-up demos: offsets −1, 0, 1 and expert steers 0.9, 0.2, −0.8. The best line has w = −0.85 and b = 0.1, so it predicts 0.95, 0.1, −0.75. Gaps 0.05, −0.1, 0.05 give L = (0.0025 + 0.01 + 0.0025)/3 = 0.005. A policy that always outputs 0 scores L = 0.50.
Copying an expert this way is imitation learning in its simplest form. Fit it yourself:
The failure: a policy that keys on the kerb colour, not the lane. It steers well on the training road and badly on a new one. Measure it on held-out roads; fix it with more varied demos.
Chapter 4
Climb four methods, from copying an expert to mining an old log, and watch each one move the same policy
A robot stands at a fork. Right leads to the charger, left to a wall. Its policy gives each move a probability, and at first both are 0.5. How does the right answer get into the policy? The lecture's four methods give four answers. They form a ladder: each rung gets less help.
| Rung | It is given | It learns by |
|---|---|---|
| 1. Imitation | expert demos: states with the expert's actions | copying: fit the action to the state |
| 2. Model-free RL | a reward, and the right to try things | trial and error: make good moves likely |
| 3. Model-based RL | a reward, and data to learn the dynamics | learning a world model, then planning in it |
| 4. Offline RL | a fixed log of past runs, of any quality | mining the log, with no new tries |
Model-free RL builds no model of the world. The lecture sums up its basic method, REINFORCE, in one line: make good stuff more likely and bad stuff less likely. Here is that line as an update. Call the policy's weights θ and the step size α (alpha). Call the return of one try G, and the probability the policy gave the action it took πθ(a | s).
Theta becomes theta plus alpha, times G, times the gradient with respect to theta of log pi-theta of a given s.
Find the direction that makes the action you took more likely. Step the weights theta that way by alpha times G. A big return G means a big step; a return of 0 means no step.
Both preferences start at 0, so p(right) = 0.5. The robot tries right and gets G = 1. For two actions, the gradient is 1 − 0.5 = 0.5 on the right preference and −0.5 on the left. With alpha 0.5 they become +0.25 and −0.25. Now p(right) = 1/(1 + e−0.5) = 0.62.
Pick a rung, then press Train a few times. The bars are the policy at the fork. The counters show what the rung spent: real tries on the robot and expert demos.
Illustrative toy. Imitation reads 5 demos per round from an expert who goes right 90% of the time. Model-free makes one real try per round and applies the update above. Model-based makes 2 real tries to learn what each move does, then trains on 10 imagined tries per round. Offline reweights a fixed log of 20 old runs (8 went right) by their returns.
Read the counters. Imitation stops at 0.9, the expert's own habit. Model-free climbs past it, but pays one real try per round. Model-based climbs fast after 2 real tries. Offline climbs with no tries at all, because its log holds some good runs.
The failure of offline RL: a log that never goes right. Then no reweighting can find the charger. Measure the log's coverage before you train. The fix is better data, which no algorithm replaces.
Chapter 5
Give the robot a model of what its actions do, plan inside it, and see how a wrong model plans toward disaster
Before you step off a kerb, you picture the step in your head. A robot can do the same with a dynamics model, also called a world model. It is a function that says which state follows a state and an action.
Call the state at tick t st, the action at, and the model f.
s-t-plus-one equals f of s-t and a-t.
Hand the model f the state s-t and the action a-t. It returns the next state. Call it again on its own answer to imagine a whole future without moving the robot.
With made-up numbers: a cart is at 2.0 m and moves at 0.5 m/s. It gets a push of 1 m/s² for 0.1 s. f gives position 2.0 + 0.5 × 0.1 = 2.05 m and speed 0.5 + 1 × 0.1 = 0.6 m/s.
| The model is | Where f comes from | Then you use |
|---|---|---|
| Known | physics: mass, friction, geometry | classical control: LQR, MPC, trajectory optimization |
| Learned | fitted to data from the robot | model-based RL: plan inside the learned f |
| None | not built at all | model-free RL: trial and error |
A known model flew Apollo to the Moon. But contact, cloth and dough have no clean equations, so there the robot must learn f or skip it. A learned model turns a few real moves into many imagined ones.
Planning in a corridor shows how. Call the worth of cell c its value V(c), the cost of one move r, and the discount γ. The model says moving right from c lands in c+1.
V of c equals r, plus gamma times V of c-plus-one.
Ask the model where a move takes you. Take that cell's value V(c+1), shrink it by gamma, and add the move's reward r. That is V(c). Sweep from the goal back to the start.
The goal, cell 11, is worth 5. V(10) = −0.1 + 0.95 × 5 = 4.65. V(9) = −0.1 + 0.95 × 4.65 = 4.32. Keep sweeping and V(0) = 1.98: the start is worth going from.
This update is the Bellman backup. Repeat it until nothing changes and you have value iteration.
The robot walks right from cell 0 for a few real moves. Purple bars are what a model-free learner knows. Pink bars are what the model-based learner computes. Then break the model.
Illustrative toy, the same numbers as the Code Lab: 12 cells, goal worth 5 at cell 11, −0.1 per move, gamma 0.95. Both learners know the reward. Only the model-based one turns its moves into the rule "right goes one cell".
The failure: one slip on cell 7 teaches the model a wall that is not there. Every cell left of 7 then values to −2, and the planner stops trying. Measure the model's predictions on fresh real moves. Fix it with more data, and trust it only where it has data.
Chapter 6
Count why one flat search over motor commands explodes, and split it into a short plan and reusable skills
To make a salad, you do not plan every muscle twitch. You think "grab the bowl, chop the lettuce, toss". Then your hands handle each step. Real robots split the work the same way, into a hierarchy.
| Level | What it picks | Speed | Easy for machines? |
|---|---|---|---|
| High-level plan | the next subgoal: "go to the bowl" | about once a second | yes: language models can list the steps |
| Low-level skill | the torques that reach the subgoal | about 50 times a second | no: this is Moravec's hard part |
Why split? Count the options. Say the robot picks one of A motor commands at each tick, for T ticks. Call the number of different command sequences N.
N equals A to the T.
Each tick multiplies the options by A. After T ticks there are A multiplied by itself T times sequences. That is N.
With A = 3 and T = 20: N = 320 = 3,486,784,401 sequences. That is for 20 ticks; a salad takes thousands.
Now split the 20 ticks into 4 segments of 5. The plan picks one of 4 subgoals per segment, and each skill searches only its own 5 ticks:
44 + 4 × 35 = 256 + 972 = 1,228 options, not 3.5 billion
The robot must reach the yellow goal behind a wall. Flat steers straight at the goal. Hierarchy first picks a subgoal at the gap, then runs the same reach skill twice. Press Run, then move the gap.
Illustrative toy. The reach skill is "move straight toward a point". The counts use 3 commands per tick, 4 subgoals, and segments of 5 ticks.
The failure: levels built apart. Classical robots ran perception, planning and control as separate modules, and an error at one handoff grew at the next. The lecture's example is drone racing: it took over seven years to beat the human champion, and then only on one known track. A person wins by coupling the levels. Robot learning aims to learn that coupling.
Chapter 7
Sort the lecture's gallery by rung, then see why closing the loop matters more than the motors
The lecture shows real systems. Every rung of the ladder has a working example.
| System | Recipe | Rung |
|---|---|---|
| Gran Turismo Sophy; DM Control soccer | deep RL in simulation, distributed training, careful reward design | model-free |
| Eureka (pen spinning) | a language model writes the reward function | reward design |
| DeepMind soccer robots; DATT | train in simulation, deploy on hardware, adapt online | sim to real |
| RoboCook; rope whipping | learn a dynamics model from real data, plan in it | model-based |
| Diffusion Policy; Mobile ALOHA | collect human teleoperation demos, imitate | imitation |
Then come the bloopers. Humanoids at the 2015 DARPA Robotics Challenge fall while opening a door. Mobile ALOHA fumbles when it runs on its own. The failures sit where Moravec's paradox says: sensing and handling things in an open world.
Why does a person driving the same robot succeed? The person runs sensing, planning and control as one tight loop. If the cup slides, the eyes see it and the hand bends toward it. A pipeline that looks once and then executes a plan cannot.
Late in the reach, the cup slides. Pick how often the robot looks again and press Reach. Then change the slide.
Illustrative toy. The reach takes 2 s; the cup slides between 1.6 s and 1.75 s. The gripper closes on whatever is within 1.5 cm of its centre. Between looks, the robot aims at the last place it saw the cup.
Look once, or twice a second, and any slide over 1.5 cm is a miss. Look 10 times a second and the gripper bends onto the cup. The measurement for a real robot is the same test: move the object mid-task and record the miss. The fix is a policy that re-reads the state every tick.
The lecture closes with the four pillars from Lecture 1: algorithm, data, computation and hardware. The field has improved each module faster than it has joined them into one brain. That joining is the open frontier.
Chapter 8
Open up the hero, derive exactly how far each learner misses, and break the model on purpose
Back to the hero. A point robot chases goals while a steady wind pushes it right. Each learner uses a controller that pushes toward the goal in proportion to the gap. Why do the first two stop short?
Call the wind's push w and the controller's gain, how hard it pushes per unit of gap, k. Call the gap where the robot comes to rest e. At rest its speed is zero, so the controller's push k × e must cancel the wind.
e equals w divided by k.
The robot settles where its push toward the goal equals the wind. Divide the wind w by the gain k to get that gap e. A stronger gain shrinks the gap but never closes it.
With w = 0.4: Copy settles at e = 0.4 / 2 = 0.20, React at 0.4 / 6 = 0.07. A goal counts only within 0.05, so both miss. Copy misses for any wind above 0.10, React above 0.30.
Model has a third term. It learns a model of its own motion. From the push it gave and the speed change it saw, it estimates the wind. Then it adds the opposite push. Its gap goes to zero. That is model-based RL in one line: learn the part of f you were not told, then plan with it.
All three learners run at once, each chasing its own copy of the goals. The plot below the arena is each learner's running score. Flip the wind mid-run, or give the model a wrong belief.
Illustrative toy. A goal counts after 1 s within 0.05; a goal left for 8 s counts as a miss. Score: +10 per goal reached, −1 per second. The frozen model stops learning and cancels twice the true wind, so it overshoots by w / 6 the other way.
Flip the wind and Model misses for about a second while it re-learns, then lands again. Freeze its belief at twice the wind and it overshoots: a wrong model is worse than a modest one. Copy, React, Model: the ladder of Chapter 4, made visible.
Chapter 9
Keep the course map, the numbers, the terms and the core code of the overview on one page
A brain exists to turn sensing into action. Robot learning builds that loop. An agent observes a state and a policy picks an action. The world returns a reward and a new state, and the agent maximizes the discounted return. The methods differ in where the supervision comes from: demos, trial, a learned model, or a frozen log.
| What | Number | Why it matters |
|---|---|---|
| Walking robot, fall at step 8 | G = −2 (no discount), −0.63 (gamma 0.97), +1.39 (gamma 0.9) | sign flips at gamma 0.953 |
| Camera policy | 224 × 224 × 3 = 150,528 numbers in, 1 out | find the few pixels that matter |
| Line policy from 3 demos | w = −0.85, b = 0.1, L = 0.005 (vs 0.50 for "always 0") | imitation is regression |
| REINFORCE, one good try | p(right) 0.50 to 0.62 with alpha 0.5 | good moves get likelier |
| Corridor values | V(10) = 4.65, V(9) = 4.32, V(0) = 1.98 | a model turns moves into a map |
| Flat vs hierarchy, 20 ticks | 320 = 3.49 billion vs 1,228 | split the search |
| Wind 0.4 | gap 0.20 (gain 2), 0.07 (gain 6), 0 (model) | e = w / k |
| Mobile ALOHA | about $32,000, 16 degrees of freedom | hardware is not the bottleneck |
| Term | Meaning |
|---|---|
| Agent, environment | The decision maker, and everything else. |
| State, action, reward | What the agent decides with, what it does, one number that scores the step. |
| Return | The sum of future rewards, each shrunk by gamma once per step of delay. |
| Reward hypothesis | Every goal is maximizing the expected return of one scalar reward. |
| Policy | The function from state to action; the thing every method learns. |
| Dynamics model | A function from state and action to the next state. |
| Bellman backup | A cell's value is the move's reward plus gamma times the value of where you land. |
| Hierarchy | A slow plan over subgoals on top of fast, reusable skills. |
| Moravec's paradox | Easy for people is hard for machines, and the reverse. |
pythonimport numpy as np def discounted_return(rewards, gamma): # Chapter 2 return sum(gamma ** t * r for t, r in enumerate(rewards)) def fit_line_policy(states, actions): # Chapter 3: imitation as regression A = np.column_stack([states, np.ones_like(states)]) return np.linalg.lstsq(A, actions, rcond=None)[0] # [w, b] def reinforce_step(h, a, G, alpha): # Chapter 4: two-action softmax p = np.exp(h) / np.exp(h).sum() grad = -p; grad[a] += 1 # d log pi(a) / d h return h + alpha * G * grad def corridor_values(n=12, goal=5.0, r=-0.1, gamma=0.95): # Chapter 5 V = np.zeros(n); V[-1] = goal for c in range(n - 2, -1, -1): V[c] = r + gamma * V[c + 1] # Bellman backup return V discounted_return([1]*8 + [-10], 0.97) # -0.63 fit_line_policy(np.array([-1., 0, 1]), np.array([.9, .2, -.8])) # [-0.85, 0.1] reinforce_step(np.zeros(2), 1, 1.0, 0.5) # [-0.25, 0.25] -> p(right) 0.62 corridor_values()[[0, 9, 10]] # [1.98, 4.32, 4.65]
Now press Present or Teach and explain from memory: the loop, the return, a policy's shapes, the four rungs and the gap e = w / k. Then go back to the bench, set the wind to 0.5, and say why only Model still lands.
Based on Lecture 2, "Robot Learning: An Overview", of Introduction to Robot Learning (CMU 16-831), taught by Guanya Shi. The quotes are Daniel Wolpert's and Hans Moravec's (Mind Children, 1988); the loop and the reward hypothesis follow Sutton and Barto, Reinforcement Learning: An Introduction. Toy devices and numbers are our own and labelled illustrative.