All problems
Bayesian Network Joint Probability
Problem
For a binary Bayesian network, each node i has parents parents[i] and conditional probability table cpts[i]. Rows of cpts[i] are indexed by the parent configuration, where the first parent is the least significant bit of the binary index, and columns are the node's probability of being 0 or 1. Return the joint probability of assignment, or 0.0 when shapes are invalid.
Hint
Multiply the conditional probability of each node given its parents' assigned values.
Test cases
case 1
in: [[[],[0]],[[[0.6,0.4]],[[0.9,0.1],[0.2,0.8]]],[0,1]]
expected: 0.06
case 2
in: [[[],[0]],[[[0.6,0.4]],[[0.9,0.1],[0.2,0.8]]],[1,1]]
expected: 0.32000000000000006
case 3
in: [[[],[0]],[[[0.6,0.4]],[[0.9,0.1],[0.2,0.8]]],[1,0]]
expected: 0.08000000000000002
case 4
in: [[[],[],[0,1]],[[[0.5,0.5]],[[0.8,0.2]],[[0.1,0.9],[0.6,0.4],[0.2,0.8],[0.7,0.3]]],[1,0,0]]
expected: 0.24
case 5
in: [[[],[0]],[[[0.6,0.4]],[[0.9,0.1],[0.2,0.8]]],[]]
expected: 0
Starter codePython
def bayesian_network_joint_probability(parents, cpts, assignment):
# Your code here
pass5 test cases · run your code against them in the editor