Search

Search papers and lessons

Generative Adversarial Imitation Learning

Jonathan Ho, Stefano Ermon · 2016

GAIL learns a policy straight from expert demonstrations: a discriminator learns to tell expert behaviour from the learner's, and its score acts as a reward-like signal, with no reward function written down.

On this page

  • Colour = topic mix
  • Reinforcement learning
  • Probability
  • Discrete math
  • Calculus
  • Linear algebra
  • Neural network basics
  • Sign in to see your progress

TL;DR

Imitation learning asks a learner to copy an expert from recorded demonstrations alone, with no reward function and no chance to ask the expert anything. The older routes either copy single actions as a supervised problem, which drifts off course, or first recover a reward function and then optimise against it, which is slow. Generative Adversarial Imitation Learning (GAIL) skips the reward step. A discriminator learns to tell the expert's state-action pairs from the learner's, and the learner is trained to make its behaviour indistinguishable from the expert's.

The paper shows that this procedure is the same as matching the expert's occupancy measure under a Jensen-Shannon divergence, and it gives a practical algorithm with neural networks that imitates complex high-dimensional robot-like controllers.

Where you'll see it: in robot and simulated-character control, where demonstrations are cheap and a hand-written reward is hard to get right, and as a reference point for later methods that learn from demonstrations and a discriminator together.

The problem

Behavioural cloning treats demonstrations as a supervised dataset: given a state, predict the expert's action. It is simple, but it fails in a specific way. Once the learner makes a small mistake, it reaches a state the expert rarely visited, has no training data there, and makes a bigger mistake. The errors compound over a long trajectory. This is the covariate-shift problem (see Covariate Shift), and behavioural cloning needs a lot of data to hide it.

Inverse reinforcement learning (IRL) avoids that trap by working at the level of whole trajectories. It finds a cost function under which the expert does better than anything else, then runs reinforcement learning on that cost. The catch is cost. Many IRL algorithms run reinforcement learning inside their own loop, which is expensive, and the cost function they learn is only an intermediate object. The learner's real goal is to act like the expert, and IRL reaches that goal indirectly.

The paper asks for a method with three properties at once: it does not need the expert during training, it scales to large environments with neural-network policies, and it can imitate an arbitrarily complex expert rather than one fitted to a small set of hand-built features.

Key idea

The key idea has two parts.

The first is a change of viewpoint. Instead of asking which cost makes the expert optimal, ask which policy the whole IRL-then-RL pipeline produces. The paper shows that this policy is the one whose occupancy measure is closest to the expert's, measured by a convex penalty. The occupancy measure is a map from state-action pairs to the discounted amount of time a policy spends in each one (see Occupancy Measure). Matching occupancy measures is a direct goal: it says where the learner should spend its time, which is exactly what imitation means.

The second is a choice of penalty. The authors pick the penalty whose optimal value is the Jensen-Shannon divergence between the learner's and the expert's occupancy measures, which is the quantity a generative adversarial network minimises in its own training. That connection suggests the algorithm: fit a discriminator to tell the two apart, and train the policy to fool it.

Picture a forger and an inspector. The inspector sees banknotes from the mint and from the forger and learns to spot the fakes. The forger uses the inspector's verdicts to improve its fakes. In GAIL the expert's trajectories are the mint, the learner is the forger, and the discriminator is the inspector. Nothing in the process requires the reward to be written down, because the discriminator's verdict plays that role.

The method

The discriminator and the learner

Write the learner's policy as πθ\pi_\theta and the discriminator as Dw(s,a)D_w(s,a), a number between 0 and 1. The discriminator is trained to output a high value on learner pairs and a low value on expert pairs. Its objective is the standard GAN objective:

max⁡w  Eπθ[log⁡Dw(s,a)]+EπE[log⁡(1−Dw(s,a))].\max_{w} \; \mathbb{E}_{\pi_\theta}\big[\log D_w(s,a)\big] + \mathbb{E}_{\pi_E}\big[\log(1 - D_w(s,a))\big].

The expectations are over state-action pairs generated by the learner and by the expert. Here πE\pi_E is the expert policy, and only sampled trajectories from it are available. The learner then minimises an expected cost. The cost of a pair is c(s,a)=log⁡Dw(s,a)c(s,a) = \log D_w(s,a), and the learner is pushed to do whatever makes that cost small, using the same policy-gradient machinery as in Policy Gradient.

Causal entropy, the average of −log⁡π(a∣s)-\log \pi(a \mid s) along trajectories, is added as a regulariser with weight λ≥0\lambda \ge 0. It keeps the policy from collapsing onto one action too early. This is the same Entropy idea that appears throughout information theory, applied along a trajectory.

Example
A small numerical picture of the learner's cost

The discriminator outputs DD, and the learner's cost is c=log⁡Dc = \log D. Because log⁡\log of a number below 1 is negative, costs are negative here.

  1. Suppose the discriminator outputs D=0.9D = 0.9 for a pair the learner produced. It looks learner-like to the discriminator, so the cost is log⁡0.9≈−0.105\log 0.9 \approx -0.105.
  2. Suppose it outputs D=0.1D = 0.1 for a pair that looks like the expert's. The cost is log⁡0.1≈−2.303\log 0.1 \approx -2.303.
  3. The learner minimises expected cost, so it is pushed toward the expert-like pair, which has the much lower cost.
  4. Interpretation: the discriminator's verdict acts as a local, learned cost. Actions the expert would take get rewarded, without anyone writing down a reward.

These numbers are illustrative and were chosen for the example; they are not from the paper.

Why the objective is a divergence

The paper shows that the best value of the discriminator's objective, up to a constant, is the Jensen-Shannon divergence between the two occupancy measures. This divergence is zero only when the two measures are equal, and it is symmetric and bounded (its square root is a true distance between distributions). So the learner that minimises it, subject to a small entropy term, ends up with an occupancy measure that matches the expert's. This is the sense in which the method imitates exactly, where earlier apprenticeship methods that restricted the cost to a small family of functions could only get close.

The algorithm

The algorithm alternates two steps, one for each player.

  1. Sample trajectories from the current policy πθi\pi_{\theta_i} by running it in the environment.
  2. Take a gradient step on the discriminator's parameters ww, using the learner's samples as the "fake" class and the expert's trajectories as the "real" class. The paper uses the Adam optimiser (see Adam Optimizer).
  3. Take a policy step with the trust-region rule of TRPO, using the cost log⁡Dwi+1\log D_{w_{i+1}}. TRPO limits how far the policy moves in each step, measured by Kullback–Leibler Divergence between the old and new policies.

The trust-region step matters for the same reason it does in TRPO. The discriminator's signal is noisy, and an unconstrained policy step on a noisy gradient can ruin a good policy. The paper also estimates the gradient of the causal entropy term and includes it in the policy step.

The procedure is a saddle-point search. The learner minimises over π\pi and the discriminator maximises over DD, the same minimax structure used in GAN training. The paper states the target as finding a saddle point of the objective rather than a minimum of one function.

What the discriminator does not need

The discriminator is trained on state-action pairs, not on full trajectories, and it does not need a model of the environment. The method is model-free: it never needs the transition probabilities of the environment, only samples from it. The paper notes that this is also its main weakness, because model-free methods usually need many more environment interactions than model-based ones.

Results

The experiments use nine physics-based control tasks from OpenAI Gym and MuJoCo, from low-dimensional classics (cartpole, acrobot, mountain car, reacher) up to a 3D humanoid. Expert policies are trained with TRPO on the true reward. Learners see small sets of expert trajectories of about 50 state-action pairs each, and each method is given the same amount of environment interaction. Policy and discriminator networks have two hidden layers of 100 units with tanh⁡\tanh nonlinearities.

The paper compares GAIL against behavioural cloning and two earlier apprenticeship methods, feature expectation matching and game-theoretic apprenticeship learning. Performance is scaled so that the expert scores 1 and a random policy scores 0.

On the classic control tasks, GAIL outperformed the baselines across the dataset sizes tested. On the reacher task, behavioural cloning was more sample-efficient than GAIL. A small causal-entropy term helped GAIL on reacher in the four-trajectory setting, with a one-sided rank-sum test reported as significant at p = .05.

On the MuJoCo tasks the gap was large. GAIL reached at least 70 percent of expert performance for almost all dataset sizes and usually beat every baseline. Feature expectation matching and game-theoretic apprenticeship learning did poorly on Ant, scoring below a uniformly random policy. Behavioural cloning did well on several tasks with enough data, but on Humanoid it fell well short of the expert, while GAIL matched expert performance at every dataset size tested.

The exact scores for every task and dataset size are in the paper's appendix tables.

The paper also says plainly where it falls short. Its method needs many environment samples: the number of samples needed to estimate the gradient was comparable to what TRPO needed to train the experts from rewards. The authors suggest initialising the policy by behavioural cloning to save interaction, a step they did not test.

Why it mattered

GAIL showed that the adversarial idea from image generation could be used for control, and that imitation could be done without an explicit reward or an expert in the loop. It gave a clean theory linking imitation to occupancy-measure matching and to a divergence, so later methods could be compared on the same axes.

Its direct descendants include adversarial inverse reinforcement learning and many methods that learn a discriminator alongside a policy for robotics and character animation. The framing also clarified that the learned discriminator is a kind of learned reward, which made later work on reward learning from demonstrations easier to state. The paper's comparison with DAgger, which uses expert queries, set up a practical trade-off that remains current: queries buy sample efficiency in expert data, while GAIL needs no queries but needs many environment samples.

Reading guide

Read the paper in this order, and use the prerequisite lessons as you go.

  1. Introduction and Background. Needs Behavior Cloning for what the baseline does, Inverse Reinforcement Learning for the IRL setting, and Markov Decision Process for the notation of states, actions and transitions.
  2. Section 3, characterising the induced optimal policy. Needs Occupancy Measure for ρπ\rho_\pi, and the duality ideas behind Lagrangian Duality. The key results are Proposition 3.2 and Corollary 3.2.1, which say that unregularised IRL followed by RL matches the expert's occupancy measure.
  3. Section 4, practical occupancy measure matching. Needs Policy Gradient for the policy-gradient estimate, and TRPO for the step rule.
  4. Section 5, the GAIL algorithm. Needs Generative Adversarial Network for the adversarial game, Minimax Game for the saddle point, Jensen–Shannon Divergence for the divergence the discriminator computes, Logistic Regression for the binary classifier, and Adam Optimizer for the discriminator update. Read Algorithm 1 side by side with the text.
  5. Section 6, experiments. Needs Reinforcement Learning for the expert training and Imitation Learning and Structured Prediction as No-Regret Online Learning only as context for the contrast in Section 7.
  6. Section 7, discussion. Needs Covariate Shift for why behavioural cloning fails, and Entropy for the regulariser's meaning.

Check yourself

QuestionWhy does behavioural cloning need more data than GAIL to stay on course over a long trajectory?Show answer

Behavioural cloning learns single-step decisions from expert states. Once the learner makes a small error it reaches states the expert rarely visited, so it has little training data there, and its mistakes compound. GAIL works at the level of whole state-action distributions through the occupancy measure, so it is trained on the states the learner actually visits, which reduces the drift.

QuestionIn GAIL, the discriminator outputs D=0.25D = 0.25 for a state-action pair. Is this pair more expert-like or learner-like, and what is its cost log⁡D\log D?Show answer

The discriminator is trained to output values near 1 on learner pairs and near 0 on expert pairs. A value of 0.25 is closer to 0, so the pair looks expert-like. Its cost is log⁡0.25≈−1.386\log 0.25 \approx -1.386, which is a low cost, so the learner is pushed toward behaviour like this.

QuestionWhat does the Jensen-Shannon divergence measure in GAIL, and why does its being zero matter?Show answer

It measures how different the learner's occupancy measure is from the expert's. It is zero only when the two are identical, so a learner that minimises it, with the entropy term small, has an occupancy measure matching the expert's and therefore imitates the expert's behaviour exactly rather than approximately.

QuestionWhy does GAIL use a trust-region policy step instead of a plain gradient step on the policy?Show answer

The discriminator's signal is a noisy estimate, and a plain gradient step on a noisy gradient can move the policy far enough to lose the behaviour it already learned. The trust-region step bounds the change in the policy, measured by KL divergence, which keeps the update stable when the discriminator is changing.

Sources

Read the full paper

Jonathan Ho, Stefano Ermon, 2016. arXiv:1606.03476