Apprenticeship Learning & Feature Matching
Matching an expert’s feature expectations, with and without a game.
Abbeel and Ng's insight was that an apprentice does not need the expert's reward, only a policy that is as good as the expert's under every reward the expert might have. This lesson proves that guarantee, builds the max-margin and projection algorithms and proves how fast they stop and how many demonstrations they need, then recasts the problem as a zero-sum game whose solution can beat the expert, solved by multiplicative weights (MWAL) or by a single linear program (LPAL).
What you’ll learn
- Prove that matching feature expectations within guarantees value within for every reward with , and explain why mixtures of policies are needed.
- Describe the max-margin and projection algorithms, and prove the projection step's geometric progress and the resulting iteration bound.
- Derive how many demonstrations suffice to estimate the expert's feature expectations, by Hoeffding's inequality and a union bound.
- Formulate apprenticeship learning as a zero-sum game, explain why its value lets the apprentice beat the expert, and prove MWAL's guarantee from the multiplicative-weights regret bound.
The guarantee, and why mixtures appear
Why mixtures? The deterministic stationary policies have finitely many feature-expectation vectors, and the expert's may lie between them, in their convex hull but at none of its corners. Mixing reaches any point of the hull, and by Carathéodory's theorem a point of a convex hull in is a convex combination of at most corners, so at most policies are ever needed. The price is that a mixture is not stationary: it commits to one policy for the whole episode. LPAL, at the end of this lesson, removes it.
Max-margin and projection
Both of Abbeel and Ng's algorithms alternate an inverse step and a forward step:
- Start from any policy and compute .
- Inverse step. Find the reward direction in which the expert still beats every policy found so far by the largest margin,
with maximizer : a quadratic program, in effect a support-vector machine separating from the earlier points.
- If , stop: some mixture of the policies found is within of the expert.
- Forward step. Solve the MDP with reward , giving and , and repeat.
The projection variant replaces the quadratic program by one line of geometry. It keeps a single point of the convex hull, sets and , and after each forward step moves to the orthogonal projection of onto the line through and the new point.
import numpy as np
def projection_apprenticeship(mu_E, solve_rl, feature_expectations, eps=1e-2, max_iter=100):
"""mu_E: (k,) expert feature expectations; solve_rl(w): an optimal policy for the
reward w . phi(s); feature_expectations(pi): (k,) vector mu(pi)."""
policies = [solve_rl(np.random.randn(len(mu_E)))] # any first policy
mus = [feature_expectations(policies[0])]
mu_bar = mus[0]
for _ in range(max_iter):
w = mu_E - mu_bar # direction in which the expert still wins
if np.linalg.norm(w) <= eps:
break
policies.append(solve_rl(w)) # forward step: the RL subroutine
mus.append(feature_expectations(policies[-1]))
d = mus[-1] - mu_bar # project mu_E onto the line through mu_bar
mu_bar = mu_bar + (d @ (mu_E - mu_bar)) / (d @ d) * d
return policies, mus, mu_barThe projection algorithm. Each projection lands on the segment between and the new point (shown below), so stays a convex combination of the ; recording the coefficients of each step gives the final mixture weights, or one small quadratic program finds the closest point of the hull at the end.
With , the forward step returns the policy that maximizes . Why is guaranteed?
- Because the expert's own policy is one of the policies the maximization ranges over
- Because has unit norm
- Because the features are nonnegative
- Because the forward step uses the expert's demonstrations
Show the answer
A. Because the expert's own policy is one of the policies the maximization ranges over
The RL step maximizes over all policies, and the expert's is one of them, so the maximum is at least the expert's value in direction . This single inequality drives the convergence proof: each new point lies at least as far along as the expert, so the hull keeps reaching toward . (With an estimated that is not exactly achievable, the proof works with a small ball around it instead.)
Why it stops: geometry and sample size
Put the origin at the current point , and write , so that the current distance is , and for the new point. The forward step maximized and the expert's policy is feasible, so
The projection of onto the line through and is . Expand and use , that is :
By the first step, . All feature expectations lie in the cube , whose diameter is , and is increasing, so
While , each iteration multiplies the distance by at most , and the first distance is at most . Since for , the distance is below after this many iterations:
The new point lies between and , so stays in the hull: , and by Cauchy–Schwarz , so the coefficient is in . The max-margin version moves to the closest point of the whole hull, which is no farther than , so the same bound holds for it.
(Abbeel and Ng's written proof bounds the norms by in one step and uses the diameter in another; with the diameter throughout, the argument gives the rate stated.) The demonstrations enter only through . Each coordinate of averages independent numbers in , so Hoeffding's inequality and a union bound over the coordinates give , hence , with probability at least . Requiring this to be at least gives the theorem's ; running the algorithm to accuracy against then gives against .
Take features, (values range over an interval of length 10), accuracy and confidence . How many demonstrations does the bound require?
Show the answer
4060
and , so , that is, 4,061 demonstrations. The bound is loose, but it shows the shape: linear in the number of features, quadratic in the effective horizon through the scale of the feature sums, and only logarithmic in .
A game: MWAL can beat the expert
Syed and Schapire (2007) changed the reward class: features in and weights in the simplex, . Each feature is now known to be good, more of it is better, and only the trade-off between features is unknown. Apprenticeship becomes a two-player zero-sum game between the apprentice, who picks a mixed policy , and an adversary, who picks the weights:
The expert's own policy scores 0 against every , so . If some policy has strictly larger feature expectations than the expert in every coordinate, then , and that policy is better than the expert under every admissible reward.
Rescale the payoff to . With features in , each lies in , so
Best response: maximizes the payoff against . The game is linear in and in over convex sets, so by the minimax theorem its value satisfies
The adversary's multiplicative weights, with losses for the features, has average regret against the best single feature (Freund & Schapire):
Chain the two, and use that is affine and : every feature satisfies . Undo the rescaling and average over any , in particular :
Making takes rounds, logarithmic in where the projection algorithm needs , and the guarantee is one-sided: at least the expert's value plus , with no ceiling. The price is the assumption that every feature's sign is known. With a wrongly signed feature, "beating the expert" on that feature means doing worse.
Key takeaways
- Values are linear in feature expectations, so gives for all ; matching may require mixing up to policies.
- The max-margin and projection algorithms alternate an inverse step, the direction in which the expert still wins, with an RL step that pushes as far as possible in that direction.
- Because the expert is feasible, each projection step shrinks the distance to by a factor of at least with , giving iterations; Hoeffding's inequality and a union bound show that demonstrations suffice.
- With nonnegative weights apprenticeship is a zero-sum game with value . MWAL, multiplicative weights against best-response RL, guarantees after rounds and can beat the expert; LPAL solves the game as one linear program over occupancy measures and returns a stationary policy.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Why do Abbeel and Ng's algorithms return a mixture of policies rather than one stationary policy?
- Because mixtures have higher entropy, which the guarantee requires
- Because the expert itself is a mixture of policies
- Because the expert's feature expectations may lie strictly inside the convex hull of those of the policies found, and only a mixture reaches such points; at most policies are needed
- Because a stationary policy cannot be optimal for a linear reward
Show the answer
C. Because the expert's feature expectations may lie strictly inside the convex hull of those of the policies found, and only a mixture reaches such points; at most policies are needed
Feature expectations of mixtures are convex combinations, so mixing fills in the convex hull of the found points, and Carathéodory's theorem caps the number of components at . LPAL later shows how to get a stationary policy in the tabular case.
While the distance exceeds , each projection step multiplies it by at most , with . How does the resulting number of iterations scale?
- As : a fixed contraction factor gives linear convergence
- As
- As , one iteration per feature
- As , independently of
Show the answer
B. As
The factor is not fixed: it is , so shrinking from to takes about steps, and .
When can MWAL's apprentice do strictly better than the expert under every admissible reward?
- Whenever enough demonstrations are available
- Never: an apprentice can at best match the expert
- Whenever the expert is suboptimal for the true reward
- When the reward weights are known to be nonnegative and some policy has larger feature expectations than the expert in every coordinate, so that the game value is positive
Show the answer
D. When the reward weights are known to be nonnegative and some policy has larger feature expectations than the expert in every coordinate, so that the game value is positive
With , a policy that beats the expert on every feature beats it under every admissible reward, by at least . MWAL's guarantee then puts the apprentice ahead. The projection algorithm, which only matches feature expectations, has no such upside.
What does LPAL change relative to MWAL?
- It solves the same game exactly, as one linear program over occupancy measures, and its solution is a single stationary policy
- It replaces the linear reward class by neural networks
- It needs no model of the dynamics
- It matches feature expectations in Euclidean norm, like the projection algorithm
Show the answer
A. It solves the same game exactly, as one linear program over occupancy measures, and its solution is a single stationary policy
Optimizing over occupancy measures turns the max–min over mixed policies and simplex weights into a linear program with one constraint per feature. Because occupancy measures correspond one-to-one to stationary policies, the solution needs no mixing.
Further reading
- P. Abbeel & A. Y. Ng, "Apprenticeship learning via inverse reinforcement learning," ICML (2004).
- U. Syed & R. E. Schapire, "A game-theoretic approach to apprenticeship learning," Advances in Neural Information Processing Systems 20 (2007).
- U. Syed, M. Bowling & R. E. Schapire, "Apprenticeship learning using linear programming," ICML (2008).
- J. Ho & S. Ermon, "Generative adversarial imitation learning," NeurIPS (2016).