Simple Algorithm
Reinforcement Learning · Fixed Point · 26 min

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 ϵ\epsilon guarantees value within ϵ\epsilon for every reward with ∥w∥2≤1\norm{\mathbf w}_2\le1, 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 v⋆≥0v^\star\ge0 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 μE\boldsymbol\mu_E may lie between them, in their convex hull M\mathcal M 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 Rk\R^k is a convex combination of at most k+1k+1 corners, so at most k+1k+1 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:

  1. Start from any policy π(0)\pi^{(0)} and compute μ(0)\boldsymbol\mu^{(0)}.
  2. Inverse step. Find the reward direction in which the expert still beats every policy found so far by the largest margin,
t(i)=max⁡∥w∥2≤1 min⁡j<i w⊤(μE−μ(j)),t^{(i)} = \max_{\norm{\mathbf w}_2\le1}\ \min_{j<i}\ \mathbf w^\top\big(\boldsymbol\mu_E - \boldsymbol\mu^{(j)}\big),

with maximizer w(i)\mathbf w^{(i)}: a quadratic program, in effect a support-vector machine separating μE\boldsymbol\mu_E from the earlier points.

  1. If t(i)≤ϵt^{(i)}\le\epsilon, stop: some mixture of the policies found is within ϵ\epsilon of the expert.
  2. Forward step. Solve the MDP with reward w(i)⊤ϕ\mathbf w^{(i)\top}\boldsymbol\phi, giving π(i)\pi^{(i)} and μ(i)\boldsymbol\mu^{(i)}, and repeat.

The projection variant replaces the quadratic program by one line of geometry. It keeps a single point μˉ\bar{\boldsymbol\mu} of the convex hull, sets w=μE−μˉ\mathbf w = \boldsymbol\mu_E - \bar{\boldsymbol\mu} and t=∥w∥2t = \norm{\mathbf w}_2, and after each forward step moves μˉ\bar{\boldsymbol\mu} to the orthogonal projection of μE\boldsymbol\mu_E onto the line through μˉ\bar{\boldsymbol\mu} and the new point.

python
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_bar

The projection algorithm. Each projection lands on the segment between μˉ\bar{\boldsymbol\mu} and the new point (shown below), so μˉ\bar{\boldsymbol\mu} stays a convex combination of the μ(i)\boldsymbol\mu^{(i)}; 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.

Check your understanding

With w=μE−μˉ\mathbf w = \boldsymbol\mu_E - \bar{\boldsymbol\mu}, the forward step returns the policy π\pi that maximizes w⊤μ(π)\mathbf w^\top\boldsymbol\mu(\pi). Why is w⊤μ(π)≥w⊤μE\mathbf w^\top\boldsymbol\mu(\pi)\ge\mathbf w^\top\boldsymbol\mu_E guaranteed?

  1. Because the expert's own policy is one of the policies the maximization ranges over
  2. Because w\mathbf w has unit norm
  3. Because the features are nonnegative
  4. 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 w\mathbf w. This single inequality drives the convergence proof: each new point lies at least as far along w\mathbf w as the expert, so the hull keeps reaching toward μE\boldsymbol\mu_E. (With an estimated μ^E\hat{\boldsymbol\mu}_E that is not exactly achievable, the proof works with a small ball around it instead.)

Why it stops: geometry and sample size

DerivationProof of progress (projection version)
  1. x⊤y ≥ x⊤x\mathbf x^\top\mathbf y\ \ge\ \mathbf x^\top\mathbf x

    Put the origin at the current point μˉ\bar{\boldsymbol\mu}, and write x=μE−μˉ\mathbf x = \boldsymbol\mu_E - \bar{\boldsymbol\mu}, so that the current distance is t=∥x∥t = \norm{\mathbf x}, and y=μnew−μˉ\mathbf y = \boldsymbol\mu^{\text{new}} - \bar{\boldsymbol\mu} for the new point. The forward step maximized x⊤μ(π)\mathbf x^\top\boldsymbol\mu(\pi) and the expert's policy is feasible, so

  2. ∥x−z∥2=∥x∥2−(x⊤y)2∥y∥2 ≤ ∥x∥2 ∥y−x∥2∥y∥2\norm{\mathbf x - \mathbf z}^2 = \norm{\mathbf x}^2 - \frac{(\mathbf x^\top\mathbf y)^2}{\norm{\mathbf y}^2}\ \le\ \frac{\norm{\mathbf x}^2\,\norm{\mathbf y - \mathbf x}^2}{\norm{\mathbf y}^2}

    The projection of x\mathbf x onto the line through 0\mathbf 0 and y\mathbf y is z=x⊤yy⊤y y\mathbf z = \frac{\mathbf x^\top\mathbf y}{\mathbf y^\top\mathbf y}\,\mathbf y. Expand ∥x−z∥2\norm{\mathbf x - \mathbf z}^2 and use (x⊤y−x⊤x)2≥0(\mathbf x^\top\mathbf y - \mathbf x^\top\mathbf x)^2\ge0, that is (x⊤y)2≥2(x⊤y)∥x∥2−∥x∥4(\mathbf x^\top\mathbf y)^2\ge2(\mathbf x^\top\mathbf y)\norm{\mathbf x}^2 - \norm{\mathbf x}^4:

  3. ∥x−z∥2∥x∥2 ≤ ∥y−x∥2∥y−x∥2+t2 ≤ D2D2+t2\frac{\norm{\mathbf x - \mathbf z}^2}{\norm{\mathbf x}^2}\ \le\ \frac{\norm{\mathbf y - \mathbf x}^2}{\norm{\mathbf y - \mathbf x}^2 + t^2}\ \le\ \frac{D^2}{D^2 + t^2}

    By the first step, ∥y∥2=∥y−x∥2+∥x∥2+2(y−x)⊤x≥∥y−x∥2+∥x∥2\norm{\mathbf y}^2 = \norm{\mathbf y - \mathbf x}^2 + \norm{\mathbf x}^2 + 2(\mathbf y - \mathbf x)^\top\mathbf x\ge\norm{\mathbf y - \mathbf x}^2 + \norm{\mathbf x}^2. All feature expectations lie in the cube [0,11−γ]k[0,\frac{1}{1-\gamma}]^k, whose diameter is D=k/(1−γ)D = \sqrt k/(1-\gamma), and u↦u/(u+c)u\mapsto u/(u+c) is increasing, so

  4. ⌈4 D2ϵ2log⁡Dϵ⌉=⌈4k(1−γ)2ϵ2log⁡k(1−γ)ϵ⌉=O(k(1−γ)2ϵ2log⁡k(1−γ)ϵ)\Big\lceil 4\,\frac{D^2}{\epsilon^2}\log\frac{D}{\epsilon}\Big\rceil = \Big\lceil\frac{4k}{(1-\gamma)^2\epsilon^2}\log\frac{\sqrt k}{(1-\gamma)\epsilon}\Big\rceil = \order{\frac{k}{(1-\gamma)^2\epsilon^2}\log\frac{k}{(1-\gamma)\epsilon}}

    While t>ϵt > \epsilon, each iteration multiplies the distance by at most (1+ϵ2/D2)−1/2(1 + \epsilon^2/D^2)^{-1/2}, and the first distance is at most DD. Since log⁡(1+u)≥u/2\log(1+u)\ge u/2 for u≤1u\le1, the distance is below ϵ\epsilon after this many iterations:

  5. The new point z\mathbf z lies between 0\mathbf 0 and y\mathbf y, so μˉ\bar{\boldsymbol\mu} stays in the hull: x⊤y≥∥x∥2≥0\mathbf x^\top\mathbf y\ge\norm{\mathbf x}^2\ge0, and by Cauchy–Schwarz (x⊤y)2≤∥x∥2∥y∥2≤(x⊤y)∥y∥2(\mathbf x^\top\mathbf y)^2\le\norm{\mathbf x}^2\norm{\mathbf y}^2\le(\mathbf x^\top\mathbf y)\norm{\mathbf y}^2, so the coefficient x⊤y/∥y∥2\mathbf x^\top\mathbf y/\norm{\mathbf y}^2 is in [0,1][0,1]. The max-margin version moves to the closest point of the whole hull, which is no farther than z\mathbf z, so the same bound holds for it. ■\blacksquare

(Abbeel and Ng's written proof bounds the norms by k/(1−γ)k/(1-\gamma) in one step and uses the diameter k/(1−γ)\sqrt k/(1-\gamma) in another; with the diameter throughout, the argument gives the rate stated.) The demonstrations enter only through μ^E\hat{\boldsymbol\mu}_E. Each coordinate of (1−γ)μ^E(1-\gamma)\hat{\boldsymbol\mu}_E averages mm independent numbers in [0,1][0,1], so Hoeffding's inequality and a union bound over the kk coordinates give ∥μ^E−μE∥∞≤ϵ/(2k)\norm{\hat{\boldsymbol\mu}_E - \boldsymbol\mu_E}_\infty\le\epsilon/(2\sqrt k), hence ∥μ^E−μE∥2≤ϵ/2\norm{\hat{\boldsymbol\mu}_E - \boldsymbol\mu_E}_2\le\epsilon/2, with probability at least 1−2k e−m(1−γ)2ϵ2/(2k)1 - 2k\,e^{-m(1-\gamma)^2\epsilon^2/(2k)}. Requiring this to be at least 1−δ1-\delta gives the theorem's mm; running the algorithm to accuracy ϵ/2\epsilon/2 against μ^E\hat{\boldsymbol\mu}_E then gives ϵ\epsilon against μE\boldsymbol\mu_E.

Predict before you look

Take k=4k = 4 features, γ=0.9\gamma = 0.9 (values range over an interval of length 10), accuracy ϵ=1\epsilon = 1 and confidence δ=0.05\delta = 0.05. How many demonstrations does the bound m≥2k(ϵ(1−γ))2ln⁡2kδm\ge\frac{2k}{(\epsilon(1-\gamma))^2}\ln\frac{2k}{\delta} require?

Show the answer

4060

2k(ϵ(1−γ))2=80.01=800\frac{2k}{(\epsilon(1-\gamma))^2} = \frac{8}{0.01} = 800 and ln⁡80.05=ln⁡160≈5.075\ln\frac{8}{0.05} = \ln160\approx5.075, so m≥4,060.2m\ge4{,}060.2, 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 1/(1−γ)1/(1-\gamma) through the scale of the feature sums, and only logarithmic in 1/δ1/\delta.

A game: MWAL can beat the expert

Syed and Schapire (2007) changed the reward class: features in [−1,1]k[-1,1]^k and weights in the simplex, w⋆∈Sk={w≥0, ∑iwi=1}\mathbf w^\star\in S_k = \{\mathbf w\ge0,\ \sum_i w_i = 1\}. 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 ψ\psi, and an adversary, who picks the weights:

v⋆=max⁡ψ min⁡w∈Sk w⊤(μ(ψ)−μE).v^\star = \max_\psi\ \min_{\mathbf w\in S_k}\ \mathbf w^\top\big(\boldsymbol\mu(\psi) - \boldsymbol\mu_E\big).

The expert's own policy scores 0 against every w\mathbf w, so v⋆≥0v^\star\ge0. If some policy has strictly larger feature expectations than the expert in every coordinate, then v⋆>0v^\star > 0, and that policy is better than the expert under every admissible reward.

DerivationProof from the multiplicative-weights bound (exact planning, known expert feature expectations)
  1. G(w,μ)=(1−γ) w⊤(μ−μE)+24∈[0,1],G(w,μ)=∑iwi G(ei,μ)G(\mathbf w,\boldsymbol\mu) = \frac{(1-\gamma)\,\mathbf w^\top(\boldsymbol\mu - \boldsymbol\mu_E) + 2}{4}\in[0,1],\qquad G(\mathbf w,\boldsymbol\mu) = \sum_i w_i\,G(\mathbf e_i,\boldsymbol\mu)

    Rescale the payoff to [0,1][0,1]. With features in [−1,1][-1,1], each μi−μE,i\mu_i - \mu_{E,i} lies in [−21−γ,21−γ][-\frac{2}{1-\gamma},\frac{2}{1-\gamma}], so

  2. G(w(t),μ(t))=max⁡ψG(w(t),μ(ψ)) ≥ min⁡wmax⁡ψG(w,μ(ψ))=v~G\big(\mathbf w^{(t)},\boldsymbol\mu^{(t)}\big) = \max_\psi G\big(\mathbf w^{(t)},\boldsymbol\mu(\psi)\big)\ \ge\ \min_{\mathbf w}\max_\psi G\big(\mathbf w,\boldsymbol\mu(\psi)\big) = \tilde v

    Best response: π(t)\pi^{(t)} maximizes the payoff against w(t)\mathbf w^{(t)}. The game is linear in w\mathbf w and in μ(ψ)\boldsymbol\mu(\psi) over convex sets, so by the minimax theorem its value v~=((1−γ)v⋆+2)/4\tilde v = ((1-\gamma)v^\star + 2)/4 satisfies

  3. 1T∑t=1TG(w(t),μ(t)) ≤ min⁡i 1T∑t=1TG(ei,μ(t))+ΔT\frac1T\sum_{t=1}^T G\big(\mathbf w^{(t)},\boldsymbol\mu^{(t)}\big)\ \le\ \min_i\ \frac1T\sum_{t=1}^T G\big(\mathbf e_i,\boldsymbol\mu^{(t)}\big) + \Delta_T

    The adversary's multiplicative weights, with losses G(ei,μ(t))G(\mathbf e_i,\boldsymbol\mu^{(t)}) for the kk features, has average regret ΔT=O(ln⁡k/T)\Delta_T = \order{\sqrt{\ln k/T}} against the best single feature (Freund & Schapire):

  4. V(ψˉ)−V(πE)=w⋆⊤(μ(ψˉ)−μE) ≥ v⋆−4ΔT1−γ■V(\bar\psi) - V(\pi_E) = \mathbf w^{\star\top}\big(\boldsymbol\mu(\bar\psi) - \boldsymbol\mu_E\big)\ \ge\ v^\star - \frac{4\Delta_T}{1-\gamma}\qquad\blacksquare

    Chain the two, and use that G(ei,⋅)G(\mathbf e_i,\cdot) is affine and μ(ψˉ)=1T∑tμ(t)\boldsymbol\mu(\bar\psi) = \frac1T\sum_t\boldsymbol\mu^{(t)}: every feature satisfies G(ei,μ(ψˉ))≥v~−ΔTG(\mathbf e_i,\boldsymbol\mu(\bar\psi))\ge\tilde v - \Delta_T. Undo the rescaling and average over any w∈Sk\mathbf w\in S_k, in particular w⋆\mathbf w^\star:

Making 4ΔT/(1−γ)≤ϵ4\Delta_T/(1-\gamma)\le\epsilon takes T=O(ln⁡k/((1−γ)2ϵ2))T = \order{\ln k/((1-\gamma)^2\epsilon^2)} rounds, logarithmic in kk where the projection algorithm needs klog⁡kk\log k, and the guarantee is one-sided: at least the expert's value plus v⋆v^\star, 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 ∥μ(π~)−μE∥2≤ϵ\norm{\boldsymbol\mu(\tilde\pi) - \boldsymbol\mu_E}_2\le\epsilon gives ∣Jw(π~)−Jw(πE)∣≤ϵ\abs{J_{\mathbf w}(\tilde\pi) - J_{\mathbf w}(\pi_E)}\le\epsilon for all ∥w∥2≤1\norm{\mathbf w}_2\le1; matching may require mixing up to k+1k+1 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 μE\boldsymbol\mu_E by a factor of at least D/D2+ϵ2D/\sqrt{D^2+\epsilon^2} with D=k/(1−γ)D = \sqrt k/(1-\gamma), giving O(k(1−γ)2ϵ2log⁡k(1−γ)ϵ)\order{\frac{k}{(1-\gamma)^2\epsilon^2}\log\frac{k}{(1-\gamma)\epsilon}} iterations; Hoeffding's inequality and a union bound show that 2k(ϵ(1−γ))2ln⁡2kδ\frac{2k}{(\epsilon(1-\gamma))^2}\ln\frac{2k}{\delta} demonstrations suffice.
  • With nonnegative weights apprenticeship is a zero-sum game with value v⋆≥0v^\star\ge0. MWAL, multiplicative weights against best-response RL, guarantees V≥V(πE)+v⋆−ϵV\ge V(\pi_E) + v^\star - \epsilon after O(ln⁡k/((1−γ)2ϵ2))\order{\ln k/((1-\gamma)^2\epsilon^2)} 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.

Question 1

Why do Abbeel and Ng's algorithms return a mixture of policies rather than one stationary policy?

  1. Because mixtures have higher entropy, which the guarantee requires
  2. Because the expert itself is a mixture of policies
  3. 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 k+1k+1 policies are needed
  4. 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 k+1k+1 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 k+1k+1. LPAL later shows how to get a stationary policy in the tabular case.

Question 2

While the distance tt exceeds ϵ\epsilon, each projection step multiplies it by at most D/D2+ϵ2D/\sqrt{D^2+\epsilon^2}, with D=k/(1−γ)D = \sqrt k/(1-\gamma). How does the resulting number of iterations scale?

  1. As log⁡(1/ϵ)\log(1/\epsilon): a fixed contraction factor gives linear convergence
  2. As k(1−γ)2ϵ2log⁡k(1−γ)ϵ\frac{k}{(1-\gamma)^2\epsilon^2}\log\frac{k}{(1-\gamma)\epsilon}
  3. As kk, one iteration per feature
  4. As 1/(1−γ)1/(1-\gamma), independently of ϵ\epsilon
Show the answer

B. As k(1−γ)2ϵ2log⁡k(1−γ)ϵ\frac{k}{(1-\gamma)^2\epsilon^2}\log\frac{k}{(1-\gamma)\epsilon}

The factor is not fixed: it is (1+ϵ2/D2)−1/2≈1−ϵ2/(2D2)(1+\epsilon^2/D^2)^{-1/2}\approx1 - \epsilon^2/(2D^2), so shrinking from DD to ϵ\epsilon takes about (D2/ϵ2)log⁡(D/ϵ)(D^2/\epsilon^2)\log(D/\epsilon) steps, and D2=k/(1−γ)2D^2 = k/(1-\gamma)^2.

Question 3

When can MWAL's apprentice do strictly better than the expert under every admissible reward?

  1. Whenever enough demonstrations are available
  2. Never: an apprentice can at best match the expert
  3. Whenever the expert is suboptimal for the true reward
  4. 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 v⋆v^\star 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 v⋆v^\star is positive

With w≥0\mathbf w\ge0, a policy that beats the expert on every feature beats it under every admissible reward, by at least v⋆v^\star. MWAL's guarantee V(ψˉ)≥V(πE)+v⋆−ϵV(\bar\psi)\ge V(\pi_E) + v^\star - \epsilon then puts the apprentice ahead. The projection algorithm, which only matches feature expectations, has no such upside.

Question 4

What does LPAL change relative to MWAL?

  1. It solves the same game exactly, as one linear program over occupancy measures, and its solution is a single stationary policy
  2. It replaces the linear reward class by neural networks
  3. It needs no model of the dynamics
  4. 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).