Search

Search papers and lessons

Adversarial Inverse Reinforcement Learning

Level 4 · 10 min read

Adversarial inverse reinforcement learning trains a discriminator to separate expert moves from the learner's, and reads a reward off the discriminator that transfers when the environment changes.

On this page

  • Colour = topic mix
  • Probability
  • Discrete math
  • Reinforcement learning
  • Calculus
  • Neural network basics
  • Linear algebra
  • ReadReady to readNot yet

TL;DR

Adversarial inverse reinforcement learning (AIRL) learns a reward function from an expert's demonstrations. It trains a discriminator to tell expert state-action pairs from the learner's, then uses that discriminator's output as the reward for a standard reinforcement learning step. Its reward is built so that it depends on the state more than on the particular dynamics, which lets a policy trained on it still behave well after the environment changes.

Builds on: Inverse Reinforcement Learning, Generative Adversarial Network, Maximum Entropy Reinforcement Learning, Reward Shaping · Leads to: reward-learning methods that transfer across environments, a step beyond plain Behavior Cloning

Where it's used

Robot control from demonstrations. A robot arm or a legged robot can be shown how to move by a person, but writing a reward function that scores a whole motion is hard. AIRL learns that score from the demonstrations, then reinforcement learning turns it into a policy.

Reusing a reward on a changed body. The paper's transfer test trains a quadruped "ant" to run forward, then disables and shrinks two of its front legs. A policy optimised with the learned state-only reward has to change its gait to crawl, and it still works, where a policy transferred from GAIL does not. The paper reports a score of 130.3 for that policy, against negative 58.8 for a policy transferred the GAIL way.

Benchmark imitation tasks. On Pendulum, Ant, Swimmer and HalfCheetah, the paper gives the learner 50 expert demonstrations and compares AIRL with GAIL, the leading imitation method of its time. Both reach close to the best achievable results on these tasks, so AIRL matches imitation performance while also recovering a reward.

How it works

Think of a learner that must move the way an expert moves. AIRL runs a loop with two players, the same pattern as a generative adversarial network.

  1. Collect expert pairs. Record state-action pairs (s,a)(s, a) from expert demonstrations. Check: each pair is one moment of expert behaviour, so the expert data is a set of such pairs.
  2. Collect learner pairs. Let the current policy π\pi act in the environment, a Markov decision process, and record its own state-action pairs. Check: the learner's pairs are the fake samples in the adversarial game.
  3. Score each pair with the discriminator. For a pair (s,a)(s, a) the discriminator outputs D(s,a)D(s, a), the probability that the pair came from the expert, not the learner. It is built from a learned function f(s,a)f(s, a) and the learner's own probability π(a∣s)\pi(a \mid s). Check: when ff is high relative to π\pi, DD is near 1, meaning "looks like the expert".
  4. Update the discriminator. Adjust ff so that expert pairs get DD near 1 and learner pairs get DD near 0. Check: ff is the reward candidate, so this is also a reward update.
  5. Read off the reward. The policy's reward for a pair is f(s,a)−log⁡π(a∣s)f(s, a) - \log \pi(a \mid s), which is the log-odds that the pair came from the expert. Check: pairs the discriminator trusts earn high reward.
  6. Update the policy. Run a Policy Gradient step on that reward, using a method such as Trust Region Policy Optimization (TRPO). The policy moves toward expert-like pairs. Check: the learner's new pairs should look more like the expert's, so the next discriminator step has a harder job.
  7. Repeat. Alternate steps 3 to 6 until the discriminator cannot separate the two sets of pairs. Then the learned ff is the reward the expert seems to be optimising.

The difference from ordinary imitation is step 5. A plain imitation method uses the discriminator only to nudge the policy toward the expert. AIRL keeps ff as a reward, and step 4 tunes that reward against the expert data.

The math

Step 3 in symbols: the discriminator

Let π(a∣s)\pi(a \mid s) be the learner's policy and f(s,a)f(s, a) a learned function. The discriminator is

D(s,a)=exp⁡{f(s,a)}exp⁡{f(s,a)}+π(a∣s)D(s, a) = \frac{\exp\{f(s, a)\}}{\exp\{f(s, a)\} + \pi(a \mid s)}

It is the probability that (s,a)(s, a) came from the expert, under equal prior odds. The function exp⁡{f}\exp\{f\} is always positive, so DD always lies between 0 and 1.

Step 4 in symbols: the training objective

The discriminator is trained by ordinary binary cross-entropy: expert pairs are labelled 1 and learner pairs 0. Expert pairs push DD up, learner pairs push DD down. Because DD depends on ff only through exp⁡{f}\exp\{f\}, minimising this loss adjusts ff directly.

Step 5 in symbols: the reward

Solve the formula above for the odds. Since D/(1−D)=exp⁡{f}/πD / (1 - D) = \exp\{f\} / \pi, taking logs gives

log⁡D(s,a)1−D(s,a)=f(s,a)−log⁡π(a∣s)\log \frac{D(s, a)}{1 - D(s, a)} = f(s, a) - \log \pi(a \mid s)

The policy's reward is this log-odds. The paper uses the opposite sign convention for its written objective, but the quantity that rewards expert-like pairs is this one.

What the optimum looks like

At the optimum the learner matches the expert, and the paper shows that f∗(s,a)=log⁡π∗(a∣s)f^{*}(s, a) = \log \pi^{*}(a \mid s). For a maximum-entropy optimal policy, log⁡π∗(a∣s)=Q∗(s,a)−V∗(s)\log \pi^{*}(a \mid s) = Q^{*}(s, a) - V^{*}(s), which is the Advantage Function. So for a plain imitation objective, ff is the advantage of the expert's policy. That reward is valid in the training environment, but it is entangled with the dynamics.

The disentangled form

To remove that entanglement, the paper writes ff as a state-only reward plus a shaping term:

fθ,ϕ(s,a,s′)=gθ(s)+γhϕ(s′)−hϕ(s)f_{\theta,\phi}(s, a, s') = g_{\theta}(s) + \gamma h_{\phi}(s') - h_{\phi}(s)

Here gθg_{\theta} is the reward estimate, hϕh_{\phi} is a learned shaping term, γ\gamma is the discount factor, and s′s' is the next state. The term γh(s′)−h(s)\gamma h(s') - h(s) is the form of Reward Shaping that leaves the optimal policy unchanged. Under the paper's conditions, the optimum gives g∗(s)=r∗(s)+constg^{*}(s) = r^{*}(s) + \text{const} and h∗(s)=V∗(s)+consth^{*}(s) = V^{*}(s) + \text{const}, where r∗r^{*} is the true reward. The shaping term absorbs the value function, so gg is left as the true state reward.

Worked examples

Example
1. One pair, by hand
  1. Take one state-action pair with the learner's probability π(a∣s)=0.25\pi(a \mid s) = 0.25.
  2. Suppose the learned function is f(s,a)=0f(s, a) = 0, so exp⁡{f}=1\exp\{f\} = 1.
  3. The discriminator is D=1/(1+0.25)=0.8D = 1 / (1 + 0.25) = 0.8.
  4. The reward is f−log⁡π=0−log⁡0.25=log⁡4≈1.386f - \log \pi = 0 - \log 0.25 = \log 4 \approx 1.386.
  5. Check: log⁡D−log⁡(1−D)=log⁡0.8−log⁡0.2=log⁡4\log D - \log(1 - D) = \log 0.8 - \log 0.2 = \log 4, the same number.
  6. Interpretation: the discriminator says the pair looks 80 percent expert-like, and the reward is positive, so the policy is pushed toward this action.
Example
2. The equilibrium in one state
  1. In a state with two actions, let the expert's policy be π∗(a1∣s)=0.8\pi^{*}(a_1 \mid s) = 0.8 and π∗(a2∣s)=0.2\pi^{*}(a_2 \mid s) = 0.2.
  2. At the optimum, f∗(s,a)=log⁡π∗(a∣s)f^{*}(s, a) = \log \pi^{*}(a \mid s), so exp⁡{f∗(s,a1)}=0.8\exp\{f^{*}(s, a_1)\} = 0.8 and exp⁡{f∗(s,a2)}=0.2\exp\{f^{*}(s, a_2)\} = 0.2.
  3. Suppose the learner's policy has also converged, so π=π∗\pi = \pi^{*}.
  4. For a1a_1, D=0.8/(0.8+0.8)=0.5D = 0.8 / (0.8 + 0.8) = 0.5. For a2a_2, D=0.2/(0.2+0.2)=0.5D = 0.2 / (0.2 + 0.2) = 0.5.
  5. Interpretation: the discriminator outputs one half everywhere. It cannot tell the expert from the learner, which is the sign that the learner has matched the expert.
Example
3. The disabled ant, from the paper

The comparison uses the paper's Table 1, Ant-Disabled column, with 5 runs per entry.

  1. The policy transferred from GAIL, with no reward learned, scores negative 58.8.
  2. The policy optimised with AIRL's state-only reward scores 130.3.
  3. The gap is 130.3−(−58.8)=189.1130.3 - (-58.8) = 189.1 points.
  4. The policy trained with the true reward on the disabled ant scores 315.5, so the AIRL policy reaches 130.3/315.5≈0.41130.3 / 315.5 \approx 0.41 of that.
  5. Interpretation: the learned reward carries over to a changed body, while copying the expert's actions does not.

Try it: on the Point Mass-Maze column, the AIRL state-only policy scores negative 8.82 and the policy trained on the true reward scores negative 8.45. What is the gap between the two scores? Answer: ∣−8.82−(−8.45)∣=0.37|-8.82 - (-8.45)| = 0.37 points, so the learned reward is close to the true one on this task.

Common mistakes and tradeoffs

It is tempting to think AIRL is just GAIL with a different name. In fact, GAIL trains a discriminator only to shape the policy, so it does not return a reward. AIRL keeps the discriminator's ff as a reward, which is why it can be reused in a new environment.

It is tempting to think a learned reward is automatically the true reward. In fact, many rewards explain the same expert, and shaping terms can change the reward without changing the optimal policy. That is why AIRL uses a state-only reward and a shaping term, and why the disentangled form is needed for transfer.

It is tempting to think the discriminator's output is a probability of success. In fact DD is a probability that a pair came from the expert, and at the optimum it sits at one half, so a value near 0.5 means the learner is doing well, not badly.

Use AIRL when you need a reward you can reuse or inspect, when the environment may change, or when you have demonstrations but no reward. Do not use it when a simple behaviour-cloning baseline already works and no transfer is needed, since adversarial training is slower and less stable. Alternatives include GAIL when you only need a policy, and direct behaviour cloning on large expert datasets.

History

Inverse reinforcement learning was framed by Ng and Russell in 2000 as the problem of finding a reward that explains expert behaviour. Its ambiguity was a known difficulty: many rewards can explain the same policy. Ziebart and colleagues developed maximum-entropy inverse reinforcement learning, which chooses among the candidate rewards by a principle. AIRL builds on that framework.

Finn and colleagues showed in 2016 a connection between generative adversarial networks and inverse reinforcement learning, with a discriminator over whole trajectories. Ho and Ermon (2016) then introduced GAIL, which drops the reward structure to make imitation fast but cannot recover a reward. Fu, Luo and Levine (2017) gave AIRL: a state-action discriminator with the reward structure that recovers a reward, and a state-only form that transfers across environments. The paper's results on transfer and benchmark imitation tasks are the evidence cited for it.

Recap

  • Inverse reinforcement learning asks for the reward that explains expert behaviour, which is ambiguous without extra structure.
  • AIRL uses a discriminator D=exp⁡{f}/(exp⁡{f}+π)D = \exp\{f\} / (\exp\{f\} + \pi) to separate expert pairs from learner pairs.
  • The policy's reward is f−log⁡πf - \log \pi, the log-odds of expert-likeness; at the optimum ff equals the expert's log-policy, which is the advantage.
  • A state-only reward plus a shaping term removes dynamics-dependent parts, so the reward transfers to changed environments.
  • Read next: Inverse Reinforcement Learning for the wider problem, and Generative Adversarial Network for the adversarial training loop.

Check yourself

QuestionWhat is the discriminator's output D(s, a) a probability of, and what does D equal when the learner matches the expert?Show answer
D(s, a) is the probability that the pair (s, a) came from the expert rather than the learner. When the learner matches the expert, the expert and learner pairs have the same distribution, so D is one half everywhere.
QuestionA pair has learner probability pi(a | s) = 0.5 and learned function f(s, a) = log 2. What is the discriminator D, and what is the policy's reward?Show answer
exp of f is 2, so D = 2 / (2 + 0.5) = 0.8. The reward is f minus log pi, which is log 2 minus log 0.5, equal to log 4, about 1.386.
QuestionWhy does AIRL use a state-only reward with a shaping term instead of the plain state-action reward f(s, a)?Show answer
The plain reward at the optimum is the expert's advantage, which is entangled with the training dynamics. Reward shaping can change the reward without changing the optimal policy, so the plain reward may not transfer. A state-only reward plus a shaping term separates the reward from the dynamics, so the learned reward carries over when the environment changes.
QuestionA team records 50 expert demonstrations of a warehouse robot and wants a reward it can reuse after the robot's wheels are replaced with a different model. Should they use AIRL or plain behaviour cloning, and why?Show answer
AIRL, because it learns a reward that can be reused and re-optimised in the changed environment. Behaviour cloning copies the expert's actions and gives no reward, so the copied policy may fail when the dynamics change.

Sources