Trust Region Policy Optimization: Mathematical Foundations, Monotonic Improvement Guarantees, and Conjugate Gradient Updates

Trust Region Policy Optimization: Mathematical Foundations, Monotonic Improvement Guarantees, and Conjugate Gradient Updates In policy gradient reinforcement learning, optimization dynamics differ fundamentally from standard supervised learning. In supervised regression or classification, the underlying data distribution $P(x, y)$ remains stationary throughout training; a sub-optimal parameter update merely yields high loss on the current batch without corrupting future sample collection. In re

9 min
Trust Region Policy Optimization: Mathematical Foundations, Monotonic Improvement Guarantees, and Conjugate Gradient Updates

Trust Region Policy Optimization: Mathematical Foundations, Monotonic Improvement Guarantees, and Conjugate Gradient Updates

In policy gradient reinforcement learning, optimization dynamics differ fundamentally from standard supervised learning. In supervised regression or classification, the underlying data distribution P(x,y)P(x, y) remains stationary throughout training; a sub-optimal parameter update merely yields high loss on the current batch without corrupting future sample collection. In reinforcement learning, however, the parameter vector θ\theta of a policy πθ(as)\pi_\theta(a|s) defines both the action distribution and the state visitation distribution ρπ(s)\rho_\pi(s). A single excessive gradient step can push the policy into an unrecoverable region of parameter space, degrading performance and generating trajectories from which meaningful reward signals cannot be collected.

To resolve this instability, Schulman et al. (2015) introduced Trust Region Policy Optimization (TRPO). Building upon the theoretical foundations of Conservative Policy Iteration by Kakade and Langford (2002), TRPO proves that enforcing a statistical constraint on policy divergence guarantees monotonic policy improvement. By optimizing a local surrogate objective subject to an average Kullback-Leibler (KL) divergence constraint, and solving the resulting quadratic subproblem via the conjugate gradient method and automatic differentiation vector products, TRPO established the modern paradigm of constrained policy optimization.


The Policy Gradient Step-Size Dilemma

Standard policy gradient methods, derived from the Policy Gradient Theorem (Sutton et al., 1999), optimize the expected cumulative discounted return:

η(π)=Eτπ[t=0γtr(st,at)]\eta(\pi) = \mathbb{E}_{\tau \sim \pi} \left[ \sum_{t=0}^\infty \gamma^t r(s_t, a_t) \right]

The analytical gradient of η(πθ)\eta(\pi_\theta) with respect to parameter vector θ\theta is given by:

θη(πθ)=Esρπθ,aπθ[θlogπθ(as)Qπθ(s,a)]\nabla_\theta \eta(\pi_\theta) = \mathbb{E}_{s \sim \rho_{\pi_\theta}, a \sim \pi_\theta} \left[ \nabla_\theta \log \pi_\theta(a|s) Q^{\pi_\theta}(s, a) \right]

In empirical implementations, parameters are updated via first-order gradient ascent:

θk+1=θk+αθη(πθ)\theta_{k+1} = \theta_k + \alpha \nabla_\theta \eta(\pi_\theta)

This first-order formulation suffers from three severe mathematical and practical limitations:

  1. Euclidean Geometry vs. Probability Manifolds: First-order gradient ascent measures step size α\alpha in parameter space Euclidean distance Δθ2\|\Delta \theta\|_2. However, neural network parameterizations are highly non-linear; an identical Euclidean step Δθ2=ϵ\|\Delta \theta\|_2 = \epsilon can cause a negligible change in policy distributions in flat regions of the parameter landscape, yet cause catastrophic shifts in steep regions.
  2. State Distribution Shift: Evaluating the gradient under trajectories sampled from πθk\pi_{\theta_k} assumes that the current state visitation distribution ρπθk\rho_{\pi_{\theta_k}} remains valid for the updated policy πθk+1\pi_{\theta_{k+1}}. If the step size is too large, the state visitation distribution shifts abruptly, invalidating prior value estimates.
  3. Irreversible Performance Collapse: In supervised learning, bad updates can be corrected by subsequent mini-batches. In reinforcement learning, a policy that degrades produces degenerate trajectories (such as getting stuck in dead-end states), eliminating exploratory actions and preventing the policy from recovering.

Kakade and Langford's Relative Performance Identity

To formalize how an updated policy π~\tilde{\pi} performs relative to an existing policy π\pi, Kakade and Langford (2002) derived the exact relative performance identity:

η(π~)=η(π)+sρπ~(s)aπ~(as)Aπ(s,a)\eta(\tilde{\pi}) = \eta(\pi) + \sum_s \rho_{\tilde{\pi}}(s) \sum_a \tilde{\pi}(a|s) A_\pi(s, a)

where Aπ(s,a)=Qπ(s,a)Vπ(s)A_\pi(s, a) = Q_\pi(s, a) - V_\pi(s) is the advantage function under policy π\pi, and ρπ(s)=t=0γtP(st=sπ)\rho_\pi(s) = \sum_{t=0}^\infty \gamma^t P(s_t = s | \pi) is the unnormalized discounted state visitation frequency.

This identity reveals that if aπ~(as)Aπ(s,a)0\sum_a \tilde{\pi}(a|s) A_\pi(s, a) \ge 0 for all states ss, then η(π~)η(π)\eta(\tilde{\pi}) \ge \eta(\pi), guaranteeing policy improvement. However, computing the expectation over ρπ~(s)\rho_{\tilde{\pi}}(s) is intractable in practice because sampling trajectories from the un-evaluated candidate policy π~\tilde{\pi} prior to optimization is impossible.

The Local Surrogate Objective

To make optimization tractable, Schulman et al. replace the unknown state distribution ρπ~(s)\rho_{\tilde{\pi}}(s) with the known state distribution ρπ(s)\rho_\pi(s), defining the local surrogate objective Lπ(π~)L_\pi(\tilde{\pi}):

Lπ(π~)=η(π)+sρπ(s)aπ~(as)Aπ(s,a)L_\pi(\tilde{\pi}) = \eta(\pi) + \sum_s \rho_\pi(s) \sum_a \tilde{\pi}(a|s) A_\pi(s, a)

For parameterized policies πθ\pi_\theta, Lθ0(θ)L_{\theta_0}(\theta) matches the true objective η(πθ)\eta(\pi_\theta) to first order at θ=θ0\theta = \theta_0:

Lθ0(θ0)=η(πθ0)L_{\theta_0}(\theta_0) = \eta(\pi_{\theta_0})

θLθ0(θ)θ=θ0=θη(πθ)θ=θ0\left. \nabla_\theta L_{\theta_0}(\theta) \right|_{\theta = \theta_0} = \left. \nabla_\theta \eta(\pi_\theta) \right|_{\theta = \theta_0}

Consequently, a sufficiently small step that improves Lθ0(θ)L_{\theta_0}(\theta) is guaranteed to improve η(πθ)\eta(\pi_\theta).

The Monotonic Improvement Bound

To establish how large a step can be taken before the approximation error between Lπ(π~)L_\pi(\tilde{\pi}) and η(π~)\eta(\tilde{\pi}) overwhelms the improvement, Schulman et al. established the formal bound:

η(π~)Lπ(π~)CDKLmax(π,π~)\eta(\tilde{\pi}) \ge L_\pi(\tilde{\pi}) - C \cdot D_{\text{KL}}^{\max}(\pi, \tilde{\pi})

where:

  • $D_{\text{KL}}^{\max}(\pi, \tilde{\pi}) = \max_s D_{\text{KL}}(\pi(\cdot|s) \parallel \tilde{\pi}(\cdot|s))$
  • C=4ϵγ(1γ)2C = \frac{4 \epsilon \gamma}{(1 - \gamma)^2}
  • ϵ=maxs,aAπ(s,a)\epsilon = \max_{s, a} |A_\pi(s, a)|

This inequality serves as a Minorize-Maximization (MM) algorithm: by iteratively maximizing the right-hand side lower bound, the true objective η(π)\eta(\pi) is guaranteed to improve monotonically at every step:

η(πk+1)Mk(πk+1)Mk(πk)=η(πk)\eta(\pi_{k+1}) \ge M_k(\pi_{k+1}) \ge M_k(\pi_k) = \eta(\pi_k)

where Mk(π)=Lπk(π)CDKLmax(πk,π)M_k(\pi) = L_{\pi_k}(\pi) - C \cdot D_{\text{KL}}^{\max}(\pi_k, \pi).


From Theoretical Penalties to Practical Trust Regions

While the theoretical bound guarantees monotonic improvement, the constant C=4ϵγ(1γ)2C = \frac{4 \epsilon \gamma}{(1 - \gamma)^2} is extremely large in practical reinforcement learning tasks (where discount factor γ0.99\gamma \approx 0.99, making (1γ)2=0.0001(1 - \gamma)^2 = 0.0001). An unconstrained optimization of Lπ(π~)CDKLmax(π,π~)L_\pi(\tilde{\pi}) - C \cdot D_{\text{KL}}^{\max}(\pi, \tilde{\pi}) forces step sizes to be vanishingly small, stalling training progress.

Furthermore, evaluating the maximum KL divergence DKLmax(π,π~)D_{\text{KL}}^{\max}(\pi, \tilde{\pi}) across the entire state space is computationally impossible in continuous or high-dimensional environments.

TRPO makes two critical transitions to turn this theoretical framework into a practical algorithm:

  1. Average KL Divergence: Replace the maximum KL divergence with the expected KL divergence under the state visitation distribution ρθold\rho_{\theta_{\text{old}}}:

DˉKL(θold,θ)=Esρθold[DKL(πθold(s)πθ(s))]\bar{D}_{\text{KL}}(\theta_{\text{old}}, \theta) = \mathbb{E}_{s \sim \rho_{\theta_{\text{old}}}} \left[ D_{\text{KL}}(\pi_{\theta_{\text{old}}}(\cdot|s) \parallel \pi_\theta(\cdot|s)) \right]

  1. Hard Trust Region Constraint: Instead of a penalty formulation with fixed coefficient CC, cast optimization as a constrained maximization problem with a bounded trust region step size δ\delta:

maxθLθold(θ)subject toDˉKL(θold,θ)δ\max_\theta L_{\theta_{\text{old}}}(\theta) \quad \text{subject to} \quad \bar{D}_{\text{KL}}(\theta_{\text{old}}, \theta) \le \delta

Using importance sampling, the surrogate objective Lθold(θ)L_{\theta_{\text{old}}}(\theta) is rewritten in sample form:

Lθold(θ)=Esρθold,aπθold[πθ(as)πθold(as)Aθold(s,a)]L_{\theta_{\text{old}}}(\theta) = \mathbb{E}_{s \sim \rho_{\theta_{\text{old}}}, a \sim \pi_{\theta_{\text{old}}}} \left[ \frac{\pi_\theta(a|s)}{\pi_{\theta_{\text{old}}}(a|s)} A_{\theta_{\text{old}}}(s, a) \right]

Conjugate Gradient Descent Trajectory

Quadratic Approximation and the Natural Policy Gradient

To solve the constrained optimization problem numerically, TRPO applies a second-order Taylor series expansion around θold\theta_{\text{old}}:

  1. Linear approximation of the objective:

Lθold(θ)Lθold(θold)+gT(θθold)L_{\theta_{\text{old}}}(\theta) \approx L_{\theta_{\text{old}}}(\theta_{\text{old}}) + g^T (\theta - \theta_{\text{old}})

where $g = \left. \nabla_\theta L_{\theta_{\text{old}}}(\theta) \right|_{\theta = \theta_{\text{old}}} = \mathbb{E} \left[ \nabla_\theta \log \pi_\theta(a|s) A(s, a) \right]$.

  1. Quadratic approximation of the KL divergence constraint:

DˉKL(θold,θ)12(θθold)TH(θθold)\bar{D}_{\text{KL}}(\theta_{\text{old}}, \theta) \approx \frac{1}{2} (\theta - \theta_{\text{old}})^T H (\theta - \theta_{\text{old}})

where HH is the Fisher Information Matrix (FIM), defined as the Hessian of the average KL divergence evaluated at θ=θold\theta = \theta_{\text{old}}:

H=Esρθold[Eaπθold[θlogπθ(as)θlogπθ(as)T]]H = \mathbb{E}_{s \sim \rho_{\theta_{\text{old}}}} \left[ \mathbb{E}_{a \sim \pi_{\theta_{\text{old}}}} \left[ \nabla_\theta \log \pi_\theta(a|s) \nabla_\theta \log \pi_\theta(a|s)^T \right] \right]

Setting Δθ=θθold\Delta \theta = \theta - \theta_{\text{old}}, the optimization problem reduces to:

maxΔθgTΔθsubject to12ΔθTHΔθδ\max_{\Delta \theta} g^T \Delta \theta \quad \text{subject to} \quad \frac{1}{2} \Delta \theta^T H \Delta \theta \le \delta

Analytical Solution via Lagrange Multipliers

Forming the Lagrangian:

L(Δθ,λ)=gTΔθλ(12ΔθTHΔθδ)\mathcal{L}(\Delta \theta, \lambda) = g^T \Delta \theta - \lambda \left( \frac{1}{2} \Delta \theta^T H \Delta \theta - \delta \right)

Taking the gradient with respect to Δθ\Delta \theta and setting it to zero:

ΔθL=gλHΔθ=0    Δθ=1λH1g\nabla_{\Delta \theta} \mathcal{L} = g - \lambda H \Delta \theta = 0 \implies \Delta \theta = \frac{1}{\lambda} H^{-1} g

Substituting Δθ\Delta \theta into the boundary constraint 12ΔθTHΔθ=δ\frac{1}{2} \Delta \theta^T H \Delta \theta = \delta:

12(1λH1g)TH(1λH1g)=δ    12λ2gTH1g=δ\frac{1}{2} \left( \frac{1}{\lambda} H^{-1} g \right)^T H \left( \frac{1}{\lambda} H^{-1} g \right) = \delta \implies \frac{1}{2 \lambda^2} g^T H^{-1} g = \delta

λ=gTH1g2δ\lambda = \sqrt{\frac{g^T H^{-1} g}{2 \delta}}

This yields the closed-form TRPO search direction:

Δθ=2δgTH1gH1g\Delta \theta = \sqrt{\frac{2 \delta}{g^T H^{-1} g}} H^{-1} g

The term H1gH^{-1} g is the Natural Policy Gradient (Amari, 1998; Kakade, 2001). TRPO automatically scales the natural gradient vector by 2δgTH1g\sqrt{\frac{2 \delta}{g^T H^{-1} g}} so that the resulting step precisely exhausts the trust region budget δ\delta.


Large-Scale Computation: Pearlmutter Vector Products and Conjugate Gradients

For modern deep neural networks containing millions of parameters (d106d \sim 10^6), forming the full Fisher Information Matrix HRd×dH \in \mathbb{R}^{d \times d} would require terabytes of memory, and inverting it (O(d3)O(d^3) operations) is computationally prohibitive.

TRPO solves Hx=gH x = g for xH1gx \approx H^{-1} g without ever materializing HH, utilizing two mathematical techniques:

1. The Pearlmutter Fisher-Vector Product (FVP)

Using the technique formalized by Pearlmutter (1994), the matrix-vector product HvH v for an arbitrary vector vv can be computed using two backward automatic differentiation passes:

Hv=θ((θDˉKL(θold,θ))Tv)H v = \nabla_\theta \left( \left( \nabla_\theta \bar{D}_{\text{KL}}(\theta_{\text{old}}, \theta) \right)^T v \right)

In PyTorch notation, this is implemented cleanly:

import torch

def compute_fisher_vector_product(kl_div, policy_params, v, damping=1e-2):
    # First backward pass: compute gradient of KL divergence
    kl_grad = torch.autograd.grad(kl_div, policy_params, create_graph=True)
    kl_grad_flat = torch.cat([g.contiguous().view(-1) for g in kl_grad])
    
    # Inner product with arbitrary vector v
    grad_v_prod = torch.sum(kl_grad_flat * v)
    
    # Second backward pass: compute Hessian-vector product
    hvp = torch.autograd.grad(grad_v_prod, policy_params, retain_graph=True)
    hvp_flat = torch.cat([g.contiguous().view(-1) for g in hvp])
    
    # Add numerical damping for positive-definiteness: (H + damping * I) v
    return hvp_flat + damping * v

2. The Conjugate Gradient Algorithm

Because HH is symmetric and positive semi-definite, the linear system Hx=gH x = g can be solved iteratively using the Conjugate Gradient (CG) algorithm. CG finds the exact solution on a Krylov subspace in at most dd steps, but in practice, k=10k = 10 to 1515 iterations yield an accurate approximation:

def conjugate_gradient(fvp_fn, b, n_steps=10, residual_tol=1e-10):
    x = torch.zeros_like(b)
    r = b.clone()
    p = b.clone()
    rdotr = torch.dot(r, r)
    
    for _ in range(n_steps):
        Ap = fvp_fn(p)
        alpha = rdotr / (torch.dot(p, Ap) + 1e-8)
        x += alpha * p
        r -= alpha * Ap
        new_rdotr = torch.dot(r, r)
        if new_rdotr < residual_tol:
            break
        beta = new_rdotr / rdotr
        p = r + beta * p
        rdotr = new_rdotr
        
    return x

Because the analytical update Δθ\Delta \theta relies on linear and quadratic Taylor approximations, higher-order terms can cause the update to violate the non-linear trust region constraint DˉKL(θold,θ)δ\bar{D}_{\text{KL}}(\theta_{\text{old}}, \theta) \le \delta or fail to improve the surrogate objective Lθold(θ)L_{\theta_{\text{old}}}(\theta).

To ensure monotonic improvement and strict constraint satisfaction, TRPO performs a backtracking line search along the direction Δθ\Delta \theta:

θnew=θold+αjΔθ\theta_{\text{new}} = \theta_{\text{old}} + \alpha^j \Delta \theta

for j{0,1,2,,J}j \in \{0, 1, 2, \dots, J\}, with decay factor α(0,1)\alpha \in (0, 1) (typically α=0.5\alpha = 0.5). The algorithm accepts the first θnew\theta_{\text{new}} that satisfies both criteria:

  1. Surrogate Improvement: Lθold(θnew)0L_{\theta_{\text{old}}}(\theta_{\text{new}}) \ge 0
  2. Trust Region Compliance: DˉKL(θold,θnew)δ\bar{D}_{\text{KL}}(\theta_{\text{old}}, \theta_{\text{new}}) \le \delta

If no step in the search satisfies both conditions after JJ iterations (typically J=10J = 10), the update is rejected, and the parameters remain θold\theta_{\text{old}}, guaranteeing that catastrophic updates are never committed.


TRPO vs. PPO: Algorithmic Comparison

In 2017, Schulman et al. (2017) published Proximal Policy Optimization (PPO), introducing a first-order clipped surrogate objective that bypassed conjugate gradient computation:

| Feature | TRPO (Trust Region Policy Optimization) | PPO (Proximal Policy Optimization) | | :--- | :--- | :--- | | Optimization Order | Second-order (Natural Policy Gradient via CG) | First-order (SGD / Adam) | | Constraint Mechanism | Hard statistical constraint: DˉKLδ\bar{D}_{\text{KL}} \le \delta | Clipped probability ratio: clip(rt(θ),1ϵ,1+ϵ)\text{clip}(r_t(\theta), 1-\epsilon, 1+\epsilon) | | Computation per Step | High (10 to 15 Fisher-vector passes + Line Search) | Low (Standard backpropagation) | | Network Architecture Flexibility | Restricted (sharing weights between Actor and Critic is difficult) | High (Supports shared actor-critic trunk and RNNs) | | Implementation Complexity | High (Custom autograd graphs and CG solver) | Low (Few lines of loss code in standard frameworks) | | Sample Efficiency | Higher on dense continuous control benchmarks | Slightly lower per batch, but faster wall-clock throughput | | Role in LLM Post-Training | Rarely used due to distributed multi-GPU CG overhead | Industry standard for RLHF and reasoning alignment |


Architectural Impact on Modern AI

While PPO became the standard algorithm for large-scale post-training and Reinforcement Learning from Human Feedback (RLHF) due to its compatibility with distributed Adam optimizers and tensor parallelism, TRPO established the foundational theoretical architecture for modern policy optimization:

  1. Information Geometry as First Principle: TRPO proved that measuring distance between policies via probability distributions (KL divergence) rather than parameter vectors (Euclidean distance) is essential for stable learning.
  2. Surrogate Importance Objectives: The probability ratio rt(θ)=πθ(atst)πθold(atst)r_t(\theta) = \frac{\pi_\theta(a_t|s_t)}{\pi_{\theta_{\text{old}}}(a_t|s_t)} combined with advantage estimates forms the backbone of all modern alignment frameworks, including PPO, GRPO, and DPO.
  3. Monotonic Lower Bounds: The Minorize-Maximization perspective demonstrated that optimizing guaranteed lower bounds prevents policy collapse in complex multi-step reasoning and control environments.

Sources

Written by

More to read

  • Latent Reasoning in Large Language Models: How Continuous Thoughts and Recurrent Hidden States Bypass Discrete Tokenization

    Standard autoregressive language models solve multi-step reasoning tasks by generating explicit verbal scratchpads. Under the Chain-of-Thought (CoT) paradigm formalized by Wei et al. (2022), a Transformer expands its effective computational depth by emitting intermediate natural language tokens into the prompt context. Each emitted token provides an additional forward pass through the network's layers, transforming reasoning into a sequence of left-to-right text predictions. While language-base

    1 min
  • Speech-to-Text Serving in Production: Comparing Faster-Whisper, Moonshine, SenseVoice, and NeMo Canary Architecture, Streaming Latency, and GPU Economics

    In conversational voice AI and real-time agentic workflows, the speech-to-text (STT) layer sets the hard lower bound on system responsiveness. Human conversational cadence expects turn-taking latencies between 200ms and 500ms. When an AI pipeline must accommodate downstream large language model (LLM) time-to-first-token generation (100ms to 250ms) and text-to-speech (TTS) audio synthesis (100ms to 200ms), the automatic speech recognition (ASR) stage cannot exceed 100ms to 150ms of processing ove

    1 min
  • Writer Releases Palmyra X6 Flagship Agentic Model with Rebuilt Enterprise Agent Harness

    Enterprise generative AI platform Writer has launched Palmyra X6, its new flagship agentic foundation model, alongside a rebuilt runtime harness engineered for multi-step workflow execution and governance. The model release introduces substantial latency and efficiency improvements over previous Palmyra iterations, cutting inference costs by 52% while accelerating output generation by 48%. Writer reported average generation speeds of 82 tokens per second and a mean task completion time of 26 se

    1 min