All problems
Control Variate Adjusted Estimate
Problem
A control variate estimator is mean(f) - c * (mean(h) - mu_h), where mu_h is the known expectation of the control. For the optimal coefficient c = Cov(f, h) / Var(h), the covariance is Cov(f, h) / Var(h).
Given samples of f, samples of h, the known mean of h, and the coefficient c (default 1.0), return the adjusted estimate.
Hint
Subtract the scaled discrepancy between the sample and known control means.
Test cases
case 1
in: [[1,2,3],[0.5,1,1.5],1]
expected: 2
case 2
in: [[2,4],[1,3],3,0.5]
expected: 3.5
case 3
in: [[0,0],[5,5],5]
expected: 0
Starter codePython
def control_variate_adjusted_estimate(f_samples, h_samples, h_mean, c=1.0):
# Your code here
pass3 test cases · run your code against them in the editor