Search

Search papers and lessons

Trust Region Policy Optimization

John Schulman, Sergey Levine, Philipp Moritz et al. · 2015

Schulman et al. (2015) prove that a surrogate objective guarantees improvement, then make it practical with a hard KL limit per update, so policy updates improve steadily on robotics and Atari tasks.

On this page

  • Colour = topic mix
  • Linear algebra
  • Probability
  • Discrete math
  • Reinforcement learning
  • Calculus
  • Inference
  • ReadReady to readNot yet

TL;DR

Schulman and colleagues (2015) prove that a particular surrogate objective never decreases the true expected return when a policy is updated, provided the update is small enough in a measure of distance between policies. They then turn that proof into a practical algorithm, TRPO, which limits each update by an average KL divergence and solves the resulting problem with conjugate gradient and a line search. The method learned walking, swimming and hopping controllers from scratch, and it played Atari games from raw pixels with little per-task tuning.

Builds on: Policy Gradient, Advantage Function, Kullback–Leibler Divergence · Leads to: Trust Region Policy Optimization (TRPO), Proximal Policy Optimization (PPO)

Why it mattered

Robot and game controllers. TRPO was one of the first policy-search methods to learn gaits for simulated swimmers, hoppers and walkers with general neural network policies and simple rewards. Earlier locomotion work relied on hand-built controllers that encoded balance and stepping.

Training large policies. The paper's policy for Atari had about 33,500 parameters, trained from images. Gradient-free methods such as the cross-entropy method scale poorly with the number of parameters, so a gradient method with stable steps was needed.

The base of later methods. Proximal policy optimization, published in 2017 by the same first author, replaces the hard KL constraint with a simpler clipped objective. Later policy-gradient methods that limit how far each update moves build on the same trust-region idea.

The problem

Policy gradient methods estimate how the expected return changes when the policy parameters change, then take a step uphill. A step that is too large can break the estimate. The gradient is only accurate near the current policy, so a step that looks good on the sampled data can move the policy into a region where the data no longer says anything, and performance can collapse.

Choosing the step size by hand is fragile. The paper frames the question differently: what is the largest update that is guaranteed to help? A trust region is the set of policies close enough to the current one that the model of the return can be trusted. Its size is set by a limit on how far the action probabilities may change. To answer the question, the authors need a surrogate objective, a function of the new policy that matches the true return to first order at the current policy, plus a penalty that accounts for how far the policy has moved.

How it works

The method is a loop with a fixed structure. The theory and the practice are linked by a sequence of approximations that the paper states explicitly.

  1. Collect trajectories with the current policy, and estimate the advantage of each state-action pair.
  2. Form the surrogate objective. It measures how much a new policy would improve the expected return, using samples from the old policy and an importance weight (Importance Sampling).
  3. Form the constraint. It limits the average KL divergence between the old and new action distributions over the visited states.
  4. Solve the constrained problem approximately. Compute the search direction with conjugate gradient, using only products with the Fisher matrix, then take the largest step along it that keeps the constraint and improves the surrogate, found by a line search.
  5. Set the new parameters and repeat.
flowchart LR
  A["Sample trajectories with the current policy"] --> B["Estimate advantages"]
  B --> C["Surrogate objective: expected gain under the new policy"]
  B --> D["Average KL between old and new policy"]
  C --> E["Conjugate gradient for the direction"]
  D --> E
  E --> F["Line search keeps KL under delta and improves the surrogate"]
  F --> A

Now trace one update on a single state with two actions, to see the surrogate and the constraint at work. The old policy chooses the two actions with probabilities (0.5,0.5)(0.5, 0.5). Their advantages are +1+1 and −1-1, so the first action is better than average.

  1. The old surrogate is ∑aπold(a) A(a)=0.5×1+0.5×(−1)=0\sum_a \pi_{\text{old}}(a)\,A(a) = 0.5 \times 1 + 0.5 \times (-1) = 0. Check: the old policy gains nothing over itself, as it should.
  2. Try a new policy (0.6,0.4)(0.6, 0.4). The surrogate is 0.6×1+0.4×(−1)=0.20.6 \times 1 + 0.4 \times (-1) = 0.2, which is an improvement. Its KL divergence from the old policy is 0.5ln⁡(0.5/0.6)+0.5ln⁡(0.5/0.4)≈0.0200.5\ln(0.5/0.6) + 0.5\ln(0.5/0.4) \approx 0.020.
  3. With a constraint δ=0.01\delta = 0.01, this step is infeasible, because 0.0200.020 is larger than 0.010.01. Check: the constraint is an upper bound, and the step is too far.
  4. Try a smaller move, (0.57,0.43)(0.57, 0.43). The surrogate is 0.57−0.43=0.140.57 - 0.43 = 0.14. The KL is 0.5ln⁡(0.5/0.57)+0.5ln⁡(0.5/0.43)≈0.00990.5\ln(0.5/0.57) + 0.5\ln(0.5/0.43) \approx 0.0099, just below 0.010.01. Check: the step is feasible and still gives a real gain.
  5. Interpret. The line search in TRPO does this shrinking automatically. It keeps the largest step that satisfies the constraint and still improves the surrogate, so the update uses as much of the trust region as the data allows.

The math

Let πθ(a∣s)\pi_\theta(a \mid s) be a stochastic policy with parameters θ\theta, and let η(π)\eta(\pi) be its expected discounted reward, defined over a Markov Decision Process with discount γ\gamma. The advantage Aπ(s,a)=Qπ(s,a)−Vπ(s)A_\pi(s,a) = Q_\pi(s,a) - V_\pi(s) measures how much better action aa is than the policy's average at state ss.

Definition: Surrogate objective

For the old policy π\pi and a candidate policy π~\tilde\pi, the local approximation is Lπ(π~)=η(π)+∑sρπ(s)∑aπ~(a∣s)Aπ(s,a)L_\pi(\tilde\pi) = \eta(\pi) + \sum_s \rho_\pi(s) \sum_a \tilde\pi(a \mid s) A_\pi(s,a), where ρπ(s)\rho_\pi(s) is the discounted visitation frequency of states under π\pi. It matches η\eta to first order at π\pi.

Step 1 in symbols: the exact improvement identity

For any two policies,

η(π~)=η(π)+∑sρπ~(s)∑aπ~(a∣s) Aπ(s,a).\eta(\tilde\pi) = \eta(\pi) + \sum_s \rho_{\tilde\pi}(s) \sum_a \tilde\pi(a \mid s)\, A_\pi(s,a).

The improvement is a weighted sum of advantages, with weights from the new policy's visitation. This is exact, but the visitation ρπ~\rho_{\tilde\pi} depends on the new policy, so the identity is hard to optimise directly.

Step 2 in symbols: the approximation and the bound

The surrogate replaces ρπ~\rho_{\tilde\pi} by ρπ\rho_\pi. Its gap from the truth is controlled by the largest distance between the two policies. The paper's Theorem 1 gives

η(π~)≥Lπ(π~)−4ϵγ(1−γ)2 α2,α=DTVmax⁡(π,π~),ϵ=max⁡s,a∣Aπ(s,a)∣.\eta(\tilde\pi) \ge L_\pi(\tilde\pi) - \frac{4\epsilon\gamma}{(1-\gamma)^2}\,\alpha^2, \qquad \alpha = D_{\mathrm{TV}}^{\max}(\pi, \tilde\pi), \quad \epsilon = \max_{s,a}|A_\pi(s,a)|.

Here DTV(p,q)=12∑a∣p(a)−q(a)∣D_{\mathrm{TV}}(p, q) = \tfrac12 \sum_a |p(a) - q(a)| is the total variation distance between two action distributions, and DTVmax⁡D_{\mathrm{TV}}^{\max} takes the worst case over states. Using the inequality DTV2≤DKLD_{\mathrm{TV}}^2 \le D_{\mathrm{KL}}, the bound becomes η(π~)≥Lπ(π~)−C DKLmax⁡(π,π~)\eta(\tilde\pi) \ge L_\pi(\tilde\pi) - C\, D_{\mathrm{KL}}^{\max}(\pi, \tilde\pi) with C=4ϵγ/(1−γ)2C = 4\epsilon\gamma/(1-\gamma)^2.

Step 3 in symbols: the monotonic algorithm

Maximising the right-hand side at each iteration gives a sequence with η(π0)≤η(π1)≤⋯\eta(\pi_0) \le \eta(\pi_1) \le \cdots. The paper calls this a minorisation-maximisation procedure: each step maximises a simple lower bound on the true return, which touches the true return at the current policy. The penalty coefficient CC from the theory is large, which forces tiny steps, so the practical algorithm replaces the penalty with a hard constraint.

Step 4 in symbols: the trust region problem

The practical problem is

max⁡θ  Lθold(θ)subject toD‾KLρθold(θold,θ)≤δ,\max_\theta \; L_{\theta_{\text{old}}}(\theta) \quad \text{subject to} \quad \overline{D}_{\mathrm{KL}}^{\rho_{\theta_{\text{old}}}}(\theta_{\text{old}}, \theta) \le \delta,

where D‾KL\overline{D}_{\mathrm{KL}} is the average KL over visited states. The paper argues that the maximum KL constraint at every state is impractical, so it uses the average.

Step 5 in symbols: sample estimates

The surrogate is estimated with importance sampling from trajectories of the old policy. For a state sns_n and actions sampled from q=πoldq = \pi_{\text{old}},

L(θ)≈1N∑nπθ(an∣sn)πold(an∣sn) A^(sn,an).L(\theta) \approx \frac{1}{N} \sum_n \frac{\pi_\theta(a_n \mid s_n)}{\pi_{\text{old}}(a_n \mid s_n)}\, \hat A(s_n, a_n).

The paper's single-path method uses sampled trajectories, and its vine method branches from a set of states.

Step 6 in symbols: the approximate solve

Write gg for the gradient of the surrogate and FF for the Fisher information matrix, the Hessian of the average KL at θold\theta_{\text{old}}. The search direction is s≈F−1gs \approx F^{-1} g, found by conjugate gradient, which needs only products FvFv. The step size β\beta is the largest value that keeps 12β2s⊤Fs≤δ\tfrac12 \beta^2 s^\top F s \le \delta, followed by a line search that checks the surrogate actually improved.

Results

Locomotion. On three simulated robots (a swimmer, a hopper and a walker), the paper reports that both single-path TRPO and vine TRPO learned to move, and that a natural gradient method with a fixed penalty did worse on the harder hopper and walker tasks. The paper reads this as evidence that a KL constraint is a more robust way to choose step sizes than a fixed penalty.

Constraint versus penalty. The authors also compare with a maximum-KL constraint on the cart-pole problem. It learned more slowly than the average-KL version, but it confirmed that the average is a reasonable approximation.

Atari from pixels. On several Atari games, TRPO used a convolutional network and raw screens as input. Table 1 of the paper compares its scores with human players and earlier methods. TRPO was competitive on some games and clearly behind on others, so the table should be read game by game rather than as a single win. Check the table itself for the exact scores and run counts.

Limits. The paper shows the approach on simulated robots and on Atari. It does not address real robots, partial observability, or recurrent policies, and it names them as future work. The vine method needs the simulator to reset to arbitrary states, which a real system often cannot do. The constraint is an average over visited states, so the paper's guarantee is an approximation to the bound, not the bound itself. The theory assumes exact advantages, so errors in estimating them are not covered by the guarantee.

Reading guide

Check yourself

QuestionRecall: what does the surrogate objective Lπ(π~)L_\pi(\tilde\pi) approximate, and at which policy is the approximation exact?Show answer

It approximates the true expected return η(π~)\eta(\tilde\pi) by replacing the new policy's state visitation with the old policy's. It matches η\eta exactly at π~=π\tilde\pi = \pi, and to first order in the parameters near it, so small steps that improve the surrogate also improve the return.

QuestionComputation: a state has two actions with advantages +2+2 and −2-2. The old policy is (0.5,0.5)(0.5, 0.5) and the new policy is (0.6,0.4)(0.6, 0.4). What is the surrogate value, and how does it compare with the value 0 at the old policy?Show answer

The surrogate is 0.6×2+0.4×(−2)=1.2−0.8=0.40.6 \times 2 + 0.4 \times (-2) = 1.2 - 0.8 = 0.4. At the old policy it is 0.5×2+0.5×(−2)=00.5 \times 2 + 0.5 \times (-2) = 0. The new policy gains 0.40.4 on the surrogate, so the surrogate says the step is an improvement.

QuestionWhy: explain why the paper uses a hard KL constraint rather than the theoretical penalty with its large coefficient.Show answer

The theory's penalty coefficient C=4ϵγ/(1−γ)2C = 4\epsilon\gamma/(1-\gamma)^2 is large, because ϵ\epsilon is a worst-case advantage and γ\gamma is near 1. A penalty that large forces very small steps, so learning would be slow. A hard constraint on the average KL lets the step use the whole trust region, and the authors found that it made steadier progress than a fixed penalty.

QuestionApplied: you apply TRPO to a robot, and the vine method is not allowed, because the robot cannot be reset to arbitrary states. What is left, and what does the paper say about its cost?Show answer

Use the single-path method, which needs only trajectories sampled by the policy itself and no resets to arbitrary states. The vine method's better use of each sample depends on those resets, so without them, expect the single-path estimate to need more data for the same progress.

Sources

Read the full paper

John Schulman, Sergey Levine, Philipp Moritz et al., 2015. arXiv:1502.05477