All problems
Importance Sampling Weights
Problem
Importance sampling corrects samples drawn from proposal to the target distribution by the ratio target[i] / proposal[i]. Return the list of importance weights for equal-length vectors, or an empty list when the inputs are empty, mismatched, or any proposal probability is nonpositive.
Hint
A weight above 1 means the target assigns more mass than the proposal there.
Test cases
case 1
in: [[0.5,0.5],[0.5,0.5]]
expected: [1,1]
case 2
in: [[0.2,0.8],[0.5,0.5]]
expected: [0.4,1.6]
case 3
in: [[0.1,0.9],[0.25,0.75]]
expected: [0.4,1.2]
case 4
in: [[],[]]
expected: []
case 5
in: [[1,0],[0,1]]
expected: []
Starter codePython
def importance_sampling_weights(target, proposal):
# Your code here
pass5 test cases · run your code against them in the editor