All problems
Stabilized Weights
Problem
Compute stabilized inverse propensity weights. Let p1 be the treated fraction; treated units get p1/e and controls get (1-p1)/(1-e), with e clipped to [1e-6, 1 - 1e-6].
Return the list of weights; empty input returns [].
Hint
Multiplying by the marginal treatment probability keeps weights near 1.
Test cases
case 1
in: [[1,0],[0.8,0.4]]
expected: [0.625,0.8333333333333334]
case 2
in: [[1,1,0,0],[0.5,0.5,0.5,0.5]]
expected: [1,1,1,1]
case 3
in: [[],[]]
expected: []
Starter codePython
def stabilized_weights(treatment, propensity):
# Your code here
pass3 test cases · run your code against them in the editor