VerifiedarXiv:1502.0547729 min
Reinforcement learning · Policy optimization

TRPO: Trust Region Policy Optimization

Limit how far each update can move the policy's action probabilities, measured in KL divergence, and take the largest improving step within that limit.

A policy-gradient step that is too large can wreck a policy that was working. TRPO derives a lower bound on the new policy's return, turns it into a KL budget per update, and solves for the step with conjugate gradient and a line search.

Explaining the paperTrust Region Policy OptimizationSchulman, Levine, Moritz, Jordan, Abbeel · UC Berkeley · ICML 2015 · arXiv:1502.05477 ↗

The gradient of expected return gives a direction for changing the policy but no distance. One KL budget, δ = 0.01 per update, worked unchanged on simulated swimming, hopping and walking and on seven Atari games played from raw pixels.

Policy-gradient reinforcement learning fails in a recognizable way. You run the current policy, collect a batch of experience, estimate which direction in parameter space increases reward, and take a step. Most steps help. Occasionally one produces a policy far worse than the one you started with: a walking robot that now falls immediately, or a game agent that puts all its probability on one action and stops exploring. The next batch is collected by that broken policy, so it contains little useful signal, and recovery can take thousands of updates. Lowering the learning rate makes collapses rarer and learning slower, and the right rate changes from task to task and during training.

The objective optimized from a batch is an approximation to expected return, built from states the old policy visited. It agrees with the true return near the old policy and drifts away from it as the policy moves. TRPO (Schulman, Levine, Moritz, Jordan and Abbeel, 2015) quantifies the drift. The page follows the paper in order:

A two-state problem small enough to solve by hand runs through the first half, so each equation can be checked with numbers.

The step-size problem in policy gradients

The agent lives in a Markov decision process. At each state ss it samples an action aa from a stochastic policy π(a∣s)\pi(a\mid s); for a neural policy, a network reads ss and outputs the parameters of a distribution over actions. The environment then moves to a new state. In this paper the reward depends only on the state, r(s)r(s). The quantity to maximize is the expected discounted return, which weights a reward tt steps in the future by γt\gamma^t for a discount γ\gamma between 0 and 1:

η(π)=Es0,a0,…[∑t=0∞γt r(st)],s0∼ρ0, at∼π(⋅∣st), st+1∼P(⋅∣st,at)\eta(\pi) = \mathbb{E}_{s_0, a_0, \dots}\Big[\textstyle\sum_{t=0}^{\infty} \gamma^t\, r(s_t)\Big], \qquad s_0\sim\rho_0,\ a_t\sim\pi(\cdot\mid s_t),\ s_{t+1}\sim P(\cdot\mid s_t,a_t)η(π)=Es0,a0,…[∑t=0∞γt r(st)],s0∼ρ0, at∼π(⋅∣st), st+1∼P(⋅∣st,at)\begin{gathered}\eta(\pi) = \mathbb{E}_{s_0, a_0, \dots}\Big[\textstyle\sum_{t=0}^{\infty} \gamma^t\, r(s_t)\Big], \\ s_0\sim\rho_0,\ a_t\sim\pi(\cdot\mid s_t),\ s_{t+1}\sim P(\cdot\mid s_t,a_t)\end{gathered}

Three standard quantities make η\eta workable. The value Vπ(s)V_\pi(s) is the expected discounted return starting from ss and following π\pi. The action value Qπ(s,a)Q_\pi(s,a) is the same quantity when the first action is fixed to aa. The advantage is their difference:

Aπ(s,a)=Qπ(s,a)−Vπ(s)A_\pi(s,a) = Q_\pi(s,a) - V_\pi(s)

A positive advantage means action aa at state ss does better than the policy's average behavior there; a negative one means worse. Averaged over the policy's own action probabilities, the advantage is exactly zero, because Vπ(s)V_\pi(s) is that average of Qπ(s,⋅)Q_\pi(s,\cdot); the surrogate section uses this.

The running example has two states. In SS the reward is 0 and the agent chooses between go, which moves it to GG, and stay, which keeps it in SS. In GG the reward is 1 on every step and every action keeps it in GG. The discount is γ=0.9\gamma = 0.9, the episode starts in SS, and the policy has one number, p=π(go∣S)p = \pi(\text{go}\mid S). Being in GG is worth 1+0.9+0.81+…1 + 0.9 + 0.81 + \dots, so V(G)=10V(G) = 10. Solving the one-line Bellman equation for SS gives

η(p)=V(S)=0.9 p V(G)1−0.9(1−p)=9p0.1+0.9p\eta(p) = V(S) = \frac{0.9\,p\,V(G)}{1 - 0.9(1-p)} = \frac{9p}{0.1 + 0.9p}

At p=0.5p = 0.5 the return is V(S)=4.5/0.55=8.18V(S) = 4.5/0.55 = 8.18. Going gives Q(S,go)=0.9⋅10=9Q(S,\text{go}) = 0.9 \cdot 10 = 9; staying gives Q(S,stay)=0.9⋅8.18=7.36Q(S,\text{stay}) = 0.9 \cdot 8.18 = 7.36. So A(S,go)=+0.82A(S,\text{go}) = +0.82 and A(S,stay)=−0.82A(S,\text{stay}) = -0.82, and their policy-weighted average is 0.5(0.82)+0.5(−0.82)=00.5(0.82) + 0.5(-0.82) = 0. In GG every action has advantage 0, since the action changes nothing.

Let ρπ(s)=∑tγtP(st=s)\rho_\pi(s) = \sum_t \gamma^t P(s_t = s) be the discounted number of visits to state ss. The paper leaves it unnormalized: it sums to 1/(1−γ)1/(1-\gamma) over states, not to 1. In the example at p=0.5p = 0.5, the agent is still in SS at time tt with probability 0.5t0.5^t, so ρ(S)\rho(S) is the geometric sum of 0.45t0.45^t, which is 1/0.55=1.821/0.55 = 1.82, and ρ(G)=8.18\rho(G) = 8.18. The two sum to 10=1/(1−0.9)10 = 1/(1-0.9). That factor of 1/(1−γ)1/(1-\gamma) comes back as a constant in the sampling section.

The exact improvement identity

The derivation starts from an identity due to Kakade and Langford (2002). The return of any policy π~\tilde\pi equals the return of π\pi plus the discounted sum of π\pi's advantages, collected along trajectories generated by π~\tilde\pi:

η(π~)=η(π)+Eτ∼π~[∑t=0∞γtAπ(st,at)]\eta(\tilde\pi) = \eta(\pi) + \mathbb{E}_{\tau \sim \tilde\pi}\Big[\textstyle\sum_{t=0}^{\infty} \gamma^t A_\pi(s_t, a_t)\Big]
(1)

It holds exactly for any two policies. The proof is a telescoping sum. In expectation over the next state, the advantage equals the one-step error r(s)+γVπ(s′)−Vπ(s)r(s) + \gamma V_\pi(s') - V_\pi(s). Add these up along a trajectory with weights γt\gamma^t and each γt+1Vπ(st+1)\gamma^{t+1} V_\pi(s_{t+1}) cancels against the next term's −γt+1Vπ(st+1)-\gamma^{t+1} V_\pi(s_{t+1}). What remains is the trajectory's discounted reward minus Vπ(s0)V_\pi(s_0). Averaged over trajectories of π~\tilde\pi, those two terms are η(π~)\eta(\tilde\pi) and η(π)\eta(\pi), which rearranges to (1).

Grouping the trajectory sum by state, with each state weighted by how often the new policy visits it, gives the form the rest of the paper works with:

η(π~)=η(π)+∑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)
(2)

Check it on the example, with old policy p=0.5p = 0.5 and new policy p~=1\tilde p = 1 (always go). The new policy leaves SS on the first step, so ρπ~(S)=1\rho_{\tilde\pi}(S) = 1. Its expected advantage in SS is 1⋅0.82+0⋅(−0.82)=0.821 \cdot 0.82 + 0 \cdot (-0.82) = 0.82. Equation (2) gives 8.18+1⋅0.82=9.008.18 + 1 \cdot 0.82 = 9.00, and the formula for η(1)\eta(1) gives 9/1=9.009/1 = 9.00. For p~=0\tilde p = 0 (never go), ρπ~(S)=10\rho_{\tilde\pi}(S) = 10, the expected advantage is −0.82-0.82, and (2) gives 8.18−8.18=08.18 - 8.18 = 0, which is right: an agent that never leaves SS collects nothing.

Equation (2) also gives a rule for improving a policy: move probability toward actions with positive advantage. If the expected advantage ∑aπ~(a∣s)Aπ(s,a)\sum_a \tilde\pi(a\mid s)A_\pi(s,a) is nonnegative at every state, the new policy is at least as good. Exact policy iteration, which picks the action with the largest advantage at every state, works for this reason. The obstacle is the weight ρπ~\rho_{\tilde\pi}. It is the new policy's visit count, and you only learn it by running the new policy, which is the thing being designed.

The surrogate objective and why it only works nearby

TRPO replaces the new policy's visit counts with the old policy's. That gives the surrogate objective:

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)
(3)

Every term on the right is available from data the old policy collected: its visited states, and its advantages there. The new policy enters only through its action probabilities at those states. It is like re-scoring an old survey with new weights per answer while assuming the same households would respond; for a small change in policy the households barely change, and for a large one the new policy reaches different states and the assumption fails.

In the example, LL keeps ρ(S)=1.82\rho(S) = 1.82 from the old policy. At p~=1\tilde p = 1 it predicts 8.18+1.82⋅0.82=9.678.18 + 1.82 \cdot 0.82 = 9.67, while the true return is 9.009.00. The surrogate overestimates by 0.67 because it assumes the agent still spends 1.82 discounted steps in SS collecting the advantage of go, when the new policy spends one. At p~=0\tilde p = 0 it predicts 6.69 against a true 0. Comparing (2) with (3), the error at any p~\tilde p is (ρπ~(S)−ρπ(S))(\rho_{\tilde\pi}(S) - \rho_\pi(S)) times the expected advantage in SS: the surrogate's whole error comes from the change in state visits.

Near the old policy the error is small: for a policy πθ\pi_\theta with differentiable parameters, LL matches η\eta to first order at the current parameters θ0\theta_0: same value and same gradient.

Lπθ0(πθ0)=η(πθ0),∇θLπθ0(πθ)∣θ0=∇θη(πθ)∣θ0L_{\pi_{\theta_0}}(\pi_{\theta_0}) = \eta(\pi_{\theta_0}), \qquad \nabla_\theta L_{\pi_{\theta_0}}(\pi_\theta)\big|_{\theta_0} = \nabla_\theta \eta(\pi_\theta)\big|_{\theta_0}Lπθ0(πθ0)=η(πθ0),∇θLπθ0(πθ)∣θ0=∇θη(πθ)∣θ0\begin{gathered}L_{\pi_{\theta_0}}(\pi_{\theta_0}) = \eta(\pi_{\theta_0}), \\ \nabla_\theta L_{\pi_{\theta_0}}(\pi_\theta)\big|_{\theta_0} = \nabla_\theta \eta(\pi_\theta)\big|_{\theta_0}\end{gathered}
(4)

The error term is a product of two factors, the change in visits and the expected advantage under the new policy. Both are zero at θ0\theta_0: the visits have not changed yet, and the expected advantage of a policy under its own advantages is zero (the property from the first section). The product of two terms that each grow linearly with the step grows quadratically, so its first derivative at θ0\theta_0 vanishes. In the example both slopes at p=0.5p = 0.5 are 2.98.

By (4), a small enough step that improves LL also improves η\eta, but (4) gives no bound on how small. The figure plots both functions for the two-state problem. Move the new policy pp and watch the gap between the teal line and the amber curve; then move poldp_{\text{old}} and see the tangent point follow it.

Figure 1 · the surrogate on a problem solved exactly
0.50
1.00
The two-state problem: η(p) is the exact return, L(p) the surrogate built at p_old. They touch at p_old with the same slope; elsewhere the straight line sits above the curve. The readout gives the gap and the discounted visits to S under each policy. At p_old near 0 the old policy almost never leaves S, ρ(S) is close to 10, and L shoots off the top. The button overlays the penalized bound M with the theory's constant C.

In this problem the true return is concave in pp, so the surrogate overestimates every move but never points the wrong way: going more often always helps. In a real task the true return eventually turns down as the policy moves, while the surrogate, which ignores the visits that the move changes, keeps rising. The next three sections bound the gap between them.

Measuring policy change: total variation and KL

A bound on the gap needs a measure of how far the policy moved. Distance between parameter vectors is a poor choice, because two networks with nearly identical weights can output very different action distributions, and two networks with very different weights can output the same ones. TRPO measures the change in the action distribution at each state. The first measure is the total variation distance, half the summed absolute difference in probabilities:

DTV(p ∥ q)=12∑i∣pi−qi∣∈[0,1]D_{\mathrm{TV}}(p\,\|\,q) = \tfrac12 \textstyle\sum_i |p_i - q_i| \in [0,1]

It equals the largest difference in probability the two distributions can assign to any single event. The bound in the next section is stated with it, then converted to the KL divergence DKL(p ∥ q)=∑ipilog⁡(pi/qi)D_{\mathrm{KL}}(p\,\|\,q)=\sum_i p_i \log(p_i/q_i), which is smooth in the policy parameters and has a simple second derivative. The conversion uses an inequality the paper cites from Pollard:

DTV(p ∥ q)2≤DKL(p ∥ q)D_{\mathrm{TV}}(p\,\|\,q)^2 \le D_{\mathrm{KL}}(p\,\|\,q)

A cap on KL therefore caps total variation, and with it how differently the two policies can act at that state. The paper's form is looser than the sharp Pinsker inequality, DTV2≤12DKLD_{\mathrm{TV}}^2 \le \tfrac12 D_{\mathrm{KL}}; the looser one is still valid and only makes the bound more conservative (footnote 4). KL is not symmetric, so the order of arguments is a convention. TRPO puts the old policy first: DKL(πold ∥ πnew)D_{\mathrm{KL}}(\pi_{\mathrm{old}}\,\|\,\pi_{\mathrm{new}}).

For scale, take the example's state SS, where the policy is a coin with p=0.5p = 0.5. Moving to p=0.57p = 0.57 costs DKL=0.010D_{\mathrm{KL}} = 0.010 nats, which is TRPO's budget, and a total variation of 0.07. In the figure, drag a five-action policy away from a fixed old one and check that DTV2D_{\mathrm{TV}}^2 stays below the KL at every setting.

Figure 2 · a distance on policies
shift 0.50
One state, five actions. π_old is fixed; the slider pushes π_new away from it along a fixed direction in logit space. Total variation and KL both grow, and the new bars turn amber once the KL passes the figure's budget δ = 0.10 (chosen for visibility; the paper uses 0.01). The bottom row checks D_TV² ≤ ½·D_KL ≤ D_KL at every setting.

The improvement bound and the monotonic guarantee

Kakade and Langford proved a lower bound on the new return for conservative policy iteration, which only allows mixture updates: with probability 1−α1-\alpha act like the old policy, with probability α\alpha act like a better one. Their bound, as TRPO prints it, is

η(πnew)≥Lπold(πnew)−2ϵγ(1−γ)2 α2,ϵ=max⁡s∣Ea∼π′Aπ(s,a)∣\eta(\pi_{\text{new}}) \ge L_{\pi_{\text{old}}}(\pi_{\text{new}}) - \frac{2\epsilon\gamma}{(1-\gamma)^2}\,\alpha^2, \qquad \epsilon = \max_s \big|\mathbb{E}_{a\sim\pi'}A_\pi(s,a)\big|η(πnew)≥Lπold(πnew)−2ϵγ(1−γ)2 α2,ϵ=max⁡s∣Ea∼π′Aπ(s,a)∣\begin{gathered}\eta(\pi_{\text{new}}) \ge L_{\pi_{\text{old}}}(\pi_{\text{new}}) - \frac{2\epsilon\gamma}{(1-\gamma)^2}\,\alpha^2, \\ \epsilon = \max_s \big|\mathbb{E}_{a\sim\pi'}A_\pi(s,a)\big|\end{gathered}

where π′\pi' is the better policy being mixed in, so ϵ\epsilon is the largest expected advantage of π′\pi' at any state. Mixture policies are rarely used in practice. TRPO's main theoretical result (Theorem 1) extends the bound to any pair of stochastic policies, with α\alpha replaced by the largest total variation between them over states. Converting total variation to KL with the inequality above gives:

η(π~)≥Lπ(π~)−C DKLmax⁡(π,π~),C=4 ϵ γ(1−γ)2,ϵ=max⁡s,a∣Aπ(s,a)∣\eta(\tilde\pi) \ge L_\pi(\tilde\pi) - C\, D_{\mathrm{KL}}^{\max}(\pi, \tilde\pi), \qquad C = \frac{4\,\epsilon\,\gamma}{(1-\gamma)^2}, \quad \epsilon = \max_{s,a}|A_\pi(s,a)|η(π~)≥Lπ(π~)−C DKLmax⁡(π,π~),C=4 ϵ γ(1−γ)2,ϵ=max⁡s,a∣Aπ(s,a)∣\begin{gathered}\eta(\tilde\pi) \ge L_\pi(\tilde\pi) - C\, D_{\mathrm{KL}}^{\max}(\pi, \tilde\pi), \\ C = \frac{4\,\epsilon\,\gamma}{(1-\gamma)^2}, \quad \epsilon = \max_{s,a}|A_\pi(s,a)|\end{gathered}
(5)

In (5), DKLmax⁡D_{\mathrm{KL}}^{\max} is the KL between the two action distributions at the state where it is largest. Two constants changed from the mixture bound. The coefficient went from 2 to 4, and the extra factor of 2 comes from the coupling argument in the proof, not from the step from total variation to KL. The proof bounds the new policy's expected advantage at each state, Ea~∼π~[Aπ(s,a~)]\mathbb{E}_{\tilde a\sim\tilde\pi}[A_\pi(s,\tilde a)]. The old policy's expected advantage is zero, so this equals E[Aπ(s,a~)−Aπ(s,a)]\mathbb{E}[A_\pi(s,\tilde a) - A_\pi(s,a)], with a~\tilde a drawn from the new policy and aa from the old. Run both policies with shared randomness so that they pick the same action as often as possible. Two distributions at total variation α\alpha can be coupled to agree with probability 1−α1-\alpha. When the two actions agree, the difference Aπ(s,a~)−Aπ(s,a)A_\pi(s,\tilde a) - A_\pi(s,a) is zero. When they disagree, each advantage can be as large as ϵ\epsilon in magnitude, so the difference can reach 2ϵ2\epsilon. The new policy's expected advantage per state is then at most 2αϵ2\alpha\epsilon in magnitude.

ϵ\epsilon was also redefined. In the mixture bound it is the worst state's expected advantage; in (5) it is the largest single ∣Aπ(s,a)∣|A_\pi(s,a)| anywhere, which is at least as large.

Call the right side of (5), built at the current policy πi\pi_i, the function MiM_i:

Mi(π)=Lπi(π)−C DKLmax⁡(πi,π)M_i(\pi) = L_{\pi_i}(\pi) - C\, D_{\mathrm{KL}}^{\max}(\pi_i, \pi)

It lies below η\eta everywhere and equals it at πi\pi_i, where the KL is zero and L=ηL = \eta. A function with those two properties is called a minorizer. The paper's Algorithm 1 sets πi+1\pi_{i+1} to the maximizer of MiM_i and repeats. Then

η(πi+1)−η(πi) ≥ Mi(πi+1)−Mi(πi) ≥ 0\eta(\pi_{i+1}) - \eta(\pi_i) \ \ge\ M_i(\pi_{i+1}) - M_i(\pi_i) \ \ge\ 0
(6)

The first inequality uses η(πi+1)≥Mi(πi+1)\eta(\pi_{i+1}) \ge M_i(\pi_{i+1}) and η(πi)=Mi(πi)\eta(\pi_i) = M_i(\pi_i). The second holds because πi+1\pi_{i+1} maximizes MiM_i, so it scores at least as well as πi\pi_i. The return never decreases. This is a minorize-maximize (MM) algorithm, the family that includes expectation maximization: build a function that touches the objective at the current point and lies below it elsewhere, move to that function's maximum, rebuild there. Picture a tarp stretched under a hilltop in fog, pinned to the ground at your feet and lying below it everywhere else, so any point on the tarp you walk to has ground at least that high above it.

The figure runs Algorithm 1 on a one-dimensional hill, with a quadratic KL penalty of strength CC. Here MiM_i is a lower bound exactly when C≥1C \ge 1, the steepest downward curvature of the hill. Press Play at the default C=2C = 2 and watch the iterates reach the top in about 20 steps. Then try C=40C = 40: still safe, but each step is 1/C1/C of the gradient, and after 20 iterations the return has gone from 0.21 to 0.25 out of a possible 3. Below C=1C = 1 the bound pokes above the curve (shaded) and the guarantee is gone; below about 0.5 the steps overshoot the peak and the bar strip shows drops.

Figure 3 · minorize, maximize, repeat
iter 0/20
C = 2.00
η is the true return over one policy parameter. At the current iterate θ_i, the violet parabola is M_i: the surrogate's tangent line minus C times the KL. Its peak (ring) is θ_(i+1); the teal dot directly above it is the true return there. The violet shading marks where M_i is above η, so it is not a lower bound. The bars give η after each step; amber bars are decreases.

The guarantee in (6) is a theorem about Algorithm 1 as written: exact advantages, an exact maximization over all policies, the theoretical CC, and the maximum KL over states. The algorithm the paper runs replaces all four with approximations, and the paper's own abstract says that despite them TRPO "tends to" give monotonic improvement. The theorem motivates the design; it does not certify any particular update of the practical algorithm.

From a penalty to a trust region

Maximizing L−C DKLmax⁡L - C\,D_{\mathrm{KL}}^{\max} directly would keep the guarantee, but the theoretical CC is enormous. At γ=0.99\gamma = 0.99 the denominator (1−γ)2(1-\gamma)^2 is 10−410^{-4}, so

C=4⋅0.99 ϵ10−4=39,600 ϵ≈4×104 ϵC = \frac{4 \cdot 0.99\,\epsilon}{10^{-4}} = 39{,}600\,\epsilon \approx 4 \times 10^4\,\epsilon

which is about 40,000 times the largest advantage. The paper says that with this CC "the step sizes would be very small."

The two-state problem shows how small, even at γ=0.9\gamma = 0.9. There ϵ=0.82\epsilon = 0.82, and CC is 4⋅0.82⋅0.9/0.014 \cdot 0.82 \cdot 0.9 / 0.01, or 295. The maximizer of MM moves the policy from p=0.5p = 0.5 to p=0.5025p = 0.5025, a true gain of 0.0075 (Figure 1 shows it with the bound button on). The best policy, p=1p = 1, is worth 0.82 more.

A smaller CC is the obvious fix, and Figure 3 shows the problem with it: the useful value depends on the curvature of the return, which differs between tasks and changes during training. The paper reports that a penalty coefficient is hard to choose robustly, and switches to a hard constraint on the KL, a trust region of radius δ\delta. TRPO takes the step that maximizes the surrogate among all steps whose KL stays within δ\delta:

max⁡θ  Lθold(θ)subject toDˉKL ρθold(θold,θ)≤δ\max_{\theta}\; L_{\theta_{\mathrm{old}}}(\theta) \quad\text{subject to}\quad \bar{D}_{\mathrm{KL}}^{\,\rho_{\theta_{\mathrm{old}}}}(\theta_{\mathrm{old}}, \theta) \le \deltamax⁡θ  Lθold(θ)subject to  DˉKL ρθold(θold,θ)≤δ\begin{aligned}&\max_{\theta}\; L_{\theta_{\mathrm{old}}}(\theta) \\ &\text{subject to}\ \ \bar{D}_{\mathrm{KL}}^{\,\rho_{\theta_{\mathrm{old}}}}(\theta_{\mathrm{old}}, \theta) \le \delta\end{aligned}
(7)

With a penalty, the step length depends on CC, on the size of the surrogate's gradient, and on the curvature of the KL; with a constraint, the step goes as far as the KL limit δ\delta allows. The constraint is stated in KL per update, the quantity the bound penalizes, so one value of δ\delta can serve problems whose rewards and curvatures differ.

Equation (7) has one more change from the theory. The bound uses the maximum KL over all states, which is one constraint per state. TRPO constrains the average KL over states visited by the old policy, DˉKL\bar{D}_{\mathrm{KL}}, and calls it a heuristic approximation. On cart-pole, the one task where the maximum-KL version was tractable, it learned somewhat more slowly and otherwise behaved similarly. Every experiment in the paper uses δ=0.01\delta = 0.01. In the example, that budget moves pp from 0.5 to 0.570 in one update and gains 0.188 (the surrogate predicted 0.209): 28 times the step and 25 times the gain of the penalized step.

The constraint does not make every δ\delta safe. The figure is a stylized slice through policy space: η\eta rises and falls, LL is its tangent line, and the trust region admits moves up to a KL of δ\delta (in the figure's own units). TRPO takes the largest step inside the region. Widen δ\delta past about 1.6 and that step lands past the dotted marker, where the true return is below the starting point while the surrogate still predicts a gain.

Figure 4 · when the trust region is too large
δ = 0.40
Moving the policy a distance θ from the old one. η is the true return; L is the surrogate, tangent to η at the start. The shaded band is the trust region, the moves whose KL stays within δ, and TRPO steps to its edge. A small δ gives a small safe gain; a large δ overshoots the peak and, past the dotted marker, ends below the start. The violet curve is a minorizer M = L − C·KL with an illustrative C.

Estimating the objective from rollouts

Problem (7) is written with sums over all states and actions and the true advantage function. The paper makes three substitutions to estimate it from samples. The sum over states weighted by ρθold\rho_{\theta_{\mathrm{old}}} becomes an expectation over sampled states, times the constant 1/(1−γ)1/(1-\gamma) from the unnormalized visit counts, which does not change the maximizer. The advantage AA becomes QQ; the difference is Vθold(s)V_{\theta_{\mathrm{old}}}(s) times ∑aπθ(a∣s)=1\sum_a \pi_\theta(a\mid s) = 1, which does not depend on θ\theta, so the objective shifts by a constant. The sum over actions becomes an importance-sampling estimate: sample actions from a distribution qq and weight each by πθ/q\pi_\theta/q. Together they turn (7) into the problem TRPO solves:

max⁡θ  Es∼ρθold, a∼q ⁣[πθ(a∣s)q(a∣s) Qθold(s,a)]  s.t.  Es∼ρθold ⁣[DKL(πθold ∥ πθ)]≤δ\max_{\theta}\; \mathbb{E}_{s\sim\rho_{\theta_{\mathrm{old}}},\ a\sim q}\!\Big[\frac{\pi_\theta(a\mid s)}{q(a\mid s)}\, Q_{\theta_{\mathrm{old}}}(s,a)\Big] \ \ \text{s.t.}\ \ \mathbb{E}_{s\sim\rho_{\theta_{\mathrm{old}}}}\!\big[D_{\mathrm{KL}}(\pi_{\theta_{\mathrm{old}}}\,\|\,\pi_\theta)\big] \le \deltamax⁡θ  Es∼ρθold, a∼q ⁣[πθ(a∣s)q(a∣s) Qθold(s,a)]s.t.  Es∼ρθold ⁣[DKL(πθold ∥ πθ)]≤δ\begin{aligned}&\max_{\theta}\; \mathbb{E}_{s\sim\rho_{\theta_{\mathrm{old}}},\ a\sim q}\!\Big[\frac{\pi_\theta(a\mid s)}{q(a\mid s)}\, Q_{\theta_{\mathrm{old}}}(s,a)\Big] \\ &\text{s.t.}\ \ \mathbb{E}_{s\sim\rho_{\theta_{\mathrm{old}}}}\!\big[D_{\mathrm{KL}}(\pi_{\theta_{\mathrm{old}}}\,\|\,\pi_\theta)\big] \le \delta\end{aligned}
(8)

The importance-sampling identity is exact for every θ\theta, but its variance grows as πθ\pi_\theta moves away from qq. If the old policy gave an action probability 0.1 and the new one gives it 0.4, each sample of that action counts four times. Keeping the KL small keeps these weights near 1, which is a second reason, separate from the bound, to limit the step.

The paper gives two ways to produce the samples and the QQ estimates. Single path is ordinary policy-gradient sampling. Run the old policy for whole trajectories, so q=πθoldq = \pi_{\theta_{\mathrm{old}}}. Every state-action pair on a trajectory is a sample, and its QQ estimate is the discounted sum of the rewards that followed it on the same trajectory. It needs no resets and can run on a physical robot. Each estimate is a single noisy return. The paper's estimator uses it as QQ directly; common implementations, and the code sketch below, subtract a learned value baseline, which shifts the objective by a constant per state and reduces variance.

Vine spends more simulation to get cleaner estimates. Run trunk trajectories, choose a subset of their states (the rollout set), and from each chosen state run KK short rollouts, one per sampled action; the experiments use about 4 per state. All KK rollouts reuse the same random number sequence for the environment's noise (common random numbers), so differences between their returns come mostly from the different first actions. With several actions per state, the paper uses a self-normalized estimator, dividing the weighted sum of Q^\hat Q values by the sum of the weights, which removes the need for a baseline. On the continuous-control tasks qq is the old policy; on Atari it is uniform over actions, which sometimes explored better. The cost is many more simulator calls per advantage estimate and the ability to reset the simulator to an arbitrary state, so vine runs only in simulation. Toggle between the two schemes:

Figure 5 · single path vs vine
simulator-only
Single path scores every state on a trajectory and reads its Q off the rest of the same path: cheap, no resets, works on real hardware, one noisy sample per state. Vine branches K rollouts from each state in a rollout set with shared random numbers: lower-variance advantages, many more simulator calls, and resets to arbitrary states.

How TRPO computes the step: natural gradient, conjugate gradient, line search

Problem (8) has to be solved approximately at every update, for policies with up to 33,500 parameters in the paper. TRPO approximates the objective by its gradient gg (linear in the step) and the average KL by its second-order Taylor expansion around θold\theta_{\mathrm{old}}, where the KL and its gradient are both zero:

DˉKL(θold,θ)≈12(θ−θold)⊤F (θ−θold)\bar{D}_{\mathrm{KL}}(\theta_{\mathrm{old}}, \theta) \approx \tfrac12 (\theta - \theta_{\mathrm{old}})^\top F\, (\theta - \theta_{\mathrm{old}})

The matrix FF is the Hessian of the average KL, the Fisher information matrix (the paper writes it AA, which collides with the advantage; this page uses FF). TRPO computes it analytically: the KL between two distributions of known form is differentiated in closed form, which integrates over all actions at each sampled state. The alternative, the covariance of sampled log-probability gradients, depends on which actions happened to be sampled; the paper tests it as the "empirical FIM" baseline and reports a similar rate of improvement.

Maximizing g⊤Δθg^\top \Delta\theta subject to 12Δθ⊤FΔθ≤δ\tfrac12 \Delta\theta^\top F \Delta\theta \le \delta gives a step along F−1gF^{-1} g. This direction is the natural gradient (Amari), applied to policies by Kakade as the natural policy gradient. It is the gradient re-measured in KL units. Along a direction where a small parameter change moves the action distribution a lot, FF is large and the step is short; along a direction the outputs are insensitive to, the step is long. A plain gradient step, the same problem with 12∥Δθ∥2≤δ\tfrac12\|\Delta\theta\|^2 \le \delta, moves the same Euclidean distance in every direction. In the figure, increase the anisotropy and compare the gray plain step with the teal KL step.

Figure 6 · why KL, not parameter distance
2.40×
Parameter space, old policy at the center. The gradient ∇L points uphill on the surrogate. The gray dashed circle is a Euclidean ball and the gray arrow the plain gradient step to its edge. The teal ellipse is the KL trust region, shaped by the Fisher matrix, and the teal arrow is TRPO's step. At anisotropy 1 the two coincide.

Forming FF is out of the question at this size. For the 33,500-parameter Atari policy it has 33,5002≈1.1×10933{,}500^2 \approx 1.1 \times 10^9 entries, 4.5 GB in 32-bit floats, before any inversion. TRPO never forms it. Conjugate gradient solves Fs=gF s = g using only products FvF v for vectors vv of its choosing, and each Fisher-vector product costs about as much as one gradient. Appendix C writes the product as J⊤MJvJ^\top M J v, where JJ is the Jacobian of the network's distribution parameters and MM the Fisher matrix of the output distribution with respect to those parameters; a generic Hessian-vector product through the KL, as in the code below, is slightly slower and easier to write. Ten iterations were enough (more did not speed learning). With 10 products per step, a naive implementation would spend over 90% of its compute on them, so the paper computes them on 10% of the batch. FF serves only as a metric, and the subsample leaves the direction's cost at about one extra gradient.

def conjugate_gradient(Fvp, g, iters=10):
    x = zeros_like(g)        # running solution of F x = g
    r = g.copy()             # residual g - F x
    p = g.copy()             # current search direction
    for _ in range(iters):
        Fp = Fvp(p)                      # the only access to F
        a  = (r @ r) / (p @ Fp)
        x  = x + a * p
        r_new = r - a * Fp
        p  = r_new + ((r_new @ r_new) / (r @ r)) * p
        r  = r_new
    return x

Conjugate gradient returns a direction s≈F−1gs \approx F^{-1} g. For the length, under the quadratic model a step βs\beta s costs KL 12β2s⊤Fs\tfrac12\beta^2 s^\top F s; setting that to δ\delta gives the largest allowed β\beta:

s≈F−1g,β=2δs⊤F s,θnew=θold+β s  (then backtrack)s \approx F^{-1} g, \qquad \beta = \sqrt{\frac{2\delta}{s^\top F\, s}}, \qquad \theta_{\mathrm{new}} = \theta_{\mathrm{old}} + \beta\, s\ \ (\text{then backtrack})s≈F−1g,β=2δs⊤F s,θnew=θold+β s  (then backtrack)\begin{gathered}s \approx F^{-1} g, \qquad \beta = \sqrt{\frac{2\delta}{s^\top F\, s}}, \\ \theta_{\mathrm{new}} = \theta_{\mathrm{old}} + \beta\, s\ \ (\text{then backtrack})\end{gathered}
(9)

Both approximations can be wrong at that length: the true KL can exceed δ\delta, and the true surrogate can fall. TRPO therefore runs a backtracking line search on the actual functions. Starting from β\beta, it shrinks the step exponentially until the surrogate improves and the average KL is at most δ\delta. The paper reports that without the line search the algorithm "occasionally computes large steps that cause a catastrophic degradation of performance." It does not give the shrink factor; the figure halves.

Figure 7 · the backtracking line search
k = 1.20
b = 0.60
Step length along the natural-gradient direction, from 0 to just past β. Top: KL, with the quadratic model (dashed) reaching δ exactly at β and the true KL (white). Bottom: surrogate gain, with the linear model (dashed) and the true gain (white). Tries at β, β/2, β/4, …; crosses fail the KL limit or lose surrogate value, the dot is the first try that passes both.

At the defaults the true KL at β\beta is 2.2δ2.2\delta, so the full step is rejected and the search accepts β/2\beta/2. Set the KL nonlinearity below 0 and the model step passes on the first try; raise the surrogate curvature above 1 and the full step loses surrogate value even when its KL is fine.

TRPO differs from the natural policy gradient in this step-length computation. Both use the direction F−1gF^{-1}g. The natural policy gradient takes

θnew=θold+1λF−1g\theta_{\mathrm{new}} = \theta_{\mathrm{old}} + \tfrac{1}{\lambda} F^{-1} g

with a fixed step size 1/λ1/\lambda chosen as a hyperparameter. TRPO recomputes the length every update so that the constraint holds, and the paper's experiments credit this difference with a large improvement on the harder tasks. The same template also covers ordinary policy gradient (replace the KL constraint with 12∥θ−θold∥2≤δ\tfrac12\|\theta-\theta_{\mathrm{old}}\|^2 \le \delta) and policy iteration (drop the constraint and maximize LL).

The policies themselves are small. For continuous control, a Gaussian whose mean comes from a fully connected network (hidden-layer size 30 for the swimmer, 50 for the hopper and walker) and whose diagonal covariance is a separate, state-independent vector of log standard deviations. For Atari, two convolutional layers with 16 channels and stride 2 and a 20-unit fully connected layer, 33,500 parameters. One iteration end to end:

# one TRPO iteration, single path, reward maximization
batch = collect_trajectories(pi_old)       # states, actions, rewards
Qhat  = discounted_returns(batch)          # Monte-Carlo Q along each path
Ahat  = Qhat - value_baseline(batch.s)     # advantage estimates
g     = grad_surrogate(pi, batch, Ahat)    # gradient of L at theta_old

def fisher_vector_product(v):              # F v without ever forming F
    sub = subsample(batch.s, frac=0.1)     # F is only a metric: 10% suffices
    kl  = mean_kl(pi_old, pi, sub)         # analytic KL, averaged over states
    return grad(grad(kl, theta) @ v, theta)  # Hessian-vector product

s    = conjugate_gradient(fisher_vector_product, g, iters=10)   # s ~= F^-1 g
beta = sqrt(2 * delta / (s @ fisher_vector_product(s)))       # delta = 0.01
step = beta * s

# backtrack until the TRUE surrogate improves and the TRUE mean KL <= delta.
# the paper says "shrink exponentially"; halving is this sketch's choice.
for _ in range(max_backtracks):
    theta_new = theta_old + step
    if improved(theta_new) and mean_kl_at(theta_new) <= delta:
        break
    step *= 0.5

Results: simulated locomotion and Atari

The locomotion tasks ran in the MuJoCo simulator: a swimmer (10-dimensional state, 364 policy parameters), a hopper (12-dimensional state, 4,806 parameters) and a walker (8,206 parameters; footnote 5 covers its state size), with rewards for forward progress and small penalties on effort. The hopper used one million simulation steps per iteration for 200 iterations. Both TRPO variants learned swimming, hopping and walking gaits with general-purpose networks, from scratch. The comparisons isolate the design choices:

The learning curves average five runs per method. The paper reads them as evidence that constraining the KL is a more robust way to choose step sizes than a fixed penalty.

The Atari experiment tests generality. The same recipe, a convolutional policy trained from raw pixels with δ=0.01\delta = 0.01 and γ=0.99\gamma = 0.99, ran once on each of the seven games from the DQN paper. 500 iterations took about 30 hours on a 16-core machine. TRPO reached reasonable scores on all seven and beat deep Q-learning on four: single path on Enduro (534.6 vs 470), Seaquest (1,908.6 vs 1,705) and narrowly Q*bert (1,973.5 vs 1,952); vine on Q*bert by about four times (7,732.5); both variants on Pong (20.9 vs 20.0). It trailed deep Q-learning on Beam Rider, Breakout and Space Invaders, and the tree-search method UCC-I scored higher than both TRPO variants on all seven games. It was not state of the art, and the paper does not claim it was: unlike the comparison methods, it was not designed for Atari.

Figure 8 · Atari, one recipe, run once
Q*bert
Table 1 of the paper, verbatim. TRPO's two variants in teal against a random policy, an expert human, deep Q-learning, and the tree-search method UCC-I. Slide through the seven games. Pong scores are a margin in [−21, 21], hence the zero line.

The trust-region update became a template. Proximal Policy Optimization (2017), by the same first author, keeps the bounded update and drops the expensive parts: no hard KL constraint, no conjugate gradient, no line search. It clips the probability ratio πθ/πθold\pi_\theta/\pi_{\theta_{\mathrm{old}}} in the surrogate and optimizes with ordinary stochastic-gradient epochs over minibatches. Deep RL from Human Preferences (2017) trained its simulated-robotics policies with TRPO and its Atari policies with A2C.

Provenance Verified against primary literatureHow we verify
Kakade & Langford (2002)The improvement identity (1), conservative policy iteration over mixture policies, and the lower bound that Theorem 1 generalizes.
Kakade (2002)The natural policy gradient: the F⁻¹g search direction (the paper writes the Fisher matrix as A) with a fixed step size.
Amari (1998)Natural gradient and the Fisher-information metric on distributions.
Pollard, AsymptopiaThe D_TV² ≤ D_KL inequality used to pass from Theorem 1 to the KL bound (5); looser than Pinsker’s D_TV² ≤ ½·D_KL.
Hunter & Lange (2004)Minorize-maximize algorithms, the class Algorithm 1 belongs to.
Owen (2013), ch. 9The self-normalized importance-sampling estimator used by vine (paper Eq. 16).
Wright & Nocedal (1999)Trust-region methods, conjugate gradient with matrix-vector products, and Hessian-vector products by automatic differentiation (App. C).
This pageThe two-state example is constructed for this explainer, not taken from the paper; every number is computed exactly from η(p) = 9p/(0.1 + 0.9p).
correctionThe paper's abstract opens with an iterative procedure 'with guaranteed monotonic improvement', and popular summaries repeat that TRPO never makes the policy worse. The guarantee is a theorem about the idealized Algorithm 1: exact advantages, exact maximization over all policies, the theoretical penalty C, and the maximum KL over states. Practical TRPO replaces each of these (sampled estimates, a linear-objective/quadratic-KL step, a hard constraint δ instead of the penalty, the average KL), which voids the proof; the same abstract says it only 'tends to give monotonic improvement'. This page teaches the guarantee as the motivation for the design, not as a property of each update.

Questions you might still have

?

Does TRPO guarantee that the policy never gets worse?
No. The proof covers the idealized Algorithm 1, with exact advantages, an exact maximization over all policies, the theoretical penalty C, and the maximum KL over states. Practical TRPO uses sampled estimates, a linear/quadratic approximation to find the step, a hard KL limit instead of the penalty, and the average KL instead of the maximum. Each change voids the proof. The paper says the practical algorithm "tends to" improve monotonically.

?

Why limit the KL divergence instead of the size of the parameter step?
Equal parameter distance does not mean equal change in behavior. Along a sensitive direction a tiny weight change moves the action probabilities a lot; along a flat direction a large weight change barely moves them. KL measures the change in the action distributions directly, so a fixed KL budget allows long steps along insensitive directions and short ones along sensitive directions. A fixed Euclidean step, which is what plain gradient ascent takes, overshoots along the sensitive directions.

?

Why not just use the penalty with a smaller constant C?
The theory fixes C = 4εγ/(1−γ)², about 40,000 times the largest advantage at γ = 0.99, and that gives tiny steps. Any smaller C has to be tuned, and the right value depends on the curvature of the return, which differs between tasks and changes during training. The paper found a fixed penalty hard to choose robustly, while a KL limit of δ = 0.01 worked unchanged on every task it tried.

?

What does δ = 0.01 mean in terms of action probabilities?
It is an average KL of 0.01 nats per state. For a two-action state where the old policy picks each action with probability 0.5, the limit allows moving to about 0.57/0.43. With more actions, or a Gaussian over continuous actions, the same budget is shared across the probabilities, and the line search adjusts the step so the measured average KL stays within it.

?

How expensive is a TRPO update compared with a plain policy-gradient step?
Not much more. The direction needs about 10 conjugate-gradient iterations, each one Fisher-vector product costing about one gradient; computing those products on 10% of the batch brings the total to roughly one extra gradient. The line search then evaluates the surrogate and KL a few times, which needs forward passes only. The expensive part of TRPO is usually collecting the samples.

?

What is the difference between TRPO and PPO?
PPO keeps the goal of a bounded update and drops the constrained solve. Instead of a hard KL limit enforced with conjugate gradient and a line search, it clips the probability ratio between new and old policy inside the surrogate, and optimizes that with several epochs of ordinary minibatch SGD on each batch. There is no Fisher matrix and no second-order computation. The Proximal Policy Optimization explainer covers it.

?

Single path or vine: which should I use?
Single path when you cannot reset the system to an arbitrary state, which includes real hardware: it needs only ordinary trajectories. Vine when a simulator can be reset and you can afford many more simulator calls in exchange for lower-variance advantage estimates. In the paper both variants solved the locomotion tasks, and on Atari each beat the other on some games.

?

Why does the surrogate overestimate the true return?
It keeps the old policy’s state-visit counts. A policy that changes where the agent spends its time changes those counts, and the surrogate ignores the change; its error equals the change in visits times the new policy’s expected advantage. In the two-state example on this page, always going is predicted to score 9.67 and actually scores 9.00, because the new policy spends one discounted step in the start state instead of 1.82. The KL penalty in the bound is the price for that frozen-visits approximation.

Footnotes & further reading

  1. The paper: Schulman, Levine, Moritz, Jordan, Abbeel, Trust Region Policy Optimization (UC Berkeley, ICML 2015). OpenAI's Spinning Up has an implementation-oriented write-up. It writes the KL constraint with the new policy first, the reverse of the paper's old-first order; the two agree to second order, so they have the same Fisher matrix and the same natural-gradient step.
  2. The identity, conservative policy iteration and the bound TRPO extends: Kakade and Langford, Approximately Optimal Approximate Reinforcement Learning (ICML 2002).
  3. The natural gradient direction: Kakade, A Natural Policy Gradient (NeurIPS 2001), building on Amari's Natural Gradient Works Efficiently in Learning (1998).
  4. The inequality DTV2≤DKLD_{\mathrm{TV}}^2 \le D_{\mathrm{KL}} is the form the paper cites from Pollard's Asymptopia; the paper never calls it Pinsker's inequality. The sharp Pinsker inequality, with the convention DTV=12∑∣p−q∣D_{\mathrm{TV}}=\tfrac12\sum|p-q|, is DTV2≤12DKLD_{\mathrm{TV}}^2 \le \tfrac12 D_{\mathrm{KL}}. Using it would halve the penalty CC. Both are valid; the looser one only makes the bound more conservative.
  5. An inconsistency to know if you reproduce the experiments: the walker's state dimension is 18 in the main text and 20 in the appendix table, with 8,206 policy parameters either way. Every experiment uses δ=0.01\delta = 0.01 and γ=0.99\gamma = 0.99.
  6. The successor that replaced the constraint with a clipped ratio: Schulman et al., Proximal Policy Optimization Algorithms (2017). TRPO was also one of the two reinforcement-learning algorithms behind Deep RL from Human Preferences, which noted that TRPO's trust region alone can under-explore when the reward being optimized keeps changing.