v9.1.1
Menu

PPO Clipped Objective (Single Sample)

mediumPROPolicy Gradients and Advantage EstimationReinforcement LearningRL 1: Foundations

Problem Statement

The PPO clipped surrogate for one sample, given the probability ratio r = pi_new/pi_old, advantage A, and clip range eps, is:

L=min⁡(r A,  clip(r,1−ϵ,1+ϵ) A)L = \min\big(r\,A,\; \mathrm{clip}(r, 1-\epsilon, 1+\epsilon)\,A\big)

Implement ppo_clip(r, adv, eps) returning the surrogate value (float). Note the min is taken after multiplying by the advantage.

Example

Input
ppo_clip(1.5, 2.0, 0.2)
Output
2.4
Reasoning
  • Determine the clipping bounds for the probability ratio rr using the range ϵ\epsilon: the lower bound is 1−0.2=0.81 - 0.2 = 0.8 and the upper bound is 1+0.2=1.21 + 0.2 = 1.2.
  • Clip the input ratio r=1.5r = 1.5 to the calculated bounds; since 1.5>1.21.5 > 1.2, the clipped value becomes 1.21.2.
  • Calculate the unclipped surrogate term by multiplying the original ratio by the advantage: 1.5×2.0=3.01.5 \times 2.0 = 3.0.
  • Calculate the clipped surrogate term by multiplying the clipped ratio by the advantage: 1.2×2.0=2.41.2 \times 2.0 = 2.4.
  • Select the minimum of the two surrogate terms to ensure the objective is conservative: min⁡(3.0,2.4)=2.4\min(3.0, 2.4) = 2.4.
  • The final output is 2.4

Constraints

  • r > 0, eps in (0, 1).
  • clip(r, 1-eps, 1+eps) bounds the ratio before the second product.
  • Return a float.

Learn this in

More from RL 1: Foundations

PRO

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test results

Sign in to run your code against the test cases.