All problems
Control Variates Estimate
Problem
Control-variate estimator of E[X] using samples_x, samples_y and the known mean of Y. Estimate beta = Cov(X, Y) / Var(Y) with n - 1 denominators, then return mean(X) - beta * (mean(Y) - known_mean_y).
Return mean(X) when the sample is degenerate or Y has zero variance.
Hint
Subtract the control's observed error scaled by the regression coefficient.
Test cases
case 1
in: [[1,2,3,4],[2,4,6,8],5]
expected: 2.5
case 2
in: [[2,4,6,8],[1,2,3,4],2]
expected: 4
case 3
in: [[1,1,1,1],[1,2,3,4],2.5]
expected: 1
case 4
in: [[1,2,3],[1,1,1],2]
expected: 2
Starter codePython
def control_variates_estimate(samples_x, samples_y, known_mean_y):
# Your code here
pass4 test cases · run your code against them in the editor