TL;DR
Inverse reinforcement learning (IRL) works backwards from reinforcement learning. Instead of being given a reward and finding good behaviour, it watches good behaviour and asks which reward would make that behaviour the best choice. Once the reward is recovered, an ordinary reinforcement learner can be trained on it, and the result can generalise to situations the expert never showed.
The catch is that many different rewards explain the same behaviour, so the problem needs an extra rule to pick one.
Where you'll see it: teaching robots and self-driving systems from human demonstrations, and modelling how people trade off goals, such as how a driver balances speed against comfort.
Intuition
Start from a question you already know
Watch a friend cross a busy city. They always take the tree-lined street, even when the bus route is shorter. You want to know what they value. Maybe they like shade, maybe they dislike noise, maybe they just like walking past the bakery. Whatever the reason, their choices reveal a preference, and a good model of that preference would let you predict their next trip.
That is the IRL question. The expert's choices are the evidence. The reward is the hidden preference that the choices came from. Reinforcement learning answers "given the preference, what should I do?" Inverse reinforcement learning answers "given what was done, what preference explains it?"
Why not just copy the expert
Behavior Cloning already learns from demonstrations, by predicting the expert's action in each situation. It is simple, but it has two weaknesses. First, when the learner drifts into a situation the expert never visited, it has no guidance. Second, the copied behaviour is tied to the exact demonstrations, so it does not transfer to a new layout or a new goal.
IRL tries to recover the reason behind the behaviour. If the learner knows that the expert wants to stay in the shade, it can act sensibly in a street the expert never walked.
The simplest version: one choice
Suppose an expert is in a state with two actions, x and y, and always picks x. What reward explains this? Any reward where x is worth more than y does. The data says nothing beyond that. That already shows the core difficulty: the answer is a set, not a single reward. We will return to this in the math section.
The math
Setting
IRL starts from a Markov Decision Process with states , actions , transitions and a discount factor , but without the reward . The discount factor says how much a reward steps away is worth today, namely of its face value. An expert policy generated trajectories . The learner sees samples of these trajectories and wants a reward function that explains them.
A common choice is a reward that is linear in known features:
where is a vector of numbers describing the state, such as distance to the road edge or whether a cell is wet, and is the weight vector the learner must find. The features are chosen by the designer, and they are the main way prior knowledge enters.
The feature expectation
For a policy , define its feature expectation
Each entry says how much of that feature the policy collects, discounted over time. The expected return under the reward is then , because the reward is linear. This is the key simplification: the policy's value depends on the weights only through its feature expectation.
Apprenticeship learning: match the features
Abbeel and Ng (2004) noticed that if the learner finds a policy whose feature expectation matches the expert's , then the learner's return under any linear reward is the same as the expert's. The learner can then perform as well as the expert on every reward of that form (with the weights bounded in size, say ). Their method repeatedly picks a new reward direction that separates the expert from the current learner, trains a policy on that reward, and repeats until the gap closes.
The ambiguity problem
Matching features is not enough to pin down a reward. The zero reward, , makes every policy equally good, so the expert is trivially optimal under it. Real demonstrations can also be explained by many non-zero rewards. Two common fixes are to demand that the expert be better than others by a margin, or to use a probabilistic model of the expert. The second is the most widely used.
Maximum-entropy IRL
Ziebart and colleagues (2008) model the expert as choosing trajectories with probability proportional to the exponential of their total reward:
Here is the normaliser, the sum over all possible trajectories, which makes the probabilities add to one. Higher reward means exponentially higher probability, but not certainty. The model is the one with the highest Entropy (the least committed) among those that match the average feature counts of the demonstrations.
Maximising the log-likelihood of the demonstrations gives a clean gradient. Write for the discounted feature sum along a trajectory and for its average over demonstrations. Then
The gradient is the gap between the expert's feature totals and the feature totals the current reward would produce. Gradient ascent on closes that gap, which is again feature matching. The expectation under requires solving the MDP under the current reward, usually with a soft version of value iteration, which uses the Bellman Equation but replaces the hard maximum over actions with a smooth one, the log of a sum of exponentials (see Maximum Entropy Reinforcement Learning).
- Start with weights , for example all zeros.
- Solve the MDP under with soft value iteration. This gives a stochastic policy .
- Compute the expected discounted feature counts by rolling out or by a state-visitation calculation.
- Compute the gradient .
- Update with step size .
- Repeat until the gradient is small.
Step 2 is the expensive part. Every outer update needs an inner solve of the MDP, which is why IRL is slow compared with behaviour cloning.
Using the recovered reward
Once is found, the learner has a reward. It can train a policy with any reinforcement learning method, such as Policy Gradient methods. The policy is then no longer a copy of the expert, but an optimiser of the inferred goal. This is what lets it handle new states.
Worked examples
Setup. A commuter has two routes, route 1 and route 2. We use a single feature: route 1 has feature value and route 2 has on a "pleasant" feature, and the reward of a route is for a single weight (the simplest case of the linear reward above). The maximum-entropy model gives .
- Observed frequency: the commuter takes route 1 on 80 percent of days.
- Set the model equal to the observed frequency: .
- Solve: , so , so .
- Take the logarithm: .
- Check: . The model reproduces the observed frequency.
Interpretation. The positive weight says the commuter values the pleasant feature. The number is not the reward in any absolute sense, only the difference between the two routes, which is all the data can reveal.
Setup. A state has actions x and y. The expert takes x every time.
- Suppose and . The expert is optimal, and the demonstrations are consistent with it.
- Suppose and . Both actions are equally good, so the expert's choice of is still optimal under the tie-breaking rule, and the demonstrations are consistent with this too.
- Suppose and . The expert is still optimal, because beats .
- In this one-state case, every reward with explains the data. That includes the useless reward that is zero everywhere.
Interpretation. Demonstrations alone say the expert prefers to , and nothing about how much. A learner that copies this reward would have no sense of scale, which matters when it must trade one goal against another. Probabilistic models and margin constraints exist to break exactly this tie.
Setup. (Illustrative numbers, not from a real dataset.) A driving policy is described by two features: , the fraction of time spent within half a metre of the lane edge, and , the fraction of time spent in the fast lane. Human demonstrations give an average . The current policy, under the current reward, gives an expected feature count . Take step size and start from .
- Gap: .
- Update: .
- Interpretation of the first weight: it is negative, so the new reward penalises time near the lane edge. That is correct, because the current policy hugs the edge far more than the experts do.
- Interpretation of the second weight: it is positive, so the new reward favours the fast lane, which the experts use more than the current policy.
- Next step: re-solve the MDP under the new reward, which shifts the policy toward less edge time and more fast-lane time, and repeat until the gap is near zero.
Interpretation. One step is not a model. It shows the mechanism. The learner repeatedly moves its reward until its own behaviour looks like the expert's on the features the designer chose, and the quality of the final reward depends on whether those features capture what the expert cares about.
Tradeoffs and failure modes
| Situation | What goes wrong | Better choice |
|---|---|---|
| Demonstrations are few, or the states rarely visited by the expert matter | The recovered reward is wrong outside the data, so the policy fails there | Collect more demonstrations, or add prior structure to the reward |
| The features leave out something the expert cares about | The learner matches features but behaves wrongly, because the missing factor is absorbed into other features | Add features, or learn the features too |
| The environment model is unknown and cannot be simulated | The inner MDP solve is impossible | Adversarial imitation such as [[gail-paper |
| Only the next action is needed and the states look the same as the demonstrations | IRL's extra work is wasted | Behavior Cloning, which is far cheaper |
| The expert is not optimal, for example it is tired or inconsistent | Forcing an optimal reward explanation misleads the learner | Models of noisy or bounded rationality |
The main tradeoff is between IRL's generalisation and its cost. Recovering a reward lets the learner act in new states, but every reward update costs a full inner solve.
History
Andrew Ng and Stuart Russell (2000) framed the problem of recovering a reward from optimal behaviour, showing that it is ill-posed without further assumptions. Pieter Abbeel and Andrew Ng (2004) turned it into apprenticeship learning, based on matching feature expectations, and showed that the learner's performance can match the expert's on the reward family. Brian Ziebart and colleagues (2008) introduced the maximum-entropy formulation, which gave a principled, probabilistic answer to the ambiguity problem and made it practical to fit to real trajectory data, including driver route choices.
The field then moved in two directions. One kept the reward as the goal and improved the inner solvers. The other, led by Jonathan Ho and Stefano Ermon (2016), showed that the reward need not be recovered explicitly. Their method trains a discriminator (a classifier) to tell expert trajectories from learner trajectories, using a generative adversarial setup, and uses the discriminator's output as a learning signal. That approach, GAIL, is now a standard tool.
Recap
Reinforcement learning maps a reward to a good policy. IRL maps a good policy back to a reward. Because many rewards explain the same behaviour, the method needs a tie-breaker, usually a maximum-entropy model that matches feature counts. Its gradient is the gap between expert and learner feature counts, so each update is a feature-matching step. The recovered reward can train a new policy that generalises beyond the demonstrations, at a cost in compute. The natural next step is to see how the matching idea is turned into an adversarial game in GAIL.
Check yourself
QuestionWhy can the zero reward always be used to explain an expert's behaviour in IRL, and what does that tell you about the problem?Show answer
Under the zero reward every action has the same return, so every policy is optimal, including the expert. Therefore the demonstrations are consistent with it. This shows IRL is ill-posed without extra assumptions: the data identifies a set of rewards, not a single one. Probabilistic models such as maximum entropy, or margin constraints, pick a specific member of that set.
QuestionIn the two-route example, the commuter takes route 1 on 75 percent of days and the model is . What is ? Give two decimal places.Show answer
Set . Then , so and . Therefore .
QuestionIn maximum-entropy IRL, the gradient is the expert's average feature count minus the model's expected feature count. Explain what happens when the two are equal.Show answer
The gradient is zero, so the update stops. At that point the model's expected features match the demonstrations, which is the condition the maximum-likelihood fit requires. The learned reward reproduces the expert's average feature usage, although other rewards might also do so.
QuestionA team has 50 demonstrations, a simulator, and needs a policy that works when the robot is pushed into states the demonstrations never covered. Would you pick behaviour cloning or IRL, and why?Show answer
IRL is the better fit. Behaviour cloning has no guidance in states the demonstrations did not visit, while an inferred reward can be optimised in new states. The simulator makes the inner MDP solves feasible. The main risk is that the 50 demonstrations must cover enough feature variety to pin the reward down, so the team should check that.
QuestionWhy does IRL need an inner solve of the MDP at every update, and what does that cost compared with behaviour cloning?Show answer
The expected feature counts under the current reward depend on the policy that the reward induces, so the learner must solve the MDP for each candidate reward. Behaviour cloning is a single supervised fit with no inner loop, so it is much cheaper, but it lacks the generalisation that a recovered reward gives.
Sources
- Inverse reinforcement learning (Wikipedia)
- Sutton, R. S. and Barto, A. G. (2018). Reinforcement Learning: An Introduction, 2nd ed. book
- Ho, J. and Ermon, S. (2016). Generative Adversarial Imitation Learning. arXiv