Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Learning by watching
A learner driver who only ever watched a perfect instructor drive down the middle of the lane has never seen how to recover from drifting towards the kerb. The first small slip puts them somewhere new, and the mistakes snowball. There are two cures: let the instructor correct the learner while the learner drives, or work out what the instructor was trying to achieve (stay safe, arrive on time) and plan from that goal. The first is DAgger; the second is inverse reinforcement learning.
Imitation learning trains self-driving and robot manipulation policies from human demonstrations, and supervised fine-tuning of language models is behavioural cloning of written answers.
- 1. Behavioural cloning learns from…
- 2. Its main weakness is…
- 3. Inverse RL tries to recover…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Imitation learning: learn a policy from demonstrations, pairs of states and expert actions, without a reward.
- Behavioural cloning (BC): fit π(a|s) to the expert’s actions by supervised learning on the states the expert visited.
- Distribution shift (covariate shift): the learner’s own mistakes take it to states unlike the training states, where its predictions are unreliable; errors compound over the horizon.
- DAgger (dataset aggregation, Ross, Gordon and Bagnell 2011): roll out the current learner, have the expert label every state it visits, add these labels to the data and refit.
- Noise injection (DART, Laskey et al. 2017): perturb the expert while demonstrating, so the data already shows recoveries.
- Inverse reinforcement learning (IRL): find a reward for which the expert’s behaviour is optimal, then plan with it.
- Maximum-entropy IRL (Ziebart et al. 2008): model demonstrations as more likely the higher their return, P(τ) ∝ exp R(τ), and fit the reward by maximum likelihood.
- Adversarial imitation (GAIL, Ho and Ermon 2016): train a discriminator to tell expert from learner state–action pairs and use it as the learner’s reward.
- 1. DAgger asks the expert to label…
- 2. Covariate shift means the test states…
- 3. MaxEnt IRL models a demonstration's probability as…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Behavioural cloning and DAgger on a slippery grid
Exercise 1.
- A 6 × 6 grid, start top left, goal bottom right (+1), six pits (−1), −0.04 per move, γ = 0.95. Deployed with slip 0.2: each side move with probability 0.1.
- The expert is the optimal policy for the slippery grid; success is the exact probability of reaching the goal within 100 steps.
- The learner is a table: the most frequent expert action at each labelled state, and a random action (fixed per state) where it has no label, standing in for a network’s arbitrary output off its training data.
- Three ways to get labels: BC from clean demonstrations recorded without slipping, BC from demonstrations recorded in the slippery grid, and DAgger (clean demonstrations first, then expert labels on the learner’s own episodes in the slippery grid).
Practice.
- Start with behavioural cloning: with plenty of varied, high-quality demonstrations it is simple and strong, and it is the first step of most robot-learning pipelines.
- Collect recoveries: inject noise during demonstrations (DART) or have the expert intervene when the learner drifts (HG-DAgger); a narrow dataset of perfect runs is the main cause of failure.
- Model multimodal actions: experts often have several good actions; mixture, diffusion (Diffusion Policy) or action-chunking (ACT) heads avoid averaging them into a bad one.
- Use IRL or adversarial imitation when the dynamics at deployment differ from the demonstrations, or when an online simulator is available (GAIL, AIRL).
- Tools: the imitation library (BC, DAgger, GAIL, AIRL) on Gymnasium; LeRobot for robot demonstrations.
def fit(states, labels, S, default):
cnt = np.zeros((S, 4)); np.add.at(cnt, (states, labels), 1)
return np.where(cnt.sum(1) > 0, cnt.argmax(1), default)
def dagger(P_demo, P, term, expert, rng, iterations, episodes, default):
data = rollout_states(P_demo, term, expert, rng, episodes)
pi = fit(data, expert[data], len(term), default)
for _ in range(iterations):
data += rollout_states(P, term, pi, rng, episodes) # the learner drives
pi = fit(data, expert[data], len(term), default) # the expert labels
return pi- 1. A common cure for missing recoveries is…
- 2. Diffusion Policy and ACT address…
- 3. A library implementing BC, DAgger and GAIL is…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Compounding errors. Suppose the cloned policy errs with probability ε at states drawn from the expert’s distribution, and an error can take it to states where it is wrong from then on. In the worst case each step’s error probability adds up along the trajectory and the expected cost over a horizon T is of order εT², against εT for the expert’s own distribution (Ross and Bagnell 2010). DAgger trains on the learner’s own state distribution, so its classification error is measured where it matters, and the cost bound becomes linear in T, up to how quickly the expert can recover.
Why more clean data does not help. In a deterministic demonstration environment every demonstration follows the same path. More demonstrations relabel the same states and leave the rest of the state space empty; only data from states off that path, collected by noise or by the learner itself, can fix the policy there.
Inverse RL is ill-posed. Many rewards make the same behaviour optimal: the zero reward makes every policy optimal, and a potential-based shaping term γΦ(s′) − Φ(s) changes every Q value by −Φ(s) and leaves the optimal policy unchanged (Ng, Harada and Russell 1999). MaxEnt IRL resolves the ambiguity by choosing the reward under which the demonstrations are most likely in a model where better trajectories are exponentially more likely. Its log-likelihood gradient is the difference between the expert’s feature counts and those of the current soft-optimal policy, so at the optimum the learner matches the expert’s feature expectations.
Adversarial imitation. GAIL finds the policy whose state–action occupancy matches the expert’s under a Jensen–Shannon divergence, using a discriminator D as a learned reward. AIRL restricts the discriminator’s form so that the recovered reward is disentangled from the dynamics and transfers.
- 1. Behavioural cloning's worst-case cost grows like…
- 2. Potential-based shaping changes the optimal policy…
- 3. At the MaxEnt IRL optimum the learner matches the expert's…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.How do clean-demonstration cloning, noisy-demonstration cloning and DAgger scale with the number of labels, and does a reward recovered by inverse RL transfer when the pits move?
History.
- D. Pomerleau (1989) trained ALVINN, a neural network that steered a vehicle by cloning a human driver, and already reported the need for recovery data.
- A. Ng and S. Russell (2000) posed inverse reinforcement learning; P. Abbeel and A. Ng (2004) introduced apprenticeship learning by feature matching.
- B. Ziebart, A. Maas, J. A. Bagnell and A. Dey (2008) introduced maximum-entropy IRL.
- S. Ross and J. A. Bagnell (2010) analysed compounding errors; S. Ross, G. Gordon and J. A. Bagnell (2011) introduced DAgger.
- J. Ho and S. Ermon (2016) introduced GAIL; J. Fu, K. Luo and S. Levine (2018) introduced AIRL.
Exercise 2, part 1.
- 4, 8, 16 or 32 demonstration episodes for BC (clean or slippery), or DAgger with that many episodes in rounds of 4. Each setting is repeated 8 times with fresh data and fresh random guesses for unlabelled states. The expert’s success is 0.8647.
Seed 0, mean success (mean number of labels in brackets):
| episodes | BC, clean demos | BC, noisy demos | DAgger |
|---|---|---|---|
| 4 | 0.639 (40) | 0.754 (53) | 0.659 (40) |
| 8 | 0.595 (80) | 0.790 (109) | 0.689 (88) |
| 16 | 0.575 (160) | 0.842 (206) | 0.790 (196) |
| 32 | 0.599 (320) | 0.850 (419) | 0.851 (408) |
- Clean cloning did not improve with data: 0.575 to 0.639 from 40 to 320 labels (at most 0.629 on seed 1 and 0.642 on seed 2). Every clean demonstration follows the same 10 states, so the learner guesses in the other 19 open states, and the slippery grid sends it there.
- Noisy demonstrations and DAgger both approached the expert: 0.850 and 0.851 with about 410 labels on seed 0 (0.861 and 0.837 on seed 1; 0.865 and 0.855 on seed 2).
- DAgger started slower here: its first round uses clean demonstrations, and with 4 learner episodes per round it needs a few rounds before the visited states are covered. Its advantage is that it needs no way to perturb the expert, only an expert that can label any state.
- Exercise 1: from 20 episodes, clean BC 0.699 (200 labels), noisy BC 0.865 (252), DAgger with 5 rounds of 4 episodes 0.865 (343).
Exercise 2, part 2: MaxEnt IRL.
- Reward features of the state arrived in: goal, pit, and 1 for every move; the true weights are (1, −1, −0.04). The expert’s discounted feature counts are estimated from 20 slippery demonstrations; 150 gradient steps of size 0.5 on the weights, each solving the soft Bellman equation exactly.
- Recovered weights: goal 22.25, pit −22.05, step −3.14 on seed 0 (15.41, −15.23, −2.50 on seed 1; 18.00, −17.82, −2.71 on seed 2). The signs and the goal–pit symmetry are right; the scale is arbitrary, and the step cost is 0.14 to 0.16 of the goal reward instead of 0.04, because the soft model explains the expert’s directness by a steeper step cost.
- Same pits: the optimal policy for the recovered reward succeeds 0.812 (expert 0.865) on all three seeds; the larger step cost makes it take a shorter, riskier route.
- Moved pits: re-planning with the recovered reward gave 0.756 and 0.758 on two new pit layouts where the re-planned expert reaches 0.768 and 0.766 (0.748 to 0.758 on seeds 1 and 2). The cloned policy, which learned actions, not goals, reached only 0.600 and 0.565.
Imitation learning in practice
- Robot learning: large demonstration datasets with action-chunking transformers and diffusion policies (ACT, Diffusion Policy, the Open X-Embodiment data) are the current default for manipulation.
- Driving: cloning human driving logs is combined with closed-loop training in simulation to fix compounding errors.
- Language models: supervised fine-tuning is behavioural cloning of demonstrations; reward models learned from preferences (topic F7-1) are a form of inverse RL.
- Combining with RL: demonstrations can seed the replay buffer or regularise a reinforcement learner (DQfD, demo-augmented policy gradients).
References
- D. Pomerleau (1989). “ALVINN: an autonomous land vehicle in a neural network.” NeurIPS.
- S. Ross, G. Gordon and J. A. Bagnell (2011). “A reduction of imitation learning and structured prediction to no-regret online learning.” AISTATS.
- B. Ziebart, A. Maas, J. A. Bagnell and A. Dey (2008). “Maximum entropy inverse reinforcement learning.” AAAI.
- A. Ng and S. Russell (2000). “Algorithms for inverse reinforcement learning.” ICML.
- J. Ho and S. Ermon (2016). “Generative adversarial imitation learning.” NeurIPS.