Why This Matters
How do we teach robots or agents to perform complex tasks without writing tedious, reward-shaped reward functions? Traditionally, we rely on Imitation Learning (IL) using expert demonstrations. There are two classical paradigms, both with major drawbacks:
- Behavioral Cloning (BC): Supervised learning mapping states to actions. While simple, it suffers from covariate shift. Once the agent drifts slightly off the expert's path, it doesn't know how to recover.
- Inverse Reinforcement Learning (IRL): Finds a cost function under which the expert is optimal, then runs Reinforcement Learning (RL) on that cost. This is extremely robust but computationally brutal, requiring an expensive RL step in an inner loop.
GAIL solves this dilemma. It matches the robustness of IRL by learning a global policy that handles compounding errors, but bypasses the expensive inner-loop cost optimization by directly matching the expert's occupancy measure.
The Big Idea
The core insight of GAIL is that regularized Inverse Reinforcement Learning is dual to matching occupancy measures.
An occupancy measure $\rho_\pi(s, a)$ uniquely defines a policy. If our agent's occupancy measure exactly matches the expert's ($\rho_\pi = \rho_{\pi_E}$), the agent will behave identically to the expert.
Instead of explicitly learning a cost function $c(s,a)$ and running RL, GAIL sets up a minimax game like a GAN:
Here, the Discriminator ($D$) tries to distinguish between state-action pairs from the expert and the learner. The Policy ($\pi$) acts as the Generator, trying to confuse the discriminator by acting like the expert.
Interactive Widget 1: Occupancy Measure Matching
Adjust the slider to change the agent's policy distribution (occupancy measure) and observe how the Jensen-Shannon Divergence ($D_{JS}$) changes as it aligns with the expert's distribution.
How It Works
GAIL alternates between two main steps in an adversarial loop:
- Discriminator Update: The discriminator $D_w(s,a)$ is trained via gradient ascent to maximize the probability of assigning the label 0 to expert trajectories and 1 to learner trajectories.
- Policy Update: The policy $\pi_\theta$ is updated using Trust Region Policy Optimization (TRPO) to minimize the cost $c(s,a) = \log D(s,a)$. This acts as a surrogate reward forcing the policy to generate trajectories that look identical to the expert's.
Interactive Widget 2: GAIL Architecture
Hover over the different components of the GAIL loop to see their mathematical formulation and role in the system.
Hover over the diagram
Move your cursor over any component of the GAIL loop to inspect its role and the mathematics behind it.
Interactive Widget 3: Compounding Error Demo (BC vs GAIL)
Simulate an agent trying to follow a straight path. Introduce a "wind disturbance" and see how Behavioral Cloning (BC) fails to recover due to covariate shift, while GAIL steers back.
Results & Benchmarks
GAIL was evaluated on 9 physics-based control tasks (using MuJoCo and OpenAI Gym). It consistently outperformed Behavioral Cloning, Feature Expectation Matching (FEM), and Game-Theoretic Apprenticeship Learning (GTAL), especially when expert data was highly constrained.
Performance across MuJoCo Tasks
Limitations & Open Questions
- Environment Interaction Sample Complexity: While GAIL is highly sample-efficient regarding expert demonstrations, it requires a massive number of active interactions with the environment during training to estimate policy gradients.
- Lack of Model-Free Efficiency: Because it is model-free, GAIL trains slower than model-based approaches that can simulate trajectories using a learned transition dynamics model.
- Reward Bias: The learned discriminator acts as a surrogate reward, but it is often highly non-stationary, making training stability a challenge (a classic issue inherited from GAN training).
Glossary
Occupancy Measure
The discounted distribution of state-action pairs encountered under a policy. It completely and uniquely characterizes a policy's behavior in a given Markov Decision Process (MDP).
Covariate Shift
A change in the distribution of input variables (states) between training and deployment. In Behavioral Cloning, small execution mistakes compound, pushing the agent into states it has never seen in the training data, leading to catastrophic failure.
Jensen-Shannon Divergence
A symmetric and bounded metric of similarity between two probability distributions. Unlike KL-divergence, JS-divergence is always finite and well-behaved even when distributions do not overlap.
Citation
@inproceedings{ho2016generative,
title={Generative adversarial imitation learning},
author={Ho, Jonathan and Ermon, Stefano},
booktitle={Advances in Neural Information Processing Systems},
pages={4565--4573},
year={2016}
}