Unit 2 of 11 · about 4 hours · derive, implement
Covariate shift, compounding imitation error and DAgger
A 1 percent mistake rate sounds safe until the horizon multiplies it. This unit makes the horizon dependence quantitative and shows what only an interactive expert can fix.
You'll be able to
- Derive the quadratic compounding bound for offline imitation and the linear bound with interactive queries.
- Run the DAgger loop (roll out learner, label visited states with the expert, aggregate, retrain) and state exactly what the extra queries change.
- Tell covariate shift apart from causal confusion and from fixed-dataset offline limits.
Covers
Read
In this order, only the parts listed
0 of 4 done
- Lecture 2: how bad covariate shift can be, then DAggerBerkeley CS 185/285 Deep Reinforcement Learning (Spring 2026) - Imitation and Offline RL
Part 4, the mistake analysis with the quadratic horizon dependence (PDF pp. 23-32); Part 5, DAgger dataset aggregation and the common-variant question (PDF pp. 33-38)
- DAgger: the reduction and the aggregation loopDAgger
Sections 1-3: the supervised T-squared mistake argument, forward training with Theorem 2.2, SMILe mixing, and the Section 3 dataset-aggregation loop that trains a stationary deterministic policy
- Lecture 02: compounding errors and interventionsStanford CS224R Spring 2026 - Imitation and Offline RL
PDF pp. 23-26: the covariate-shift diagram, the corrective-data loop (dataset aggregation), and human-gated DAgger
Use pp. 7-22 only as background from the previous unit. The examinable material here is pp. 23-26.
- Why cloning errors compound, and the DAgger fixHands-on Modern RL - Offline RL and Imitation Concepts
Sections 2 and 3: the error-rate table (1 percent error at horizons 10, 50, 100, 1000) and the mixing schedule with expert relabeling of policy-visited states (page read 2026-10-14)
Focus on
- The arithmetic first: at 1 percent error per step, clean-run probability is but and . Recompute all three.
- The bound behind it: offline cloning pays up to , because one off-distribution step can cost the rest of the horizon; labeling the learner's own visited states cuts it to .
- DAgger aggregates policy-visited states with expert labels and retrains on the union. The load-bearing ingredient is the expert label on the learner's distribution, not the extra states alone.
- DAgger needs an interactive expert, so it does not apply to a fixed offline dataset. Causal confusion is a separate failure: Berkeley Lecture 3 asks whether history or DAgger mitigates it, citing de Haan et al., who find that more input information can make cloning worse and resolve it with targeted interventions.
Common mistakes · 3
- Believing more clean demonstrations remove the quadratic term. They shrink the per-step rate but the horizon dependence stays; recoveries in the data (the Lecture 2 paradox) can help more than extra clean runs.
- Running the common intervention variant (the human takes over at some step and only the takeover data is stored) and quoting the DAgger guarantee. Labels then cover the takeover states and what the human drives afterwards, not every state the learner visits; Lecture 2 poses exactly this question.
- Treating DAgger as an offline algorithm. It needs an interactive expert during training; with only a fixed dataset you are back in the offline regime of the next units.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.At 1 percent per-step error, what fraction of length-100 runs stays clean, and why does length-1000 collapse?Answer
0.37 for length 100; 0.00004 for length 1000. Clean probability decays exponentially as 0.99^T, so long horizons need a far smaller per-step rate.
2.State the offline cloning bound and the DAgger bound, and the intuition for the gap.Answer
Offline: ; interactive: . Offline, one mistake can leave the training distribution and cost more mistakes, and there are chances to leave; on-policy labels remove the distribution mismatch.
3.What exactly is added to the dataset at each DAgger iteration?Answer
States visited by the current learner policy, each labeled with the expert's action, appended to all previous data. The next policy mimics the expert on the whole aggregate.
4.Demonstrations show braking whenever the dashboard brake indicator is lit, because braking turns it on. Why can a cloned policy brake at the wrong time, and why is this not covariate shift?Answer
The indicator is an effect of braking that predicts the expert action almost perfectly, so the policy can key on it instead of the road: causal confusion. More data from the same distribution keeps cue and action together; de Haan et al. resolve it with targeted interventions, environment interaction or expert queries, and compare against DAgger, so do not assume aggregation alone fixes it.
Practice
- Stanford CS224R Homework 1, Problem 3: DAgger on Flappy Bird
Problem 3: implement
DeterministicExpert.act, rollout, and relabel indagger.py, retrain with the Problem 1 regression objective, and submitdagger_hard.txtagainstbc_reg_hard.txtRuns on CPU or Colab. Compare hard-mode success before and after aggregation, and state what the expert queries added. Follow the Stanford honor code; generative-model code is banned for this homework.
You're done when
Your hand probabilities match Python, and your DAgger run beats your Problem 1 cloning run on hard mode with the query difference written down.
Only when you can do this without notes.
Leads to
Notes
Resources · 4 for this unit, 10 more in the section
- Stanford CS224R Spring 2026 - Imitation and Offline RLStanford University · primary
Study Lecture 02 (imitation: behavior cloning, covariate shift, DAgger) and Lecture 07 (offline RL). Homework 1 (behavior cloning, flow matching and DAgger on a small Flappy Bird environment) runs on CPU; Homework 3 (AWAC, IQL and a stitching study) runs on cloud GPUs, so read it for the losses. Follow the Stanford honor code for course materials.
- Berkeley CS 185/285 Deep Reinforcement Learning (Spring 2026) - Imitation and Offline RLUC Berkeley · required
Slides are public at https://rail.eecs.berkeley.edu/deeprlcourse/static/slides/lec-N.pdf; current videos are not, and the public Fall 2023 playlist numbers lectures differently. Study Lectures 2 and 3 (behavioral cloning) and Lectures 17 and 18 (offline RL). Homework 1 (MSE and flow-matching action-chunk policies) runs on a laptop CPU; Homework 5 (SAC+BC, IQL and FQL on OGBench) needs a GPU, so debug on the smallest task and treat full 1M-step sweeps as optional.
- DAggerRoss, Gordon and Bagnell · support
Read the no-regret reduction and interactive data-aggregation loop. Demonstrate compounding error in a controlled imitation task, then show exactly what additional expert queries change.
- Hands-on Modern RL - Offline RL and Imitation ConceptsWalking Labs · support
Use the offline data and distribution-shift page and the imitation chapter as pre-reading for BCQ, CQL, IQL, behavior cloning, DAgger and GAIL. They have no runnable offline or imitation scripts and no off-policy evaluation. Pin commit 9231bab of walkinglabs/hands-on-modern-rl; its
code/chapterNNfolders do not follow the site chapter numbers.
Also in this section
- Offline Reinforcement Learning: Tutorial, Review and PerspectivesLevine et al. · required
Study the problem definition, distribution-shift failure, policy constraints, uncertainty and model-based/model-free taxonomy. Use it to state which offline assumptions each implementation relies on.
- Implicit Q-LearningKostrikov et al. · required
Derive the expectile value loss, Q target and advantage-weighted policy update. Implement fixed-batch loss tests and compare IQL with behavior cloning across dataset quality and coverage.
- Conservative Q-Learning for Offline Reinforcement LearningKumar et al. (NeurIPS 2020) · support
Read the conservative regularizer and the lower-bound argument. Implement the regularizer on a fixed batch and show how it lowers Q-values on actions the dataset does not contain.
- Generative Adversarial Imitation LearningHo and Ermon (NeurIPS 2016) · support
Read the occupancy-measure view of imitation and the discriminator-as-reward construction. State what GAIL needs that behavior cloning does not (environment interaction) and what it recovers instead of a reward.
- Cal-QL: Calibrated Offline RL Pre-Training for Efficient Online Fine-TuningNakamoto et al. (NeurIPS 2023) · support
Read why conservative values cause an initial dip when online fine-tuning starts and how calibration bounds the values. Measure the first online episodes after offline training with and without the fix.
- Doubly Robust Off-policy Value Evaluation for Reinforcement LearningJiang and Li (ICML 2016) · support
Read the per-decision importance-sampling estimator, the doubly robust form and its variance analysis. Implement ordinary, weighted and doubly robust estimates on logged trajectories from a small MDP whose true value you can compute.
- Batch Policy Learning under Constraints (Fitted Q Evaluation)Le, Voloshin and Yue (ICML 2019) · support
Read the Fitted Q Evaluation algorithm and its role inside the constrained learner. Implement FQE on your logged data and compare it with the importance-sampling estimates against the true value.
- Benchmarks for Deep Off-Policy EvaluationFu et al. (ICLR 2021) · support
Read the evaluation protocol and the metrics for estimator quality and offline model selection (rank correlation, regret of the selected policy). Use them to judge your estimators instead of one point error.
- Minari Offline DatasetsFarama Foundation · support
Use Minari as the dataset source for offline experiments: it serves Gymnasium-native datasets that download without login (start with a small MuJoCo set such as
mujoco/invertedpendulum/expert-v0). Record the dataset id and version with every result. - Reinforcement Learning Control Laboratory - Offline StretchRoadmap-Final · support
Add the project offline-data stretch only after online control passes. Calibrate importance or fitted-value estimates against simulator truth and expose one support-mismatch failure before hiding online access.