Trust-Region Policy Optimization
Imagine training a robot arm with policy gradients. One unlucky update — a slightly too-large step — makes the policy suddenly output torques. This flings the arm off the table. The policy never recovers. The new bad policy generates the very data used to compute the next gradient. This is the central fragility of naive policy gradient methods. There is no built-in limit on how far a single update can move the policy. In reinforcement learning, unlike supervised learning, a bad step corrupts the data-generating process itself. Trust-Region Policy Optimization (TRPO) attacks this problem directly. It asks a precise question: how large a step can we take in policy-parameter space? This must still guarantee that the true expected return does not decrease. The answer comes from a theorem that bounds the gap. This gap is between a cheaply computable surrogate objective and the true objective. It is expressed in terms of a KL-divergence penalty. TRPO turns this theorem into a practical algorithm. It maximizes the surrogate subject to a bound on the average KL-divergence between old and new policies. This is solved approximately each iteration using conjugate gradients and a natural-gradient direction. TRPO matters because it was the first policy-gradient method to combine strong empirical performance with a genuine guarantee. This performance was on high-dimensional continuous-control and Atari benchmarks. The guarantee was a non-heuristic monotonic-improvement guarantee. It made policy optimization reliable enough to train locomotion policies, robotic manipulation, and game-playing agents. This happened without constant divergence and re-tuning. Its core idea — constrain policy updates to a "trust region" in distribution space rather than parameter space — reshaped how the field thinks about step-size control in RL. This article builds the theory from the Policy Parameterization and Objectives and The Advantage Function. It proceeds up through the surrogate objective, the monotonic-improvement bound, and the practical constrained-optimization algorithm. It also covers its complexity and correctness. It closes by tracing the direct line from TRPO to its simplified successor, Proximal Policy Optimization.
- TRPO maximizes a surrogate objective — expected advantage under the new policy but sampled from the old policy — while bounding the KL-divergence between the two.
- A theorem bounds the true performance difference between policies by the surrogate objective minus a term proportional to the maximum KL-divergence, giving a monotonic-improvement guarantee.
- In practice, average KL is bounded (a trust region) instead of max KL, and the constrained problem is solved via a linear approximation of the objective and a quadratic approximation of the constraint.
- The step direction is the natural gradient, computed efficiently with conjugate gradients using Fisher-vector products, avoiding ever forming the full Fisher information matrix.
- A line search on the true constraint and surrogate objective corrects for the approximation error, preserving the improvement guarantee in practice.
- TRPO's ideas — surrogate objective, trust region, natural gradient — directly motivate Proximal Policy Optimization, which approximates the same goal with first-order methods.
TRPO improves a policy by maximizing an easy-to-estimate surrogate objective subject to a constraint that the policy not move too far in distribution — a trust region — which provably bounds how much true performance can drop.
The idea
Let denote a stochastic policy with parameters , and let be its expected discounted return. Given a current policy , a classical identity (used throughout policy-based methods) expresses the performance of any other policy in terms of the advantage function of the old policy:
where is the discounted state-visitation distribution under . This identity is exact but useless computationally, because it requires sampling states from the new policy , which we have not yet computed. TRPO's first move is to replace with , giving the surrogate objective:
This substitution is exactly what makes the objective usable: it can be estimated from trajectories generated by the old policy, using The Advantage Function estimates already computed, and (with an importance-sampling ratio over actions) differentiated with respect to . The substitution is also the source of error — for policies that are far from , and diverge, and no longer tracks faithfully. The key theoretical contribution of TRPO is a bound quantifying exactly how much can diverge from , expressed via a KL-divergence penalty between and . This transforms an intuitive idea — "don't move the policy too far" — into a precise, provable stopping condition. The practical algorithm then solves, at each iteration,
where is the KL-divergence averaged over states visited by , and is a trust-region radius. This is a trust-region method in the classical optimization sense: instead of trusting a linear/quadratic local model everywhere, we only trust it within a region — here, a region in policy-distribution space rather than raw parameter space, which matters because a small parameter change can produce an enormous change in action probabilities (or vice versa).
How it works
The monotonic-improvement bound
Define . The central theorem states that for and a constant ,
This says: the true return of the new policy is at least the surrogate value minus a penalty that grows with how far, in the worst-case state, the new policy has drifted from the old one. Two immediate corollaries follow. First, at , both sides equal and the KL term is zero, so the bound is tight at the current policy — there is no slack to exploit trivially. Second, define
Then and for all . Any policy update that increases therefore cannot decrease :
This is a minorization-maximization (MM) algorithm: is a lower bound (a minorant) on that touches at the current point, and maximizing each iteration guarantees the true objective is non-decreasing. This is the same template that underlies expectation-maximization algorithms, and it is what gives TRPO its name: theoretically maximizing instead of alone yields guaranteed monotonic improvement.
From theory to practice
Maximizing directly is impractical: the penalty coefficient is enormous in typical problems (because close to makes tiny), producing minuscule, glacially slow steps. TRPO makes two practical relaxations: 1. Replace the max-KL penalty with a hard constraint on the average KL-divergence, , chosen empirically (e.g., ) rather than derived from . 2. Solve the constrained problem approximately using local Taylor expansions: linearize the objective, quadratically approximate the constraint. Writing for the policy gradient and for the Fisher information matrix of the policy (the Hessian of the KL constraint at ), the local problem becomes
whose solution (via Lagrange multipliers) is the natural gradient direction
Forming and inverting explicitly is infeasible for networks with thousands to millions of parameters ( for a naive inverse, just to store ). TRPO instead computes the step direction using the conjugate gradient (CG) method, which only needs the ability to compute Fisher-vector products for arbitrary vectors — computable in time via automatic differentiation (a Pearlmutter-style Hessian-vector-product trick applied to the KL divergence), without ever materializing . Because the linear/quadratic approximations are only locally valid, the raw natural-gradient step can violate the true KL constraint or even decrease the true surrogate objective. TRPO corrects this with a backtracking line search: it tries the full step, and if either the KL constraint is violated or the surrogate objective did not improve, it shrinks the step geometrically until both conditions hold. ``` PSEUDOCODE — Trust-Region Policy Optimization (single iteration) Inputs: current policy parameters θ_old, trust-region size δ, CG iterations K, backtracking coefficient α ∈ (0,1), max backtracking steps L 1. Collect a batch of trajectories using π_θold, interacting with the environment 2. Estimate advantages Â(s,a) for all visited (s,a) # e.g., via GAE, using a value baseline 3. Form the surrogate objective estimate: L(θ) = (1/N) Σ_i [ π_θ(a_i | s_i) / π_θold(a_i | s_i) ] Â_i 4. Compute policy gradient g = ∇_θ L(θ) at θ = θ_old 5. Use Conjugate Gradient to approximately solve F x = g (so x ≈ F⁻¹ g) without forming F explicitly: function Fisher_vector_product(v): kl = mean_s KL[ π_θold(·|s) ‖ π_θ(·|s) ] # evaluated at θ = θ_old grad_kl = ∇_θ kl gv = grad_kl · v # scalar return ∇_θ (gv) # this equals F v (+ damping·v) x ← ConjugateGradient(Fisher_vector_product, g, iterations=K) 6. Compute the maximal step length under the quadratic KL model: β ← sqrt( 2δ / (xᵀ F x) ) # xᵀFx estimated via one more Fisher-vector product full_step ← β x 7. Backtracking line search (ensures true improvement + true constraint satisfaction): for j = 0, 1, ..., L-1: θ_new ← θ_old + α^j full_step if KL(θ_old, θ_new) ≤ δ and L(θ_new) ≥ L(θ_old) and L(θ_new) is finite: accept θ_new; break if no step accepted after L tries: θ_new ← θ_old # reject the update this iteration 8. (Separately) Fit the value function baseline V_φ by regression on observed returns Output: θ ← θ_new ``` The CG solve in step 5 finds minimizing , which is mathematically equivalent to solving ; running iterations (typically –) gives a good approximate direction far cheaper than exact inversion. The line search in step 7 is essential: it is what upgrades an approximate* natural-gradient step into one that verifiably respects the trust-region constraint and improves the surrogate, restoring the guarantees that the Taylor approximations alone would forfeit.
Complexity & correctness
Per-iteration time complexity. Let be the number of policy parameters and the number of sampled transitions per batch. Sampling trajectories and computing advantages costs forward/backward passes through the policy and value networks. Each Fisher-vector product costs two backpropagation passes through the policy network, (proportional to network size, same order as an ordinary gradient computation), and CG runs for iterations, giving for the search-direction computation — versus for naive exact Fisher-matrix inversion and just to store . Since is a small constant (commonly 10–20) independent of , TRPO's per-iteration cost is effectively linear in the number of parameters, the same asymptotic order as a plain policy-gradient step, at the price of a constant-factor overhead of roughly backward passes plus the line search's extra forward evaluations (each cheap, , since it only re-evaluates the objective and KL, not full gradients).
Space complexity is : parameters, their gradients, and CG's working vectors (), plus the stored batch of transitions (). No matrix is ever stored, which is what makes TRPO usable for policies with millions of parameters.
Correctness argument (why monotonic improvement holds). The proof rests on three pieces fitting together: 1. Exact identity. The performance-difference identity is an algebraic consequence of telescoping the discounted-return difference over time steps and using the definition of the advantage function; it holds for any two policies, with no approximation. 2. Bounding the distribution-shift error. Swapping for introduces an error bounded by a total-variation argument: the difference in expected advantage under the two state distributions is controlled by how much probability mass shifts between them, which itself is bounded by the (max) KL-divergence between the policies via Pinsker's-inequality-type reasoning, propagated through the discounted horizon. This chain of bounds yields exactly the constant in the theorem, showing the surrogate-true gap is controlled — not merely correlated — by KL-divergence. 3. MM argument. Given the bound with equality at , any with satisfies . This is the textbook argument for MM (minorize-maximize) algorithms: improving a global lower bound that touches the objective at the current point cannot decrease the true objective.
Honesty about the practical algorithm's guarantees. The theorem uses and a specific, typically very conservative constant ; the practical algorithm uses an average-KL constraint with an empirically chosen , and solves the constrained problem only approximately via linearization plus CG plus line search. Strictly speaking, this means the textbook monotonic-improvement guarantee is not exactly preserved by the implemented algorithm — it is a well-motivated approximation. What is preserved, mechanically, by the line search is a weaker but still meaningful guarantee: each accepted step provably satisfies the average-KL constraint and provably does not decrease the estimated surrogate objective on the current batch. Empirically this tracks true performance closely when is small and batches are large enough to keep the advantage/objective estimates low-variance, but it is a heuristic bridge, not a formally airtight guarantee, over the sampling noise and the max-vs-average KL substitution.
Worked example
Consider a small discrete-action policy with two scalar parameters , controlling action logits in a 2-state, 2-action toy MDP. Suppose one iteration collects transitions and computes the following (illustrative, hand-computable) quantities at :
| Sample | ||||
|---|---|---|---|---|
| 1 | 0.5 | +1.2 | ||
| 2 | 0.5 | −0.4 | ||
| 3 | 0.5 | +0.3 | ||
| 4 | 0.5 | +0.9 |
Suppose the policy gradient at works out to (obtained by differentiating the importance-weighted surrogate, which at reduces to the ordinary score-function policy gradient weighted by ), and suppose the Fisher information matrix — here small enough to write explicitly for illustration, though TRPO would never form it this way at scale — is
Step — natural gradient via CG. Instead of inverting , TRPO's conjugate-gradient routine solves iteratively. Starting from , residual , direction :
- Iteration 1:
giving , quite close to the true already after one step (since is close to diagonal here). Continuing CG for a second iteration would essentially converge to the exact solution
Step — step-size scaling. With trust-region radius , compute . Then
so the proposed full step is .
Step — line search. TRPO evaluates : it recomputes the exact average KL divergence between and over the sampled states (not the quadratic approximation) and the exact surrogate objective . Suppose this full step yields — the quadratic model under-estimated the true divergence, a common occurrence for larger steps. TRPO backtracks: it tries , recomputes KL and ; suppose now and . Both conditions hold, so this half-step is accepted as . This trace illustrates the two-layer safety net explicitly: the quadratic KL model determines an initial candidate step, and the exact KL and objective, checked in the line search, are what actually gate acceptance — protecting against the inevitable mismatch between the local quadratic approximation and the true, nonlinear KL-divergence surface.
Common pitfalls & traps
| Pitfall | Why it happens | Consequence |
|---|---|---|
| Forming explicitly for large networks | Tempting for small toy examples (as above) | memory, inversion — infeasible for deep networks |
| Skipping the line search | Assuming the quadratic-model step size already satisfies the constraint | Quadratic approximation underestimates true KL for larger steps; accepted steps can silently blow past and destabilize the policy |
| Confusing average KL constraint with the theorem's max-KL bound | The two look interchangeable | The monotonic-improvement theorem uses max-KL; the practical algorithm uses average-KL — a real gap, not just a naming detail |
| Using stale/high-variance advantage estimates | Small batch sizes, no proper baseline | Surrogate objective becomes a noisy estimate of , so "improvement" in may not reflect true improvement |
| Treating the importance ratio as valid far from | Ignoring that the surrogate derivation assumes | Large steps make the surrogate objective's own gradient estimate unreliable, independent of the KL constraint |
| Reusing old trajectories across many CG/line-search evaluations without re-sampling | Trying to save compute | Each iteration's guarantees are with respect to the sampled state distribution; overusing stale data mismatches the on-policy assumption underlying the derivation |
Pioneers & history
TRPO was introduced by John Schulman and collaborators at UC Berkeley (advised by Pieter Abbeel), building on decades-earlier ideas about natural gradients in the parameter space of probability distributions, conservative policy iteration, and trust-region methods from classical numerical optimization.
Origins · 1 minJohn Schulman and how this was discovered
John Schulman led the development of TRPO as part of his PhD work on scalable, stable policy-gradient methods for high-dimensional continuous control and robotics. He went on to co-develop Proximal Policy Optimization, which simplified TRPO's constrained optimization into an unconstrained objective with a clipped surrogate, trading some of TRPO's theoretical machinery for dramatically simpler implementation and comparable empirical performance. His work bridged rigorous performance-bound theory and practical large-scale deep reinforcement learning systems, later including RLHF pipelines for large language models.
Where this matters
TRPO's direct descendants are ubiquitous in modern deep reinforcement learning. Proximal Policy Optimization, which simplifies TRPO's machinery into a first-order clipped objective, became the default policy-optimization algorithm behind many robotics locomotion controllers, game-playing agents, and — notably — the reinforcement-learning-from-human-feedback (RLHF) stage used to align large language models, where a KL-constrained-style objective against a reference policy is central for exactly the same reason TRPO cares about it: preventing a single bad update from catastrophically shifting model behavior. Natural-gradient and Fisher-vector-product techniques developed for TRPO's conjugate-gradient solver also influenced later second-order and preconditioned optimization methods in deep learning more broadly. Trust-region reasoning — bound the divergence between successive policies, not just the parameter step — remains the conceptual backbone for stable policy improvement across continuous-control robotics, autonomous-vehicle planning research, and multi-agent training pipelines that require careful control over policy drift.
Ask the tutor: How does the clipped surrogate objective in Proximal Policy Optimization approximate the same trust-region guarantee without conjugate gradients or a line search?
Why can't TRPO just use a small, fixed learning rate on the policy gradient instead of a trust region?
A fixed learning rate controls step size in raw parameter space, but the same parameter-space step can correspond to wildly different changes in the policy's action distribution, depending on the network's local sensitivity (curvature). A tiny parameter change near a near-deterministic policy can flip action probabilities dramatically, while a large change elsewhere barely affects behavior. TRPO's trust region instead bounds the KL-divergence — a direct measure of distributional change — making the step-size control invariant to reparameterization and directly tied to the quantity the monotonic-improvement theorem actually bounds.
What exactly is the "surrogate objective" and why is it safe to optimize with data from the old policy?
The surrogate objective equals the exact performance-difference identity, but with the new policy's state-visitation distribution swapped for the old policy's. This substitution lets it be estimated entirely from trajectories already collected under , using importance sampling only over the action distribution (not the states). It is "safe" only approximately: the monotonic-improvement theorem quantifies exactly how much error this substitution introduces, as a function of KL-divergence, which is why the KL constraint is necessary rather than optional.
How does TRPO relate to natural gradient descent?
The natural gradient rescales the ordinary policy gradient by the inverse Fisher information matrix, , producing an update direction that accounts for the local curvature of the policy's distributional geometry rather than its raw parameterization. TRPO's local quadratic approximation to the KL-constrained problem yields exactly this direction, scaled to the largest step satisfying the quadratic KL budget. TRPO can be viewed as natural gradient descent with an adaptively chosen step size (via the trust-region radius) plus a line-search safety check against the exact, non-approximated constraint and objective.
Does TRPO guarantee improvement in practice, or only in theory?
The theorem guarantees improvement only under an idealized version of the algorithm — exact optimization subject to a max-KL bound with a specific (often very conservative) constant. The practical implementation uses an average-KL constraint, approximate optimization via linearization and conjugate gradients, and finite-sample estimates of the advantage and KL from a single batch. Empirically, updates are usually stable and close to monotonic when the KL threshold is small and batches are large, but occasional performance dips can and do occur, especially under high-variance advantage estimates.
Why did the field largely move from TRPO to Proximal Policy Optimization?
TRPO requires computing Fisher-vector products, running conjugate gradients, and performing a line search every iteration — correct but complex to implement, tune, and combine with other network architectures (e.g., ones sharing parameters between policy and value heads). Proximal Policy Optimization replaces the hard KL constraint with a clipped surrogate objective optimizable via plain stochastic gradient ascent, discarding the second-order machinery while empirically achieving similar sample efficiency and stability. TRPO remains the theoretical anchor explaining why constraining policy updates works; PPO is the practical, first-order approximation of that same idea.
What is the role of the advantage function in TRPO, and does the choice of advantage estimator matter?
The surrogate objective is defined directly in terms of the advantage function of the current policy, following the same rationale used throughout The Advantage Function: it isolates the relative value of an action versus the policy's own baseline, reducing gradient variance compared to using raw returns. TRPO in practice pairs well with low-variance, low-bias advantage estimators (such as generalized advantage estimation); noisy advantage estimates directly translate into a noisy surrogate objective and gradient, undermining both the line search's correctness checks and the practical fidelity of the monotonic-improvement argument.
Is the Fisher information matrix in TRPO the same object used in classical statistics?
Yes conceptually: it is the Fisher information matrix of the policy distribution with respect to its parameters, averaged over states visited by the current policy. It equals the Hessian of the KL-divergence with respect to , evaluated at — this is precisely why computing Fisher-vector products for TRPO's conjugate-gradient solver reduces to differentiating the KL-divergence twice via automatic differentiation, rather than requiring any specialized statistical machinery.