Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-314

Conditional Gaussian Mean and Variance

Problem

For a bivariate Gaussian with mean [mu1, mu2] and covariance [[s11, s12], [s12, s22]], the conditional distribution of the first coordinate given that the second equals x2 is Gaussian with mean mu1 + (s12 / s22) * (x2 - mu2) and variance s11 - s12^2 / s22. Return [conditional mean, conditional variance], clamping a negative variance to 0.0 and returning [0.0, 0.0] for invalid shapes or nonpositive marginal variances.

Hint

The conditional variance does not depend on the observed value.

Test cases

case 1
in: [[0,0],[[1,0.5],[0.5,1]],1]
expected: [0.5,0.75]
case 2
in: [[1,2],[[2,1],[1,2]],3]
expected: [1.5,1.5]
case 3
in: [[0,0],[[1,0],[0,1]],5]
expected: [0,1]
case 4
in: [[2,1],[[4,-1],[-1,2]],0.5]
expected: [2.25,3.5]
case 5
in: [[0,0],[[1,2],[2,1]],1]
expected: [2,0]
Starter codePython
def conditional_gaussian_moments(mu, covariance, x2):
    # Your code here
    pass

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