Adversarial Imitation: GAIL & Distribution Matching
Imitation as matching occupancy measures, with a discriminator as the reward.
Behavior cloning matches the expert's actions one state at a time, on the expert's states. Adversarial imitation matches something larger: the whole distribution of states and actions the expert visits, measured on the learner's own behavior. This lesson derives that view from maximum-causal-entropy inverse RL (Ho and Ermon's theorem), shows why a discriminator's output is a reward, compares the divergences behind GAIL, AIRL and their relatives, and follows the attempts to make the idea off-policy and non-adversarial.
What you’ll learn
- Show that RL on the cost found by -regularized maximum-causal-entropy IRL solves , and recover exact occupancy matching, feature matching and GAIL as special cases.
- Derive GAIL's discriminator objective as a Jensen–Shannon divergence, and show that the optimal discriminator's log-output is the gradient of that divergence with respect to the learner's occupancy measure.
- Explain the divergence view of imitation (cloning as forward KL on the expert's states, GAIL as Jensen–Shannon, AIRL as reverse KL) and AIRL's disentangled reward.
- Derive ValueDICE's off-policy objective and IQ-Learn's single-Q objective, and explain what offline adversarial imitation can and cannot guarantee.
From inverse RL to occupancy matching
Maximum-causal-entropy inverse RL with a convex cost regularizer looks for a cost under which the expert beats every high-entropy policy, and RL then optimizes that cost:
Write everything over occupancy measures with the two facts above. IRL computes for
is strictly convex in and concave in , and is convex and compact for finite and , so minimax duality lets the and the be exchanged. Taking the max over first produces a conjugate:
Now let be the IRL cost, a maximizer of . Because the two optimal values coincide, is a saddle point, so minimizes , which is exactly the RL problem for . Strict convexity makes that minimizer unique, so RL on the IRL cost returns , the solution of the occupancy problem. (This is Ho and Ermon's argument, given optimizers of both problems.)
| Regularizer | Penalty | Resulting method |
|---|---|---|
| constant | if , else | Exact occupancy matching (Ho & Ermon, Cor. 3.2.1) |
| indicator of | Feature-expectation matching (Abbeel & Ng, 2004) | |
| indicator of | MWAL and LPAL (Syed & Schapire; Syed, Bowling & Schapire) | |
| below | GAIL |
With a constant regularizer and the expert's exact occupancy measure, what does RL after IRL return?
- The policy of maximum causal entropy
- Some policy that is optimal for a cost the expert also minimizes, not necessarily the expert's
- The expert's own policy
- A policy whose occupancy measure is only approximately the expert's
Show the answer
C. The expert's own policy
A constant has at and elsewhere, so the solution must have exactly the expert's occupancy measure, and the one-to-one correspondence between policies and occupancy measures leaves only . With finitely many demonstrations, though, most expert occupancies are estimated as zero, and exact matching would forbid every unseen state–action pair: that is why practical methods regularize.
GAIL: a discriminator as the reward
Ho and Ermon's regularizer for GAIL lets the cost be any negative function, penalized more when it assigns the expert's pairs costs close to zero: with for and unless everywhere. Its conjugate turns out to be a classification loss.
Expand the conjugate; the terms and cancel:
Substitute . The result is the negative log-loss of the best discriminator , trained to output 1 on the learner's pairs and 0 on the expert's:
The maximization separates over pairs, and each term is maximized at
Plug back in and normalize, and , with . Up to the factor , the value is Ho and Ermon's Jensen–Shannon divergence (twice the usual one), shifted by a constant:
Use the normalized measures. When the learner's occupancy measure equals the expert's, what is the optimal value of ?
Show the answer
-1.39
With the best discriminator cannot tell the two apart, everywhere, and the value is , the minimum, where . At the other extreme, with disjoint supports, is 1 on the learner's pairs and 0 on the expert's, the value is 0 and , its maximum.
Let . By Danskin's theorem its derivative is the derivative of the objective at the maximizer, holding fixed. A direct check:
A small policy change changes the occupancy measure by , and the objective to first order by . That is exactly the change in the expected discounted cost with the cost held fixed. So a policy-gradient step on the cost is a gradient step on the divergence: the discriminator is the divergence's gradient, and RL follows it.
GAIL(expert pairs E, policy πθ, discriminator Dw : S×A → (0, 1), entropy weight λ)
repeat:
sample trajectories τ with πθ
# discriminator: ascend the log-likelihood of telling learner (1) from expert (0)
w ← w + η ∇w [ mean over τ of log Dw(s,a) + mean over E of log(1 − Dw(s,a)) ]
# policy: a trust-region step (TRPO in the paper) that lowers the cost
# E_τ[ Σt γ^t log Dw(st, at) ] − λ H(πθ)
θ ← PolicyStep(θ, cost = log Dw)Ho and Ermon's algorithm. Many implementations flip the convention so that means "expert" and use the reward or . These choices give rewards of different signs, which matters when episodes can end early: a reward that is always positive rewards surviving, one that is always negative rewards ending the episode, a bias that Kostrikov et al. (2019) analyzed in their discriminator-actor-critic method.
Which divergence? AIRL and the f-divergence view
Jensen–Shannon is one choice among many. Every -divergence , with convex and , has the variational form , so it can be estimated by a discriminator-like critic and minimized by RL in the same way. Ghasemipour, Zemel and Gu (2019) wrote the common imitation methods in one table.
| Method | Divergence minimized |
|---|---|
| Behavior cloning | : forward KL between action distributions, on the expert's states |
| DAgger, round | The same, averaged over the states of all rounds so far |
| GAIL | |
| AIRL | : reverse KL between occupancy measures |
| FAIRL | : forward KL between occupancy measures |
| -MAX | for a chosen |
AIRL (Fu, Luo & Levine, 2018) gives its discriminator a special form, with now the probability that a pair is the expert's, and rewards the policy with the log-odds:
The term is an entropy bonus, so the policy step is entropy-regularized RL with reward . A rich enough discriminator, trained to tell the expert's pairs from the learner's, reaches the Bayes-optimal classifier, whose log-odds are the log density ratio:
As with GAIL, holding the reward fixed and taking a policy-gradient step follows the gradient of the divergence: , and the drops out because .
The direction matters. Reverse KL, , is infinite if the learner puts mass where the expert has none, so it is mode-seeking: a learner that cannot represent all of the expert's behaviors reproduces some of them faithfully. Forward KL, used by cloning and FAIRL, is infinite if the learner misses any of the expert's mass, so it is mode-covering: the same learner spreads itself over all the behaviors, including the gaps between them. Jensen–Shannon sits in between, and stays finite in both cases.
Proof idea. At the optimum equals the expert's soft advantage, which for deterministic dynamics is . Equating with it for every transition, decomposability separates the terms in from those in and gives both identities. Which rewards demonstrations can identify in general is the subject of Which Rewards Explain Behavior?
Off-policy and non-adversarial imitation
GAIL's two loops both consume interaction: the discriminator compares against fresh on-policy samples, and the policy step is on-policy RL. Training the discriminator on a replay buffer instead changes the divergence being minimized, to one between the expert and the buffer. Two ideas remove the on-policy expectation altogether.
Start from the Donsker–Varadhan form of the reverse KL, whose minimizer is the log density ratio , up to a constant:
The second term needs samples from the learner. Change variables to , where is the Bellman operator with zero reward. By the flow constraints of , the on-policy expectation telescopes to the start:
What remains needs only expert transitions, start states and the learner's own action choices, and the policy is trained on the same objective, with no separate reward or RL step. (In practice a single sample replaces the expectation inside the exponent.)
In principle ValueDICE needs no interaction at all. The published experiments still mixed a little replay-buffer data into both terms, which keeps the expert as the optimum, and treated every state of a demonstration as a start state. Two later readings temper the picture. Li, Xu, Yu and Luo (2022) argued that in the purely offline setting ValueDICE effectively reduces to behavior cloning, and that properly regularized cloning matches it. Swamy et al. (2021) place it with cloning among the off-policy Q-value moment matchers, whose worst case is (Compounding Errors & Interactive Imitation).
The start-state term can be rewritten by the same telescoping identity as an expectation over the transitions of any policy, so IQ-Learn can be trained on expert data alone, and Garg et al. report strong results both offline and online. Offline, though, any of these methods still learns only from the states in the demonstrations, so the lower bounds for imitation without interaction apply to them just as to cloning.
Key takeaways
- -regularized maximum-causal-entropy IRL followed by RL solves : inverse RL is implicitly occupancy-measure matching, and picks the distance (constant: exact matching; linear cost classes: feature matching or MWAL; : GAIL).
- GAIL's discriminator objective equals a Jensen–Shannon divergence between occupancy measures up to constants, and is that divergence's derivative with respect to the learner's occupancy measure, so RL on the cost follows its gradient.
- Imitation methods differ in what they match and in which direction: cloning uses forward KL between action distributions on the expert's states, GAIL Jensen–Shannon and AIRL reverse KL between occupancy measures. AIRL's shaped discriminator recovers a state-only reward up to a constant under deterministic dynamics.
- ValueDICE (Donsker–Varadhan plus a Bellman change of variables) and IQ-Learn (an inverse soft Bellman operator and one concave objective in ) avoid on-policy samples or adversarial reward learning; trained offline, they still learn only from the expert's states and face the lower bounds of imitation without interaction.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
In , what is the role of the cost regularizer ?
- It smooths the reward so that the RL step converges faster
- Its conjugate is the penalty on the gap between the learner's and the expert's occupancy measures, so choosing chooses the distance that imitation minimizes
- It plays no role at the optimum, which is always the expert
- It fixes the overall scale of the recovered reward and nothing else
Show the answer
B. Its conjugate is the penalty on the gap between the learner's and the expert's occupancy measures, so choosing chooses the distance that imitation minimizes
A constant gives exact matching, indicator functions of linear cost classes give feature matching or MWAL, and gives a Jensen–Shannon divergence. The regularizer is not a nuisance: it decides what "close to the expert" means, which matters as soon as the data are finite.
In GAIL, what does the optimal discriminator output when the learner's occupancy measure equals the expert's?
- for every state–action pair
- 0 for every pair, since every pair is the expert's
- 1 for every pair, since every pair is the learner's
- It is undefined, because the classification problem is degenerate
Show the answer
A. for every state–action pair
wherever the two measures agree. The cost is then constant, so it gives the policy no direction to move: the expert's occupancy measure is a fixed point of the game.
At the optimal discriminator, what does AIRL's reward equal, and which divergence does the policy then minimize?
- , and the forward KL
- , and the reverse KL
- , and the Jensen–Shannon divergence
- The true reward, and no divergence at all
Show the answer
B. , and the reverse KL
With the probability of the expert, the Bayes-optimal log-odds are , whose expectation under the learner's occupancy measure is . Reverse KL is mode-seeking: it punishes the learner hardest for visiting pairs the expert never visits.
Why can ValueDICE's objective be estimated without samples from the learner's own occupancy measure?
- It reweights the expert's samples by importance ratios
- It fits a dynamics model and simulates the learner
- It assumes that the learner already matches the expert
- The change of variables makes the on-policy expectation telescope into one over start states, leaving only expert transitions, start states and the learner's action choices
Show the answer
D. The change of variables makes the on-policy expectation telescope into one over start states, leaving only expert transitions, start states and the learner's action choices
The Donsker–Varadhan form of has one expectation under , which the demonstrations provide, and one under . Writing turns the second into by the flow constraints of .
Further reading
- J. Ho & S. Ermon, "Generative adversarial imitation learning," NeurIPS (2016).
- J. Fu, K. Luo & S. Levine, "Learning robust rewards with adversarial inverse reinforcement learning," ICLR (2018).
- S. K. S. Ghasemipour, R. Zemel & S. Gu, "A divergence minimization perspective on imitation learning methods," CoRL (2019).
- I. Kostrikov, O. Nachum & J. Tompson, "Imitation learning via off-policy distribution matching," ICLR (2020).
- D. Garg, S. Chakraborty, C. Cundy, J. Song & S. Ermon, "IQ-Learn: Inverse soft-Q learning for imitation," NeurIPS (2021).