Build the 3-node Burglary→Alarm→Call BBN (prior P(B), CPTs P(A|B), P(C|A)) and compute the posterior P(burglary | call) by enumeration. Print it rounded to 3 decimals.
Build the 3-node Burglary→Alarm→Call BBN (prior P(B), CPTs P(A|B), P(C|A)) and compute the posterior P(burglary | call) by enumeration. Print it rounded to 3 decimals.
Answer
# 3-node BBN: Burglary -> Alarm -> Call (neighbour calls) # Given P(B), P(A|B), P(C|A); compute the posterior P(B | C) by enumeration. P_B = 0.001 # prior P(burglary = true) P_A_given_B = {True: 0.94, False: 0.01} # alarm fires given burglary / not P_C_given_A = {True: 0.90, False: 0.05} # call given alarm / not def joint(b, a, c): pb = P_B if b else (1 - P_B) pa = P_A_given_B[b] if a else (1 - P_A_given_B[b]) pc = P_C_given_A[a] if c else (1 - P_C_given_A[a]) return pb * pa * pc # Numerator: sum over the hidden variable Alarm of P(B=t, A, C=t) num = sum(joint(True, a, True) for a in (True, False)) # Evidence P(C=t): sum over Burglary and Alarm den = sum(joint(b, a, True) for b in (True, False) for a in (True, False)) post = num / den print(f"P(burglary | call) = {round(post, 3)}")