All problems
Law of Total Variance
Problem
Decompose the variance of X given conditional means, conditional variances and the probabilities of the conditioning events:
Var(X) = E[Var(X | Y)] + Var(E[X | Y]).
All three input lists have the same length. An empty input returns 0.0.
Hint
Compute the overall mean first, then the two variance pieces.
Test cases
case 1
in: [[0,10],[1,1],[0.5,0.5]]
expected: 26
case 2
in: [[2,4],[3,5],[0.25,0.75]]
expected: 5.25
case 3
in: [[1,1,1],[2,3,4],[0.3333333333333333,0.3333333333333333,0.3333333333333333]]
expected: 3
case 4
in: [[],[],[]]
expected: 0
Starter codePython
def law_of_total_variance(cond_means, cond_vars, probs):
# Your code here
pass4 test cases · run your code against them in the editor