Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-344

Self-Normalized IPS Estimate

Problem

Compute the self-normalized inverse propensity score estimate: sum(w * reward) / sum(w) with w = target_prob / behavior_prob and behavior_prob clipped to at least 1e-6. Return 0.0 when the weights sum to 0 or the input is empty.

Hint

Dividing by the sum of the weights keeps the estimate stable when importance weights explode.

Test cases

case 1
in: [[1,0,2],[0.5,0.5,0.4],[0.7,0.3,0.5]]
expected: 1.2
case 2
in: [[1],[0.25],[1]]
expected: 1
case 3
in: [[0,0],[1,1],[0.5,0.5]]
expected: 0
case 4
in: [[],[],[]]
expected: 0
Starter codePython
def snips_estimate(rewards, behavior_probs, target_probs):
    # Your code here
    pass

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