All problems
Importance Weight Clipping Bound
Problem
Clip importance weights to the range [0, max_ratio]. A negative max_ratio caps everything at zero. Return the clipped list, or [] for an empty input.
Hint
Clipping importance weights bounds the variance of off-policy estimates.
Test cases
case 1
in: [[0.5,1.5,3],2]
expected: [0.5,1.5,2]
case 2
in: [[1,1],1]
expected: [1,1]
case 3
in: [[-1,0.5],1]
expected: [0,0.5]
case 4
in: [[],1]
expected: []
Starter codePython
def clip_importance_weights(weights, max_ratio):
# Your code here
pass4 test cases · run your code against them in the editor