Skip to content
AI360XpertBeta

Adversarial Inverse RL (AIRL)

AIRL copies the goal instead of the motions. It splits what the expert wanted from how the old world moved, so the aim still works when the world changes.

A discriminator score of 0.9813 splits into portable reward 2.00 plus shaping 0.35, and the 2.00 survives when the next-state potential drops
A discriminator score of 0.9813 splits into portable reward 2.00 plus shaping 0.35, and the 2.00 survives when the next-state potential drops

Why Does This Exist?

Copying motions fails when the world shifts. GAIL matches the expert's state-action visits, and its discriminator soaks up the training world's physics along with the behavior. Move one hurdle, change the friction, jam a motor, and the copied motions land in empty air. The agent learned how to move, not what to want.

Wanting is a reward function, and recovering rewards from demonstrations is inverse RL. Classical maximum entropy IRL does this honestly and slowly: every gradient step re-solves a forward RL problem, which is hopeless for hard continuous control.

AIRL keeps the adversarial sample efficiency and repairs the transfer. It structures the discriminator so the portable state reward separates from the dynamics-dependent shaping term. The reward exports to new physics. The shaping stays behind.

Think of It Like This

The agility dog that learns the prize

A champion dog runs an agility course: tunnel, red hurdle, finish line with food.

The mimicking student memorizes paw placements and leap timing. While the hurdles stay put, it shines. Slide the red hurdle three meters left and it leaps into empty air. It copied the route, not the reason.

The AIRL student splits the demo in two. The hurdle jump was local maneuvering for that arena layout. The food at the finish was the point. In a new arena it plans a fresh path around the moved hurdles and still sprints to the bowl.

Where it stops: a real dog smells the food. AIRL gets zero reward signal during demos and must isolate the goal purely from the discriminator math, which is why the state-only restriction below carries the whole guarantee.

How It Actually Works

Symbols for this page: ss is the state, aa the action, s′s' the next state, π(a∣s)\pi(a \mid s) the learner policy, gθ(s)g_\theta(s) the portable state reward network, hϕ(s)h_\phi(s) the shaping potential network, γ\gamma the discount, and DD the discriminator.

Maximum entropy IRL says the expert policy looks like π∗(a∣s)∝exp⁡(Q∗(s,a)−V∗(s))\pi^*(a \mid s) \propto \exp(Q^*(s,a) - V^*(s)). AIRL bakes that shape into the discriminator:

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

Reward split that survives new physics

Reward shaping theory says two rewards share the optimal policy exactly when they differ by γΦ(s′)−Φ(s)\gamma \Phi(s') - \Phi(s). AIRL parameterizes the advantage to expose that split:

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

The gθ(s)g_\theta(s) term sees only the state and carries the goal. The γhϕ(s′)−hϕ(s)\gamma h_\phi(s') - h_\phi(s) term absorbs layout quirks and value offsets. When gg stays state-only, theory says its optimum equals the true reward up to a constant, free of transition dynamics. That is the export license: train in world one, carry gg into world two, re-plan there.

The two-step training loop

The discriminator learns binary cross-entropy on expert transitions against policy transitions. The policy trains with policy gradients on the surrogate reward:

r^(s,a,s′)=log⁡D−log⁡(1−D)=f(s,a,s′)−log⁡π(a∣s)\hat{r}(s, a, s') = \log D - \log(1 - D) = f(s, a, s') - \log \pi(a \mid s)

Low policy probability under the current π\pi raises the surrogate, which pushes the policy toward expert-like transitions without ever copying joint angles directly.

Worked example with discriminator 0.9813

One transition carries gθ(s)=2.0g_\theta(s) = 2.0, potentials hϕ(s)=1.0h_\phi(s) = 1.0 and hϕ(s′)=1.5h_\phi(s') = 1.5, discount γ=0.9\gamma = 0.9, and policy probability π(a∣s)=0.20\pi(a \mid s) = 0.20.

Shaped advantage:

f=2.0+0.9×1.5−1.0=2.0+1.35−1.00=2.35f = 2.0 + 0.9 \times 1.5 - 1.0 = 2.0 + 1.35 - 1.00 = 2.35

The portable part contributes 2.002.00 and the shaping contributes 0.350.35. Discriminator:

exp⁡(2.35)≈10.4856,D=10.485610.4856+0.20≈0.9813\exp(2.35) \approx 10.4856, \quad D = \frac{10.4856}{10.4856 + 0.20} \approx 0.9813

Near one, so the discriminator calls this expert-like. Surrogate reward with log⁡(0.20)≈−1.6094\log(0.20) \approx -1.6094:

r^=2.35−(−1.6094)=3.9594\hat{r} = 2.35 - (-1.6094) = 3.9594

Now change the world. Higher friction routes the same (s,a)(s, a) to s′′s'' with hϕ(s′′)=0.80h_\phi(s'') = 0.80. The shaping becomes 0.9×0.80−1.0=−0.280.9 \times 0.80 - 1.0 = -0.28 and the advantage drops to 1.721.72. The portable gθ(s)=2.00g_\theta(s) = 2.00 does not move. The agent re-optimizes gg under the new physics instead of replaying stale motions.

Code

A short check of the worked numbers above, with type hints throughout:

import math

def shaped_advantage(g: float, h: float, h_next: float, gamma: float) -> float:    return g + gamma * h_next - h

def discriminator(f: float, pi: float) -> float:    expf = math.exp(f)    return expf / (expf + pi)

g = 2.0h = 1.0h_next = 1.5gamma = 0.9pi = 0.20
f = shaped_advantage(g, h, h_next, gamma)d = discriminator(f, pi)r = f - math.log(pi)print([round(f, 2), round(math.exp(f), 4), round(d, 4), round(r, 4)])# -> [2.35, 10.4856, 0.9813, 3.9594]
f2 = shaped_advantage(g, h, 0.80, gamma)print([round(f2, 2), round(g, 2)])# -> [1.72, 2.0]
# -> expected output:[2.35, 10.4856, 0.9813, 3.9594][1.72, 2.0]

Watch Out For

Letting the reward see the action

Widening gg to g(s,a)g(s, a) feels more expressive and breaks the guarantee. With actions inside, the shaping term can no longer absorb dynamics uniquely, and the learned reward entangles with the training world's transitions. Transfer to new friction or payloads then produces erratic policies that exploit stale shaping.

Keep gg state-only. That single restriction is what makes the recovered reward portable.

The Quick Version

  • AIRL structures its discriminator as D=exp⁡(f)/(exp⁡(f)+π)D = \exp(f)/(\exp(f) + \pi) with f(s,a,s′)=g(s)+γh(s′)−h(s)f(s,a,s') = g(s) + \gamma h(s') - h(s).
  • The state-only g(s)g(s) carries the goal and exports across dynamics, while hh absorbs training-world shaping.
  • Unlike GAIL motion matching, the recovered goal re-plans under new physics instead of replaying stale paths.
  • One worked step gives advantage 2.352.35, discriminator 0.98130.9813 and surrogate reward 3.95943.9594, with g=2.00g = 2.00 unchanged when shaping drops the total to 1.721.72.
  • Conditioning the reward on actions voids the disentanglement, so keep gg state-only.