The estimator is on-policy in two ways: states follow the current policy's occupancy dπθ, and actions follow πθ(⋅∣s).
Suppose a batch was collected by πθk and one gradient step produces
θk+1=θk+αgk.
The old state-action pairs did not come from πθk+1. Reusing them naively substitutes the wrong sampling distribution into the next gradient estimate.
This is expensive because reliable policy gradients need large trajectory batches. We want an outer loop that collects data and an inner loop that performs several optimization steps:
collect once⟶estimate advantages once⟶optimize several times.
Every inner step makes the batch more off-policy. Advanced policy optimization asks how to reuse it without letting the candidate policy drift so far that the old data becomes misleading.
Importance Sampling
Let p be a target distribution and q a behavior distribution. If q(x)>0 wherever p(x)>0, then
Ex∼p[f(x)]=Ex∼q[q(x)p(x)f(x)].
The likelihood ratio corrects for sampling from the wrong distribution.
This deliberately ignores state-distribution mismatch. It is useful only while the candidate policy remains close to the behavior policy.
Policy Improvement from Old Advantages
The right justification for several old-batch updates is approximate policy iteration. We evaluate the old policy, then fit a new policy that prefers its positive-advantage actions.
For policies π and π′, the performance-difference lemma states
At each fixed state, change the action distribution back to π:
Ea∼π′[Aπ(s,a)]=Ea∼π[π(a∣s)π′(a∣s)Aπ(s,a)].
The only remaining new-policy quantity is its state distribution. Replacing dπ′ with dπ yields the tractable surrogate
Lπ(π′)=1−γ1Es∼dπ,a∼π[π(a∣s)π′(a∣s)Aπ(s,a)].
The old advantage is exact. The approximation is freezing the state visitation distribution.
Several inner updates are reasonable while the old advantages remain informative and dπ′ remains close to dπ.
Controlling State-Distribution Shift
At a state, total-variation distance between two policies is
DTV(π′(⋅∣s),π(⋅∣s))=21a∑∣π′(a∣s)−π(a∣s)∣.
Assume
smaxDTV(π′(⋅∣s),π(⋅∣s))≤α.
The policies can be coupled to choose the same action at each shared state with probability at least 1−α. The probability of no disagreement for t decisions is at least (1−α)t, so
DTV(ptπ′,ptπ)≤1−(1−α)t≤tα.
Thus small action-distribution changes control state-distribution changes over a limited horizon.
For a bounded function f,
∣Ep′[f]−Ep[f]∣≤2DTV(p′,p)∥f∥∞.
Combining these ideas gives the structural bound
true improvement≥old-data surrogate improvement−penalty for policy change.
For the infinite-horizon discounted case, the penalty contains
t=0∑∞tγt=(1−γ)2γ,
so long effective horizons make distribution shift especially costly.
Pinsker's inequality connects total variation to KL divergence:
DTV(p,q)≤21DKL(p∥q).
We can therefore control the approximation error by keeping the candidate policy close in KL.
KL Trust Regions
Euclidean parameter distance is a poor measure of policy change. A tiny parameter step can drastically alter action probabilities, while a large step in an insensitive direction may barely change them.
KL divergence measures change in the represented distributions:
DKL(p∥q)=Ex∼p[logq(x)p(x)].
It is nonnegative but asymmetric:
DKL(p∥q)=DKL(q∥p).
We usually average statewise KL under old-policy states:
For At>0, it rewards increasing ρt without limit. For At<0, it rewards decreasing ρt without limit. Repeated updates can therefore move far beyond the region where the old advantage is reliable.
The sample stops rewarding further increases beyond 1+ϵ. Moving in the harmful direction still receives the unclipped penalty.
When A<0,
ℓ(ρ,A)={(1−ϵ)A,ρA,ρ<1−ϵ,ρ≥1−ϵ.
The sample stops rewarding further probability reduction below 1−ϵ, while increasing the bad action remains penalized.
This is why PPO uses
min(ρA,clip(ρ)A)
rather than simply replacing ρ by its clipped value.
Clipping does not enforce
1−ϵ≤ρt≤1+ϵ
for every sample. It removes the incentive for excessive movement in one direction; it does not pull an out-of-range ratio back. Shared network parameters can also change unsampled probabilities.
At the start of the update, ρt=1, so clipped and unclipped objectives have the same gradient. After policy movement, clipping introduces deliberate bias in exchange for lower variance and safer reuse.
Old log-probabilities, advantages, and value targets are computed once and frozen throughout the inner epochs. Recomputing the denominator with the updated policy would collapse the ratio toward one and destroy the surrogate's meaning.
The entropy bonus discourages premature collapse of the action distribution.
Clipped PPOInitialize actor πθ and critic Vϕ.Repeat:θold←θ,collect trajectories with πθold,store logπθold(at∣st),compute and freeze At and Vttarget,for several epochs:shuffle the batch into minibatches,ρt←exp(logπθ(at∣st)−logπold(at∣st)),optimize the clipped actor objective, value loss, and entropy,measure KL and stop early if it becomes too large.collect a fresh batch with the updated policy.
An empirical old-to-new KL estimate is
DKL≈B1t∑[logπold(at∣st)−logπθ(at∣st)].
Clipping approximates a trust region; monitoring KL and stopping inner optimization early remain important safeguards.
Natural Policy Gradients
The ordinary gradient is the steepest-ascent direction under a Euclidean parameter constraint:
δmaxg⊤δsubject toδ⊤δ≤ε,
where g=∇θJ(θ). Natural gradients instead measure local distance by policy KL.
Linearize the objective and quadratically approximate KL:
δmaxsubject tog⊤δ21δ⊤Fδ≤ε.
The solution is
δ∗=g⊤F−1g2εF−1g.›See derivation
Form the Lagrangian
L(δ,λ)=g⊤δ−λ(21δ⊤Fδ−ε).
Stationarity gives
g−λFδ=0,
so
δ=λ1F−1g.
The optimum uses the full KL budget:
2λ21g⊤F−1g=ε.
Solving for λ and substituting yields the stated step.
The direction
∇θJ=F−1∇θJ
is the natural policy gradient. Directions that strongly change action probabilities have large Fisher curvature and are shrunk. Directions that barely change the policy can move farther in parameter space.
Trust Region Policy Optimization
TRPO approximates the natural-gradient trust-region step without constructing or inverting the Fisher matrix.
At the current policy, estimate the surrogate gradient g and solve
Fx=g.
For a network with millions of parameters, explicitly forming F is impossible. Automatic differentiation can instead compute Fisher-vector products
Fv=∇θ′[∇θ′DKL(θ′)⊤v]θ′=θ
without materializing the matrix.
Conjugate gradients approximately solves the damped system
(F+ηI)x=g.
Damping improves conditioning and prevents extreme movement along poorly estimated low-curvature directions.
Scale the direction to the quadratic KL radius:
δquad=x⊤Fx2δKLx.
This step is based on local approximations and a finite-sample Fisher estimate. TRPO therefore performs backtracking line search. It tries
θcandidate=θ+αδquad,α∈{1,ξ,ξ2,…},
and accepts the first candidate that improves the measured surrogate while satisfying the empirical KL limit.
TRPOCollect trajectories with πθ.Estimate fixed advantages and the surrogate gradient g.Define v↦(F+ηI)v using Fisher-vector products.Use conjugate gradients to approximately solve (F+ηI)x=g.Scale x to the quadratic KL radius.Backtrack along the step until:the surrogate improves, andDKL≤δKL.Accept the candidate and collect a new batch.
TRPO more faithfully enforces a KL trust region. PPO replaces the second-order solve and line search with ordinary minibatch optimization and approximate clipping.
Property
TRPO
PPO
Policy control
Explicit empirical KL check
Pessimistic ratio clipping
Optimizer
Conjugate gradients and line search
SGD or Adam
Batch reuse
One large constrained step
Several minibatch epochs
Constraint fidelity
Higher
Approximate
Implementation complexity
High
Moderate
Practical Diagnosis
PPO is usually the practical default when standard minibatch optimization, accelerator efficiency, and simple distributed rollout collection matter. TRPO is useful when tighter control over policy movement justifies curvature estimation and line search.
The main PPO diagnostics are:
DKL(πold,πθ),clipfrac=B1t∑1[∣ρt−1∣>ϵ],
policy entropy, value loss, and explained variance
EV=1−Var(Vtarget)Var(Vtarget−Vϕ).
Symptom
Likely cause
Useful response
KL rises sharply within an epoch
Learning rate or epoch count is too large
Stop early and reduce inner optimization
Most samples are clipped
Batch is already too off-policy
Use fewer epochs or smaller updates
KL is tiny and clip fraction is near zero
Updates are overly conservative
Increase learning rate or reuse cautiously
Entropy collapses early
Policy becomes deterministic too quickly
Increase entropy regularization or reduce actor updates
Ratios are unstable
Old log-probabilities or policy scale are wrong
Store the denominator once and inspect log-ratios
Policy metrics look healthy but returns fail
Critic advantages are unreliable
Inspect value loss and explained variance
Value loss decreases while policy degrades
Critic is overfitting a stale batch
Reduce critic epochs and collect fresh data
Before trusting a PPO run, verify that old log-probabilities are stored and frozen, advantages and value targets are computed once, terminal and truncation bootstrapping are correct, ratios use log-probability differences, and inner optimization stops when KL becomes excessive.
PPO approximates this constraint with clipped ratios or an adaptive KL penalty. Natural gradients use the Fisher geometry of policy space. TRPO combines that geometry with conjugate gradients and line search. All three aim to extract more learning from each batch without trusting old advantages beyond their local region.