Exercises — Trust Region Policy Optimization (TRPO)
Level 1 — Recognition
Here we only name and match pieces. No computation yet.
Exercise 1.1 — Name every symbol
In the TRPO optimization problem
identify in plain words what each of these is: the ratio , the quantity , the symbol , and the number .
Recall Solution
- — the importance ratio. We collected data with the old policy but want to score the new one, so we re-weight each old sample by how much more (or less) likely the new policy makes that action. See Importance Sampling.
- — the advantage: how much better action is than the average action in state , under the old policy. Using the objects defined above, — the Q-value of taking minus the state's average value. Positive means "better than average, push it up."
- — the mean KL divergence between old and new action-distributions, averaged over visited states. It measures how different the two policies are as probability distributions (in "nats"). See KL Divergence.
- — the trust-region size: the maximum allowed KL. A speed limit measured in distribution-space.
Exercise 1.2 — Which lives where?
For each item, say whether it is measured in parameter-space (distances between vectors) or distribution-space (distances between probability distributions): (a) , (b) , (c) the Fisher matrix .
Recall Solution
- (a) — parameter-space. Plain Euclidean length of the step vector — how far the weights moved.
- (b) — distribution-space. It ignores how the weights are laid out and asks only how different the resulting policies are.
- (c) — the bridge between the two. is the local map that turns a small parameter step into the distribution-distance it causes: . That is exactly why the natural gradient uses .
Look at the picture below: the arrow points straight uphill in flat weight-space, but the trust region is a squashed ellipse (because stretches some directions), so the safe step is not along — it is bent by onto the ellipse boundary.

Level 2 — Application
Now we compute, using the TRPO step formula. Recall from the definitions above that is the policy gradient, the Fisher matrix, and the parameter step we solve for:
Read it as: take the raw uphill direction , bend it by (this is the natural gradient direction), then scale the whole arrow so it lands exactly on the KL trust-region boundary.
Exercise 2.1 — Diagonal Fisher step
Let , , . Compute , then , then the scale factor, then the full step . Verify .
Recall Solution
Step 1 (natural gradient). is diagonal, so its inverse just divides each entry: Why: inverting a diagonal matrix means reciprocating each diagonal entry — no heavy linear algebra. Step 2 (denominator). Step 3 (scale). Step 4 (step). Verify. ✓
Exercise 2.2 — Importance ratio sign
Old policy , new . Compute the surrogate contribution of this sample when (a) , (b) . Interpret each sign.
Recall Solution
Ratio .
- (a) : contribution . The action is good, but the new policy made it less likely (ratio ), so we recorded a smaller gain — the objective is telling us we moved the wrong way for this action.
- (b) : contribution . The action is bad, and we reduced its probability, so this is still a negative term but less negative than the ratio-1 case — reducing a bad action is rewarded relative to keeping it.
Exercise 2.3 — KL as a speed limit in nats
A step produces but . Is the step accepted? What does TRPO do next?
Recall Solution
Rejected: , the true KL exceeds the trust region. TRPO runs a backtracking line search: shrink the step by a factor (e.g. : try full, then half, then quarter…) until the true KL and the surrogate objective actually improved. The quadratic KL approximation can under-estimate real KL, which is exactly why this safety check exists.
Level 3 — Analysis
Now we reason about why the machinery is built this way.
Exercise 3.1 — Non-diagonal Fisher
Let and , . Compute the natural gradient and compare its direction to the raw gradient . What did change?
Recall Solution
, so Here points the same direction as (both are ) because happens to be an eigenvector of (eigenvalue ). In general the direction changes: stretches directions of high curvature (large distribution-change per unit ) and shrinks the step there, so equal-looking parameter moves cause equal policy moves. See Natural Gradient Descent and Fisher Information Matrix. The scale: ; scale ; step
Exercise 3.2 — Why the KL Hessian, not the KL gradient
The parent note says the constraint is approximated by , using the second derivative of KL, not the first. Explain why the first-order (gradient) term of KL is useless here.
Recall Solution
At the two policies are identical, so there, and it is a minimum (KL is ). At a minimum the gradient is zero: . So a first-order Taylor expansion would say "KL stays 0 in every direction," which is false. The leading nonzero information is the curvature — the Hessian of KL — and that Hessian is the Fisher matrix . That is why we must go to second order to see the trust region at all.
Exercise 3.3 — What happens as ?
The theoretical penalty coefficient is . Describe its behaviour as and explain why that makes the theoretical guaranteed step tiny.
Recall Solution
As , the denominator , so . The guaranteed-improvement bound is ; a huge means even a tiny KL subtracts an enormous penalty, so the largest provably safe step shrinks toward zero. Intuition: with near the agent cares about the far future, so a small policy change can ripple across many timesteps and the worst-case damage grows. This blow-up is exactly why TRPO abandons the literal and uses a hard tunable constraint plus a line search instead.
Level 4 — Synthesis
Now assemble multiple ideas into one pipeline.
Exercise 4.1 — Order the TRPO update
Put these steps in the correct order for one TRPO update, and name the tool used at each: (i) line search, (ii) estimate advantages, (iii) collect trajectories, (iv) compute , (v) compute policy gradient , (vi) scale to the trust-region boundary.
Recall Solution
- (iii) Collect trajectories by running in the environment.
- (ii) Estimate advantages from those trajectories — tool: Advantage Estimation (GAE).
- (v) Compute the policy gradient of the (importance-weighted) surrogate — tool: Policy Gradient Methods.
- (iv) Compute by solving with Conjugate Gradient Method using Fisher-vector products (never building ).
- (vi) Scale to the trust-region boundary via the factor , giving the full step .
- (i) Line search — backtrack until true KL and the surrogate improved.
Exercise 4.2 — Full mini-pipeline on numbers
You collected two samples. Sample A: old prob , new prob , advantage . Sample B: old prob , new prob , advantage . Compute the empirical surrogate objective (average of ratio × advantage). Is this update improving the surrogate?
Recall Solution
- Sample A: ratio , term .
- Sample B: ratio , term .
- Surrogate . Positive surrogate () means the new policy improves on the old under the frozen state distribution — it raised probability of the good action and lowered probability of the bad one. Whether it improves the true return still needs the KL check + line search.
Exercise 4.3 — Connect TRPO to PPO
State one thing TRPO does with the KL constraint that Proximal Policy Optimization (PPO) replaces, and why PPO's version is cheaper.
Recall Solution
TRPO enforces a hard KL constraint solved with conjugate gradient + Fisher-vector products + line search — mathematically clean but heavy per step. PPO removes the second-order machinery: it either adds a KL penalty or, more commonly, clips the importance ratio to so that pushing the ratio too far stops helping the objective. This keeps the "don't move too far" spirit using only first-order gradients (plain SGD/Adam), so it is far cheaper and easier to implement, at the cost of TRPO's exact trust-region guarantee.
Level 5 — Mastery
Full derivations from first principles.
Exercise 5.1 — Derive the step formula
Starting from s.t. ( symmetric positive-definite), derive . State where the constraint is active.
Recall Solution
Lagrangian. Since maximizing pushes as far as allowed, the constraint is active (equality) at the optimum: . Form Stationarity. (Uses symmetric so .) Solve for . Plug into the active constraint: using and . Hence (positive root, so ). Assemble.
Exercise 5.2 — Guaranteed-improvement check
With bound , suppose a step gives surrogate improvement , KL , and . Is monotonic improvement guaranteed by the bound? What if ?
Recall Solution
The lower bound on the true improvement is .
- : . Guaranteed improvement. ✓
- : . The bound no longer guarantees improvement (worst case could decrease ). ✗ Lesson: a larger penalty coefficient demands a smaller KL step to stay provably safe — precisely why the theoretical forces tiny steps and TRPO prefers a tuned + line search.
Exercise 5.3 — Two-parameter full solve
Let , , . Compute , , the scale, the full step , and verify the KL constraint is met exactly.
Recall Solution
- scale
- Verify: ✓
Look at the picture below: the penalty eats into the surrogate gain. For the same KL step, a steeper penalty line () drops the guaranteed bound below zero.

Recall Self-test checklist
Name every symbol in the TRPO problem ::: importance ratio, advantage, mean KL, trust-region size . What are g, F, and s ::: g is the policy gradient (uphill direction in weight-space), F the Fisher matrix (parameter-to-distribution sensitivity), s the parameter step we solve for. Why is the KL constraint quadratic, not linear, in ::: because KL is minimized (=0) at , so its gradient vanishes and the Fisher Hessian is the leading term. Direction and scale of the TRPO step ::: direction (natural gradient), scale . Why never invert ::: too big; solve with conjugate gradient via Fisher-vector products. Why a line search after the step ::: the quadratic KL approximation may violate the true constraint, so backtrack until true KL and surrogate improves.