Beispiel #1
0
    def test__example_1_7(self):

        c__given__a__and__b = 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'])
        a = Discrete.binary(0.65, 'A')
        b = Discrete.binary(0.77, 'B')
        a__and__b = a * b
        a__and__b__and__c = a__and__b * c__given__a__and__b
        self.assertAlmostEqual(0.8436, a__and__b__and__c.given(C=0).p(A=1), 4)
Beispiel #2
0
    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))