All problems
Self-Normalized Importance Sampling Estimate
Problem
Self-normalized importance sampling estimates E[f(X)] as the weighted average of sampled values using weights target[sample] / proposal[sample]. Return sum(weight * value) / sum(weight) over the given sample indices. Return 0.0 for empty or invalid arguments.
Hint
Normalizing by the total weight removes the need to know the target's normalizing constant.
Test cases
case 1
in: [[1,2,3],[0.2,0.3,0.5],[0.5,0.25,0.25],[0,1,2]]
expected: 2.4444444444444446
case 2
in: [[1,2],[0.5,0.5],[0.5,0.5],[0,0,1]]
expected: 1.3333333333333333
case 3
in: [[2,4],[0.25,0.75],[0.5,0.5],[1,1]]
expected: 4
case 4
in: [[1],[1],[1],[]]
expected: 0
case 5
in: [[1,2],[0.5,0.5],[0.5,0.5],[5]]
expected: 0
Starter codePython
def self_normalized_is_estimate(values, target, proposal, samples):
# Your code here
pass5 test cases · run your code against them in the editor