Skip to content
DeepForgeby svx
All problems

PPO Clip Fraction Diagnostics

Problem

Compute the fraction of probability ratios outside [1 - clip_eps, 1 + clip_eps], a diagnostic for how often PPO's clipping is active. An empty batch returns 0.0.

Hint

A large clip fraction signals that the policy is moving too fast per update.

Test cases

case 1
in: [[1,1.05,0.9,1.3],0.2]
expected: 0.25
case 2
in: [[1,1.1],0.2]
expected: 0
case 3
in: [[],0.2]
expected: 0
case 4
in: [[0.5,1.5,1],0.5]
expected: 0
Starter codePython
def ppo_clip_fraction(ratios, clip_eps):
    # Your code here
    pass

4 test cases · run your code against them in the editor