Skip to the content.

Week 03 — Imitation Learning

← Control and MDPs · Week 3 of 11 · Next: Reinforcement Learning I →

Outcomes

Prerequisites: notation

Notation for imitation learning (and intelligent/learning systems in general):

Symbol Meaning
$a_t$ Action at time $t$
$o_t$ Observation at time $t$
$s_t$ State at time $t$
$\tau$ Trajectory: $\tau = (s_1, a_1, s_2, a_2, \ldots, s_T)$
$r(s, a)$ Reward

Example: for a self-driving car, $o_t$ is the camera image, $s_t$ is the car’s pose and velocity, $a_t$ is the steering/throttle command, and $\tau$ is one full drive.

What is imitation learning?

Given a set of trajectories collected by an expert, called demonstrations:

\[\mathcal{D} = \{ (s_1, a_1, \ldots, s_T) \}\]

the goal is to learn a policy $\pi$ that imitates the expert’s behaviour.

Behaviour cloning

The simplest approach — treat imitation as supervised learning. Given $\mathcal{D} = \{(s_1, a_1, \ldots, s_T)\}$, for a deterministic policy, regress onto the expert’s actions:

\[\min_\theta \; \frac{1}{|\mathcal{D}|} \sum_{(s, a) \in \mathcal{D}} \lVert a - \hat{a} \rVert^2, \qquad \hat{a} = \pi_\theta(s)\]

then deploy $\pi_\theta$ on the robot.

Does it work?

Sometimes, yes — see End to End Learning for Self-Driving Cars (Bojarski et al., 2016), which trained a CNN to map raw camera pixels directly to steering commands.

Trick: “data augmentation”

Bojarski et al. add fake data that illustrates corrections, using side-facing cameras: the left/right camera views look like the car has drifted off-centre, so they are relabelled with the corrective steering command.

Data augmentation with side cameras

The upper bound of behaviour cloning

Compounding error: the policy drifts away from the expert's states

The policy makes a small mistake ($\epsilon$ per step), lands in a state the expert never demonstrated, and makes a bigger mistake there. Over a time horizon $T$, this distribution shift causes the error to compound quadratically:

\[\mathbb{E}[\text{cost}] \in O(\epsilon T^2)\]

See A Reduction of Imitation Learning and Structured Prediction to No-Regret Online Learning (Ross et al., 2011).

Addressing compounding error: DAgger

How can we make $p_{\text{expert}}(s) = p_{\pi}(s)$ — i.e. states visited by the expert $=$ states visited by the policy?

Idea: instead of being clever about the policy, be clever about the data — make the dataset cover the states the policy actually visits.

The DAgger loop

  1. Roll out $\pi_\theta$ on the robot.
  2. Query the expert: label the visited states $s^{\prime}$ with expert actions $a^*$.
  3. Aggregate the corrections with the existing data: $\mathcal{D} \leftarrow \mathcal{D} \cup \{(s^{\prime}, a^*)\}$.
  4. Update the policy: $\theta \leftarrow \arg\min_\theta L(\pi_\theta, \mathcal{D})$, and repeat.

The good

The bad

Example: Waymo self-driving safety drivers (teleoperators) take over when needed, and those interventions become labelled recovery data.

Why might we still fail to mimic the expert?

Why the MSE policy fails: mode averaging

Demonstrations are multimodal: faced with a tree, half the experts swerve left and half swerve right, so the true action distribution $p(a \mid s)$ has several modes. Minimizing MSE is maximum likelihood under a single Gaussian, so the optimal prediction is the conditional mean:

\[\pi_\theta(s) = \mathbb{E}[a \mid s]\]

and the mean of “left” and “right” is “straight into the tree” — an action no expert ever took.

Mode averaging under an MSE loss

Concretely, if the expert’s actions follow a mixture of Gaussians,

\[p(a \mid s) = \sum_{i=1}^{k} w_i(s)\, \mathcal{N}\big(a;\ \mu_i(s), \Sigma_i(s)\big),\]

the MSE-optimal policy outputs $\sum_i w_i \mu_i$ — which can land in a near-zero-probability valley between the modes.

Expressive policies

Fix: replace the implicit unimodal Gaussian with a distribution class that can represent multiple modes.

Scaling control to “any” task

How do we go from one policy per task to one policy for any task?

  1. Single task: $\pi_\theta(a \mid s)$ — one policy per task, nothing shared.
  2. Task-conditioned: $\pi_\theta(a \mid s, z_{\text{task}})$ — condition on a task ID (one-hot, or a language embedding). One network, data shared across tasks — but only for a predefined list of tasks.
  3. Goal-conditioned: $\pi_\theta(a \mid s, g)$ — condition on a goal state $g$ (e.g. an image of the desired outcome). “Any task” becomes “reach any goal state”. Bonus: hindsight relabelling — whatever state a trajectory actually ended in is a valid goal for that trajectory, so every trajectory supervises goal-reaching for free.

Caveat: goal-conditioning only covers tasks expressible as reaching a state — “wave hello” or “keep the cup upright while moving” don’t map cleanly to a single goal state.

Dataset and architecture decisions

Failure modes

Paper discussion

Contrast the diagnosis in Causal Confusion in Imitation Learning with the empirical case for pretrained visual representations in Pari et al..

Build milestone

Collect or synthesize demonstrations, train behavior cloning, then introduce initial-state noise. Add either DAgger or recovery data and compare closed-loop success—not just validation loss—over three seeds.

Plot performance against perturbation magnitude and dataset size. Include the expert, a random policy, and behavior cloning before claiming the interactive method helps.


← Control and MDPs · Next: Reinforcement Learning I →