What is Proximal Policy Optimization (PPO)?

This diagram visualizes how PPO’s clipped objective constrains the policy update using the probability ratio. Updates are unclipped in the trust region [1 - ε, 1 + ε], while ratios outside this band are clipped to limit overly large probability changes and stabilize learning.
Title: PPO Clipping Regions Along the Probability Ratio rtr_t
Source: AIML.com Research

How to Train Agents Without Breaking Them?

In reinforcement learning, an agent learns a policy, its action-selection behavior, and training works by repeatedly updating that policy from experience. The catch is that each update changes the agent’s behavior, which also changes the data it will collect next. If one update is too large, the policy can shift abruptly, the agent starts visiting different states and taking different actions than before, and the next batch of trajectories no longer matches what the update “expected.” That hurts data quality (the experience becomes less useful for the skill you were trying to refine) and corrupts the learning signal (the gradient/advantage you compute from that experience becomes noisy or misleading), which can spiral into more bad updates.

Imagine you are training a dog not to jump on the bed. In RL terms, the dog’s “policy” is its habit when it sees the bed, a “policy update” is how that habit changes after feedback, and “rewards” are treats or attention. If you leave for a week and a caretaker accidentally gives treats whenever the dog jumps on the bed, the dog’s habit quickly shifts toward “jumping is good.” During that week it practices the wrong behavior, and the treats provide a strong but misleading learning signal that reinforces it, so when you return, you are undoing a reinforced habit rather than correcting a small mistake.

This is exactly the kind of problem Proximal Policy Optimization (PPO) is designed to prevent. PPO limits how far the policy is allowed to move in a single update, like putting a speed limit on habit change. So a short burst of misleading feedback is less likely to overwrite what the agent had learned.

A simple analogy for misaligned optimization: the “reward” signal (attention/comfort) can unintentionally reinforce an unhelpful behavior
Title: When feedback reinforces the wrong behavior
Source: AIML.com Research

Trust Region: How Does PPO Limit Updates?

To keep updates from becoming too large, PPO optimizes a clipped surrogate objective. The idea is to improve the policy, but stop rewarding changes once they exceed a small safe range (the “trust region”). This gives PPO its practical stability: learning continues, but extreme one-step updates become unattractive.

A natural question is why we use a surrogate objective instead of optimizing the true RL objective directly. The true objective is long-term reward, but it is hard to differentiate and optimize from finite, noisy trajectories, especially because every policy update changes the data distribution the agent will generate next. A surrogate objective is a practical training target we can compute from the current batch of experience that still pushes the policy in the right direction.

In our dog example, clipping is like making the dog’s habit change gradually: even if it gets an unusually large treat one day, its behavior shifts only a little.  So a temporary period of rewarding bed-jumping does not prevent you from training the dog back to the right behavior.

The Clipped Objective in One Line

$$ L^{\mathrm{CLIP}}(\theta)= \hat{\mathbb{E}}_t\!\left[ \min\!\left( r_t(\theta)\,\hat{A}_t,\; \operatorname{clip}\!\left(r_t(\theta),\,1-\epsilon,\,1+\epsilon\right)\hat{A}_t \right) \right] $$

It combines three elements:

  • The ratio rt(θ)r_t (\theta): measures how much the new policy changes the action probability relative to old policy πθold\pi_{\theta_{old}}.
  • The advantage At^\hat{A_t}: measures whether the sampled action was better or worse than the baseline expectation for that state (typically computed using an actor-critic setup).
  • The clipping operator clip⁡(rt(θ),1−ϵ,1+ϵ)\operatorname{clip}\!\left(r_t(\theta),\,1-\epsilon,\,1+\epsilon\right): caps the effective ratio inside a trust region.
    PPO defines a small tolerance ϵ\epsilon and treats the interval [1−ϵ,1+ϵ][1-\epsilon,\; 1+\epsilon] as the allowable local neighborhood for updates. When rt(θ)r_t (\theta) moves outside this band, PPO suppresses the incentive to push it further.
Two side-by-side line plots showing the PPO clipped surrogate objective as a function of the probability ratio r. In the left plot (advantage positive), the curve increases until it reaches the upper clip boundary and then flattens, indicating no extra benefit from making the action much more likely. In the right plot (advantage negative), the curve decreases until it reaches the lower clip boundary and then flattens, indicating limited penalty for making the action much less likely.
Title: PPO Clipped Surrogate Objective LCLIPL^{CLIP} vs. Probability Ratio rtr_t
Source:J. Schulman, F. Wolski, P. Dhariwal, A. Radford, and O. Klimov, “Proximal Policy Optimization Algorithms”

In code, PPO computes both the unclipped and clipped surrogate terms and then takes the more conservative one:

Python
surr1 = ratios * batch_advantages
surr2 = torch.clamp(ratios, 1.0 - clip_ratio, 1.0 + clip_ratio) * batch_advantages
policy_loss = -torch.min(surr1, surr2).mean()

Here, surr1 is the unclipped term rt(θ)A^tr_t(\theta)\hat{A}_t , and surr2 is the clipped term clip⁡(rt(θ),1−ϵ,1+ϵ)\operatorname{clip}\!\left(r_t(\theta),\,1-\epsilon,\,1+\epsilon\right). The min(·)makes the update conservative: once the ratio would push beyond the clip boundary (in the direction that would increase the objective), PPO uses the clipped value instead, so there is no additional benefit from making the policy change even larger. The leading minus sign turns the maximization objective into a loss to minimize.

Ratio: How Much Did the Policy Change?

In our dog example, we said the dog has its own steady “sense of what’s right”, so its behavior should not change too much from one update to the next. In PPO, we measure this change with the rt(θ)r_t(\theta). This ratio compares the new policy to the old policy by looking at the probability they assign to the same action in the same state. In other words, it tells us how much the update increased or decreased that action’s probability.

$$r_t(\theta) = \frac{\pi_{\theta}(a_t \mid s_t)}{\pi_{\theta_{\text{old}}}(a_t \mid s_t)}.$$
  • If rt(θ)r_t(\theta) > 1, the action ata_t is assigned higher probability under the updated policy.
  • If rt(θ)r_t(\theta) < 1, the action ata_t is assigned lower probability under the updated policy.
  • If rt(θ)r_t(\theta) = 1, no change for action ata_t at that state.

Advantages: Where the Advantage Comes From?

In common PPO implementations, the advantage A^t\hat{A}_t is computed using an actor – critic setup:

  • Actor πθ\pi_{\theta} : the policy network used to select actions.
  • Critic VϕV_{\phi} : estimates the state value and serves as the baseline.

The advantage A^t \hat{A}_t is then constructed by comparing realized returns against the critic’s baseline:

  • If A^t \hat{A}_t > 0, the action performed better than expected →\rightarrow increases its probability (subject to clipping).
  • If A^t \hat{A}_t < 0, the action performed worse than expected →\rightarrow decreases its probability (subject to clipping).

Case Breakdown: What Happens for A^t\hat{A}_t​ in Different Cases?

Advantage (A)Ratio (r)OperationEffect on updateIntuition
Positive (> 0)
Action was good
r > 1 + εClipNo additional gain beyond the clip boundAvoid overconfidence
Positive (> 0)
Action was good
r <= 1 + εUpdateIncrease the probabilitySafe to improve policy
Negative (<0)
Action was bad
r < 1 - εclipNo additional gain beyond the clip boundPrevent collapse
Negative (<0)
Action was bad
r >= 1 - εUpdateDecrease the probabilitySafe to penalize policy

How does ratio clipping looks Like in Practice: Ratio Stability During Training

The plot shows the 95th percentile of the policy ratio across updates. The no-clip run (green) has the largest spikes, the raw ratio in the clipped run (blue) is less spiky, and the clipped ratio (orange) is the smoothest and stays within the shaded safe zone
Title: Policy Ratio Stability With vs. Without Clipping.
Source: AIML.com Research

The plot tracks the 95th percentile of the policy ratio across training updates, 

$$r_t(\theta) = \frac{\pi_{\theta}(a_t \mid s_t)}{\pi_{\theta_{\text{old}}}(a_t \mid s_t)}.$$

where values near 1 mean the policy barely changed for the sampled actions, and large deviations indicate aggressive probability shifts. We focus on the 95th percentile to summarize the “large-change tail” without letting a single extreme outlier dominate. 

The practical lesson is that clipping changes what the optimizer is rewarded for: without clipping, large ratios can keep improving the objective whenever the advantage agrees, so updates sometimes push probabilities far from the behavior policy (green spikes). With PPO, once the ratio approaches the boundary, further pushes stop providing extra objective gain, so extreme updates become unattractive. This reduces the distribution shift between the data used to compute the gradient and the rollouts collected afterward, making advantage estimates more reliable and producing steadier learning rather than sudden swings.

Summary

PPO is widely used because it directly targets a common instability in policy-gradient training: updates that change the policy too much in one step, shifting the data distribution and weakening the learning signal.

The clipped surrogate objective provides a pragmatic trust region effect. It allows policy improvement when supported by the advantage signal, while preventing excessive probability shifts that can trigger collapse. In actor-critic settings, the critic supplies the baseline needed to make those updates directionally meaningful and clipping keeps the resulting policy updates safely bound.

Video Explanation

  • In this video titled “Proximal Policy Optimization | ChatGPT uses this” by CodeEmporium, you’ll learn how PPO works and the fundamental knowledge needed to understand it. The video also includes three small quizzes to help you test your understanding. (Runtime: 13min)
YouTube video
PPO explained by CodeEmporium
  • “Proximal Policy Optimization Explained By Edan Meyer” provides a solid background on reinforcement learning and compares PPO to other algorithms like DQN and TRPO. It also briefly introduces PPO with KL-divergence, noting that it is less commonly used in the industry compared to the standard clipped version. (Runtime: 18min, the most relevant section explaining PPO mechanics, 08:30 – 13:30)
YouTube video
PPO explained by Edan Meyer
  • In the video “Proximal Policy Optimization (PPO) – How to train Large Language Models“ by Serrano Academy, you will be walked through the mechanics of PPO using clear, illustrative examples. The most critical segment is from 33:00 to 37:00, where the core concept of clipping is explained in detail (Runtime: 4 mins starting at 33 mins)
YouTube video
PPO explained by Serrano Academy

Author

Help us improve this post by suggesting in comments below:

– modifications to the text, and infographics
– video resources that offer clear explanations for this question
– code snippets and case studies relevant to this concept
– online blogs, and research publications that are a “must read” on this topic

Leave the first comment

Partner Ad
Find out all the ways that you can
Contribute