Skip to content
DeepForgeby svx
All problems

Importance Sampling Variance

Problem

Estimate the variance of the importance-sampling return estimator from samples of weight times return: Var = E[(wG)^2] - E[wG]^2. An empty batch returns 0.0.

Hint

Large importance weights inflate estimator variance quickly.

Test cases

case 1
in: [[1,1],[1,3]]
expected: 1
case 2
in: [[0.5,2],[2,1]]
expected: 0.25
case 3
in: [[1],[5]]
expected: 0
case 4
in: [[],[]]
expected: 0
Starter codePython
def importance_sampling_variance(weights, returns):
    # Your code here
    pass

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