Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-311

Control Variate Optimal Coefficient

Problem

The optimal coefficient for the control variate estimator X - b * (Y - E[Y]) is b = Cov(X, Y) / Var(Y). Given samples of the estimator values and the control values, return b using population moments, or 0.0 when there are fewer than two pairs or the control variance is zero.

Hint

Regressing the estimator on the control gives the variance-minimizing coefficient.

Test cases

case 1
in: [[1,2,3],[1,2,3]]
expected: 1
case 2
in: [[1,2,3],[3,2,1]]
expected: -1
case 3
in: [[1,2,3,4],[1,1,2,2]]
expected: 2
case 4
in: [[1,2],[3,3]]
expected: 0
case 5
in: [[1,2],[5]]
expected: 0
Starter codePython
def control_variate_optimal_coefficient(values, controls):
    # Your code here
    pass

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