Maximum-Entropy Inverse RL
A probabilistic model of near-optimal behavior, and its feature-matching gradient.
Maximum-entropy inverse RL turns an ill-posed inverse problem into a well-posed statistical one: of all the ways to match the expert's feature counts, assume nothing more. This lesson derives the resulting exponential-family model and its gradient, repairs its flaw under stochastic dynamics with maximum causal entropy, builds the backward–forward algorithm, and follows the idea to neural rewards, sampled partition functions and an exact equivalence with GANs.
What you’ll learn
- Derive the maximum-entropy trajectory distribution under feature-matching constraints, show that fitting it is concave maximum likelihood, and compute its gradient.
- Explain why the 2008 trajectory model misbehaves under stochastic dynamics, and state the soft Bellman recursion of maximum causal entropy.
- Write the backward (soft value iteration) and forward (visitation) passes and state their cost.
- Explain deep maximum-entropy IRL, guided cost learning's importance-sampled partition function, and the equivalence between sample-based maximum-entropy IRL and a GAN whose discriminator knows the generator's density.
Maximum entropy over trajectories
Maximize the entropy subject to matching the features and normalization, with multipliers and :
Setting the derivative of the Lagrangian with respect to to zero, , gives an exponential family over trajectories:
Substituting back, the entropy is and the Lagrangian collapses to the dual function . Minimizing it is the same as maximizing the average log-likelihood of the demonstrations:
The gradient of is the model's expected feature count, and its Hessian is the feature covariance, which is positive semidefinite. So the log-likelihood is concave, its gradient is expert features minus model features, and at the optimum the two match:
Three routes take 10, 10 and 12 minutes. The only feature is travel time, with weight per minute. Under the maximum-entropy model, what is the probability of the 12-minute route?
Show the answer
0.06
. The two equally fast routes share the rest equally, about 0.47 each. A model that chose locally, junction by junction, could give equally good routes different probabilities depending on how many branches they pass; Ziebart et al. called this label bias and avoided it by normalizing over whole trajectories.
Two properties made the model popular. Trajectories with equal reward get equal probability and better ones get exponentially more, so the model ranks behavior by reward and nothing else. And every feasible trajectory has positive probability, so suboptimal or inconsistent demonstrations never make the problem infeasible: they lower the fitted instead, the model's way of saying the demonstrator is noisy.
Stochastic dynamics and maximum causal entropy
With stochastic transitions a trajectory is no longer fixed by the actions. Ziebart et al. (2008) approximated . That lets the outcome of a transition influence the probability of the action before it: an action looks better when its lucky outcomes are good, as if the agent could choose its luck.
Under the 2008 trajectory model, what is ?
Show the answer
0.79
, so . The trajectory model aggregates outcomes by , which exceeds by Jensen's inequality, so a demonstrator who is indifferent between the two actions looks risk-seeking. Fitting such a model to real data would attribute to people a taste for gambling that is an artifact of the model.
Two remarks. The likelihood of a demonstration under the causal model is : the transition probabilities do not depend on and drop out, so the dynamics are needed only to compute , not to score data. And the recursion is exactly the soft Bellman equation of maximum-entropy RL (Maximum-Entropy RL & Soft Actor–Critic): maximum-entropy IRL is the inverse of maximum-entropy RL, which is why it reappears inside GAIL, AIRL and IQ-Learn.
The backward–forward algorithm
Each gradient step needs the model's expected feature counts. Over a horizon they come from two dynamic programs, one backward in time and one forward.
Backward pass (soft value iteration), V_T(s) = 0; for t = T−1, ..., 0:
Q_t(s, a) = θᵀφ(s, a) + Σ_s' P(s' | s, a) · V_{t+1}(s')
V_t(s) = log Σ_a exp Q_t(s, a)
π_t(a | s) = exp(Q_t(s, a) − V_t(s))
Forward pass (expected visits), D_0(s) = Pr(S_0 = s); for t = 0, ..., T−1:
D_{t+1}(s') = Σ_{s, a} D_t(s) · π_t(a | s) · P(s' | s, a)
Gradient:
f̃ − Σ_t Σ_{s, a} D_t(s) · π_t(a | s) · φ(s, a)Each pass costs for at most successor states per state–action pair, and both are repeated at every gradient step: the inner loop is a full soft planning problem. Ziebart et al.'s 2008 algorithm is the same computation for deterministic dynamics, written with partition functions .
Three practical notes.
- Work in log space. is a log-sum-exp; exponentiating directly overflows as soon as rewards are large.
- Mind the horizon. With an infinite horizon and absorbing goal states, can diverge even when every reward is negative, as Ziebart et al. note; a finite horizon or a discount avoids it.
- The data are estimates too. averages demonstrations. With bounded features, Hoeffding's inequality and a union bound over the features control each coordinate's error at rate times the range of the feature counts, which is the statistical side of the feature-matching guarantee.
Neural rewards, sampled partition functions and GANs
Deep maximum-entropy IRL (Wulfmeier, Ondruska & Posner, 2015) replaces the linear reward with a network , for example a convolutional network over a map. With one indicator feature per state, the gradient with respect to each state's reward is the demonstrations' average number of visits minus the model's expected number , from the forward pass; the chain rule carries it into the network:
Guided cost learning (Finn, Levine & Abbeel, 2016) drops the planning. With a learned cost and the model , it estimates by importance sampling from trajectories of a sampling policy :
Give the discriminator the generator's density and a learned normalizer , and let it output the probability that a trajectory is a demonstration:
Finn et al. show that training this discriminator by logistic regression, demonstrations against generated trajectories, optimizes the maximum-entropy IRL cost objective, with the partition function estimated by importance sampling from a mixture of demonstrations and samples.
The generator's GAN loss, computed directly from the form of , is the maximum-entropy RL objective for the current cost: the expected cost minus the generator's entropy, plus a constant.
So the sample-based form of maximum-entropy IRL is a GAN whose discriminator knows the generator's density. AIRL applies the same construction to single state–action pairs, with the policy's probability in place of , which lowers the variance that whole trajectories bring (Adversarial Imitation: GAIL & Distribution Matching).
Key takeaways
- The maximum-entropy distribution matching expected feature counts is ; its dual is maximum likelihood, concave with Hessian , and its gradient is .
- Under stochastic dynamics the trajectory model lets outcomes influence the preceding action, so indifferent demonstrators look risk-seeking; maximum causal entropy gives with the soft Bellman recursion , .
- Each gradient step solves a soft planning problem backward and propagates expected visits forward, at cost ; computations belong in log space.
- Deep maximum-entropy IRL backpropagates visit differences into a neural reward; guided cost learning estimates the partition function by importance sampling from an adaptively trained policy, which is exactly a GAN whose discriminator knows the generator's density.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
At the maximum-likelihood of maximum-entropy IRL, what holds?
- The model assigns probability 1 to the demonstrated trajectories
- The model's expected feature counts equal the demonstrations' average feature counts
- The demonstrated trajectories have the highest reward under
- , because entropy is maximal there
Show the answer
B. The model's expected feature counts equal the demonstrations' average feature counts
The gradient is , so it vanishes exactly when the feature expectations match, which is the constraint of the maximum-entropy problem. By the feature-matching argument, the model is then as good as the demonstrator under every reward linear in the features.
Why is the maximum-entropy IRL log-likelihood concave in (for rewards linear in the features)?
- Because the entropy is concave
- Because the dynamics are deterministic
- Because the feature counts are nonnegative
- Because its Hessian is , and covariance matrices are positive semidefinite
Show the answer
D. Because its Hessian is , and covariance matrices are positive semidefinite
The log-likelihood is linear in minus , and is the cumulant function of an exponential family, whose Hessian is the covariance of the sufficient statistics. Concavity is what makes simple gradient ascent find the global optimum.
Why did Ziebart, Bagnell and Dey replace the 2008 trajectory model with maximum causal entropy for stochastic dynamics?
- Because the trajectory model lets the outcomes of transitions raise or lower the probability of the actions before them, so the modeled agent behaves as if it could choose its luck
- Because the trajectory model cannot represent deterministic dynamics
- Because maximum causal entropy needs no model of the dynamics
- Because the trajectory model's likelihood is not concave
Show the answer
A. Because the trajectory model lets the outcomes of transitions raise or lower the probability of the actions before them, so the modeled agent behaves as if it could choose its luck
Weighting each full trajectory by aggregates random outcomes optimistically (), so in the gamble example an indifferent demonstrator appears to prefer gambling 79% of the time. The causal model conditions each action only on the past and backs up the expected soft value.
In the GAN view of sample-based maximum-entropy IRL, with , what does the generator minimize?
- The probability that the discriminator labels its samples correctly, and nothing else
- The cost alone, with no entropy term
- : the maximum-entropy RL objective for the current cost
- The KL divergence from the demonstrations to its samples,
Show the answer
C. : the maximum-entropy RL objective for the current cost
Plugging the special form of into the generator's loss gives . The generator therefore does entropy-regularized RL on the current cost, and the discriminator update is the cost update of maximum-entropy IRL.
Further reading
- B. D. Ziebart, A. Maas, J. A. Bagnell & A. K. Dey, "Maximum entropy inverse reinforcement learning," AAAI (2008).
- B. D. Ziebart, J. A. Bagnell & A. K. Dey, "Modeling interaction via the principle of maximum causal entropy," ICML (2010).
- M. Wulfmeier, P. Ondruska & I. Posner, "Maximum entropy deep inverse reinforcement learning," arXiv:1507.04888 (2015).
- C. Finn, S. Levine & P. Abbeel, "Guided cost learning: Deep inverse optimal control via policy optimization," ICML (2016).
- C. Finn, P. Christiano, P. Abbeel & S. Levine, "A connection between generative adversarial networks, inverse reinforcement learning, and energy-based models," arXiv:1611.03852 (2016).