TL;DR
Behavior cloning learns a policy by copying demonstrations. You record an expert doing the task, pairing each observation the expert saw with the action it took. You then train a model with ordinary supervised learning to predict that action from that observation. No reward function is needed.
It is fast and simple, but the learned policy drifts into situations the expert never demonstrated, and small mistakes compound there.
Where you'll see it: teaching robot arms to grasp and pour from human teleoperation data, and as the initial stage of training large robot-control models before reinforcement learning or other fine-tuning.
Intuition
Learning to drive by watching
Think of a new driver sitting beside an instructor. Each time the instructor turns the wheel, the student notes what the road looked like and which way the wheel went. After enough hours, the student has a rough map from "what I see" to "what to do". That map is the policy. Behavior cloning builds the same map from recorded data instead of from a human teacher in the seat.
The appeal is that no one has to write a reward function. Designing a reward that makes a robot pour water without spilling is hard. Recording a person doing it is easy.
Where it breaks
The student has only ever seen the instructor's good driving. If the car drifts toward the kerb, the student has never seen how to recover, so it turns the wrong way, drifts further, and ends up in a state with no training examples at all. Each small error takes the car somewhere the training data never covered, and the next error is worse. Errors compound.
This is the central tension of the topic: the training data comes from the expert's distribution of states, but the learner's own actions decide which states it visits. The mismatch between training inputs and deployment inputs is the source of most failures.
flowchart LR A[Expert demonstrations] --> B[Pairs of observation and action] B --> C[Supervised training] C --> D[Learned policy] D --> E[Visits states the expert never showed] E --> F[Errors compound] F --> E
The math
Setup
Let be an observation (or state) and an action. An expert policy produces a distribution over actions. The demonstration dataset is
where is the number of recorded pairs. A learned policy is a model with parameters , for example a feedforward neural network that outputs a distribution over actions.
The objective
Behavior cloning is maximum-likelihood fitting of to the demonstrations:
Equivalently, minimise the negative log-likelihood. For discrete actions with a Softmax output this is the cross-entropy loss. For continuous actions with a Gaussian output of fixed variance, it reduces to the squared error between predicted and demonstrated actions.
Derivation for the Gaussian case. Let . Then
With fixed, maximising the sum is the same as minimising . That is ordinary least squares on the demonstrations, with a neural network as the function .
What the learner is trying to match
If the expert is deterministic, , the objective pushes toward on states that appear in . Nothing in the objective says what to do on states not in . The network's behaviour there is set by generalisation, which is not guaranteed to be sensible.
Why the error grows with the horizon
Suppose the learned policy makes a mistake with probability at each step, and that a mistake puts the agent in a state where it may make further errors. A simple analysis in Ross et al. (2011) shows that the expected cost of plain behavior cloning can grow with the square of the horizon , roughly like , rather than linearly like . The intuition is that an error early in a trajectory changes every state after it. Ross et al. show this quadratic growth is tight: there are problems where it really occurs. They propose a fix described below.
Worked examples
A car has a single steering observation , the lateral offset from the lane centre in metres. The expert steers (a proportional correction). The dataset has three pairs: , , . We fit a linear policy by least squares.
- Minimise .
- Differentiate with respect to : .
- Expand: , so .
- Solve: .
- The fitted policy is , exactly the expert.
Interpretation: with noiseless demonstrations from a linear expert, behavior cloning recovers the expert on the states that were demonstrated. The next example shows what happens off that set.
Use the same expert and fitted policy , but now the learner starts at offset , which the demonstrations never covered. Assume the car moves by per step, where the is an unmodelled drift to the right.
- Step 0: , action , next offset .
- Step 1: , .
- Step 2: , .
- The offset shrinks each step and settles near (where balances), because the policy's correction is stronger than the drift.
Change the policy to a slightly worse fit, . Repeat from :
- Step 0: , .
- Step 1: , .
- Step 2: , .
Interpretation: the weaker correction converges to a fixed point near rather than to zero, because it never balances the drift. This is a small but real version of compounding error: a policy that is nearly right on the demonstrations can settle into a bad state off them, and the demonstrations give no signal about that.
A robot arm observes a camera image and its joint angles, and outputs a 7-dimensional joint-velocity command. A human teleoperates it through 200 successful grasps, giving roughly pairs, where is the number of control steps per grasp. A policy network trained with a squared loss will learn the average demonstrated motion for each visual situation.
Where the demonstrations contain several valid ways to grasp (approach from above, or from the side), the average of those motions is a motion that grasps nothing. This is a failure of averaging, not of the optimiser. Models that represent several modes, such as mixture density networks or diffusion-based policies, are used to avoid it.
Interpretation: behavior cloning works well when the demonstrations are consistent and the task is close to the demonstrated distribution. Multi-modal data and new situations are where the simple objective breaks down.
Tradeoffs and failure modes
| Situation | What goes wrong | Better choice |
|---|---|---|
| Plenty of expert data, task close to demonstrations | Works well and is cheap to train | Behavior cloning |
| Long horizon, errors compound | Drift into unseen states, growing error | Interactive imitation (DAgger), or fine-tune with reinforcement learning |
| Demonstrations contain several valid strategies | Averaging yields an invalid action | Mixture density output, or a diffusion or flow policy |
| No way to query the expert during training | Cannot collect recovery data | Add noise to the expert during collection so the data covers recoveries |
| Reward is easy to write down and the policy must beat the expert | Cloning caps performance at roughly expert level | Start from cloning, then [[reinforcement-learning |
| Expert uses information the robot cannot observe | The policy learns an average over hidden causes | Include the information in the observation, or model latent variables |
Two practical points. First, the choice of loss matters more than it looks: a squared loss on a multi-modal action target gives the averaging failure above, and a cross-entropy loss over discretised actions does not. Second, behavior cloning is often used as a warm start. A policy trained by cloning begins near the expert, which makes later reinforcement learning far less likely to get stuck.
History
Dean Pomerleau's ALVINN system (late 1980s) is one of the first well-known uses of learning from human driving. A small neural network mapped camera images to steering commands, trained on recorded human driving, and steered a test vehicle. It is often cited as an early demonstration of behavior cloning for driving.
Stéphane Ross, Geoffrey Gordon and Drew Bagnell (2011) analysed why cloning errors compound and proposed DAgger, which repeatedly runs the learned policy, asks the expert to label the states it reaches, and adds those labels to the training set. The paper reduces imitation to no-regret online learning and shows DAgger avoids the quadratic growth in the horizon.
The Diffusion Policy paper (Chi et al., 2023) uses a diffusion model over action sequences, which can represent the multiple modes of demonstrations that squared-loss cloning averages away.
Check yourself
QuestionIn one sentence, what is the supervised learning problem that behavior cloning creates from a set of demonstrations?Show answer
Learn a function from observations to actions , using the demonstrated pairs as labelled examples, by maximising the likelihood of the demonstrated actions. Behavior cloning is supervised learning with the expert's actions as labels.
QuestionA deterministic expert uses . A learner fits to demonstrations at and . What is the least-squares estimate of ?Show answer
Minimise . Differentiating gives , so , giving and . The learner recovers the expert exactly, because the expert is linear and the data is noiseless.
QuestionWhy does a behavior-cloned policy with a small per-step error rate still fail badly over a long trajectory?Show answer
Each error moves the agent to a state the demonstrations did not cover, so the next action is less reliable, and the next error makes things worse. Errors compound along the trajectory rather than staying independent, so the total cost grows faster than linearly in the horizon.
QuestionA demonstration set contains two valid ways to reach a cup: from the left and from the right. A learner with a squared loss outputs an action halfway between them. Explain why this fails and name one model class that avoids it.Show answer
The average of the two valid actions points at neither side. The squared loss rewards predicting the mean of the demonstrated actions, and that mean is not a valid motion. A mixture density network or a diffusion policy can represent both modes and sample one of them, so the learned action is a real strategy.
QuestionApplied: you have 500 teleoperated grasps and a policy that works in the lab but fails when the cup is moved to a new position. Which two changes would you consider first, and why?Show answer
First, collect demonstrations that cover the new positions, because the failure is a shift in the states the policy sees and the policy has no data there. Second, consider an interactive method such as DAgger, which asks the expert to label the states the current policy actually reaches. Both target the cause, which is that the policy has never been trained on the states where it now fails. Changing the network size alone would not address the coverage gap.
Sources
- Imitation learning (Wikipedia)
- Ross, S., Gordon, G., Bagnell, D. (2011). A Reduction of Imitation Learning and Structured Prediction to No-Regret Online Learning.
- Chi, C., et al. (2023). Diffusion Policy: Visuomotor Policy Learning via Action Diffusion.