Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-305

Gibbs Two-Variable Sweep Mean

Problem

For a bivariate Gaussian with means mu1 and mu2, standard deviations sigma1 and sigma2, and correlation rho, one Gibbs sweep first updates the first coordinate given x2, so its mean is mu1 + rho * (sigma1 / sigma2) * (x2 - mu2). The second coordinate then updates from that mean, giving mu2 + rho * (sigma2 / sigma1) * (first_mean - mu1) after taking its expectation. Return [first_mean, second_mean], or [0.0, 0.0] for invalid parameters.

Hint

Apply the bivariate conditional mean formula twice, with the second step averaging over the first update.

Test cases

case 1
in: [0,0,1,1,0.5,2]
expected: [1,0.5]
case 2
in: [1,2,2,1,0.5,3]
expected: [2,2.25]
case 3
in: [0,0,1,2,0.8,4]
expected: [1.6,2.5600000000000005]
case 4
in: [3,3,1,1,0,7]
expected: [3,3]
case 5
in: [0,0,1,1,1.5,1]
expected: [0,0]
Starter codePython
def gibbs_sweep_mean(mu1, mu2, sigma1, sigma2, rho, x2):
    # Your code here
    pass

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