def test_binary_from_probs(self): c__a_b__1 = Conditional.from_probs( data={ (1, 0, 0): 0.1, (1, 0, 1): 0.99, (1, 1, 0): 0.8, (1, 1, 1): 0.25, (0, 0, 0): 1 - 0.1, (0, 0, 1): 1 - 0.99, (0, 1, 0): 1 - 0.8, (0, 1, 1): 1 - 0.25, }, joint_variables='C', conditional_variables=['A', 'B'] ).data c__a_b__2 = Conditional.binary_from_probs( data={ (0, 0): 0.1, (0, 1): 0.99, (1, 0): 0.8, (1, 1): 0.25, }, joint_variable='C', conditional_variables=['A', 'B'] ).data self.assertTrue(c__a_b__1.equals(c__a_b__2))
def test_given_one_variable(self): expected = Conditional.binary_from_probs( data={ 0: 0, 1: 1, }, joint_variable='A_xor_B', conditional_variables='B').data xor = Conditional.binary_from_probs(data={ (0, 0): 0, (0, 1): 1, (1, 0): 1, (1, 1): 0, }, joint_variable='A_xor_B', conditional_variables=['A', 'B']) actual = xor.given(A=0).data self.assertTrue(expected.equals(actual))
def test_given_all_variables(self): expected = Discrete.binary(0, 'A_xor_B').data xor = Conditional.binary_from_probs(data={ (0, 0): 0, (0, 1): 1, (1, 0): 1, (1, 1): 0, }, joint_variable='A_xor_B', conditional_variables=['A', 'B']) actual = xor.given(A=1, B=1).data self.assertTrue(expected.equals(actual))