All problems
Importance Weight Clipping
Problem
Clip importance weights at max_weight, then rescale them so their mean is 1.
Return zeros when the clipped weights sum to 0; empty input returns [].
Hint
Clipping controls variance at the cost of some bias; renormalizing keeps scale stable.
Test cases
case 1
in: [[1,2,10],3]
expected: [0.5,1,1.5]
case 2
in: [[0,0],5]
expected: [0,0]
case 3
in: [[5],5]
expected: [1]
case 4
in: [[],3]
expected: []
Starter codePython
def clip_and_normalize_weights(weights, max_weight):
# Your code here
pass4 test cases · run your code against them in the editor