Skip to main content
MahiDev — Learn. Build. Become AI-ready.

Lesson 68

Trust Region Policy Optimization

Constrain a policy update so the new policy stays inside a small KL divergence of the old one. One example is on this page.

Intermediate12 min
Trust Region Policy Optimization MahiDev

What You Will Learn

  • Idea
  • Example
  • When to use it

Idea

TRPO maximizes the advantage under a hard trust region. The region is a maximum KL divergence between the old action probabilities and the new ones. If a proposed step would change the policy too much, the step is shortened. PPO's clip is a simpler stand-in for this constraint.

Example

python
import math

old = [0.7, 0.3]
new = [0.6, 0.4]
kl = sum(m * math.log(m / p) for m, p in zip(old, new))
print(f"kl: {kl:.4f}")

Output:

text
kl: 0.0216

When to use it

  • Use it when you need a measured guarantee that the policy moved only a little.
  • The KL above is the divergence from the old action probabilities to the new ones.
  • PPO is the practical alternative when the conjugate-gradient step is more machinery than you want.

Loading playground…