Skip to content
DeepForgeby svx
All problems
HardProbabilitypr-043

Pairwise vs Mutual Independence

Problem

Check pairwise and mutual independence of three events.

probs = [P(A), P(B), P(C)] and joints = [P(A and B), P(A and C), P(B and C), P(A and B and C)]. Return a dictionary with boolean keys pairwise and mutual: pairwise holds when each pair product matches its joint within 1e-9, and mutual also requires P(A and B and C) = P(A) * P(B) * P(C).

Hint

Pairwise independence does not imply mutual independence.

Test cases

case 1
in: [[0.5,0.5,0.5],[0.25,0.25,0.25,0.125]]
expected: {"pairwise":true,"mutual":true}
case 2
in: [[0.5,0.5,0.5],[0.25,0.25,0.25,0]]
expected: {"pairwise":true,"mutual":false}
case 3
in: [[0.5,0.5,0.5],[0.3,0.25,0.25,0.125]]
expected: {"pairwise":false,"mutual":false}
case 4
in: [[0.2,0.4,0.5],[0.08,0.1,0.2,0.04]]
expected: {"pairwise":true,"mutual":true}
Starter codePython
def pairwise_and_mutual_independence(probs, joints):
    # Your code here
    pass

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