@@ -10,13 +10,6 @@ def tests():
10
10
assert cpt .p (True , event ) == 0.95
11
11
event = {'Burglary' : False , 'Earthquake' : True }
12
12
assert cpt .p (False , event ) == 0.71
13
- # assert BoolCPT({T: 0.2, F: 0.625}).p(False, ['Burglary'], event) == 0.375
14
- # assert BoolCPT(0.75).p(False, [], {}) == 0.25
15
- # cpt = BoolCPT({True: 0.2, False: 0.7})
16
- # assert cpt.rand(['A'], {'A': True}) in [True, False]
17
- # cpt = BoolCPT({(True, True): 0.1, (True, False): 0.3,
18
- # (False, True): 0.5, (False, False): 0.7})
19
- # assert cpt.rand(['A', 'B'], {'A': True, 'B': False}) in [True, False]
20
13
# #enumeration_ask('Earthquake', {}, burglary)
21
14
22
15
s = {'A' : True , 'B' : False , 'C' : True , 'D' : False }
@@ -87,6 +80,15 @@ def test_enumerate_joint_ask():
87
80
def test_bayesnode_p ():
88
81
bn = BayesNode ('X' , 'Burglary' , {T : 0.2 , F : 0.625 })
89
82
assert bn .p (False , {'Burglary' : False , 'Earthquake' : True }) == 0.375
83
+ assert BayesNode ('W' , '' , 0.75 ).p (False , {'Random' : True }) == 0.25
84
+
85
+
86
+ def test_bayesnode_sample ():
87
+ X = BayesNode ('X' , 'Burglary' , {T : 0.2 , F : 0.625 })
88
+ assert X .sample ({'Burglary' : False , 'Earthquake' : True }) in [True , False ]
89
+ Z = BayesNode ('Z' , 'P Q' , {(True , True ): 0.2 , (True , False ): 0.3 ,
90
+ (False , True ): 0.5 , (False , False ): 0.7 })
91
+ assert Z .sample ({'P' : True , 'Q' : False }) in [True , False ]
90
92
91
93
92
94
def test_enumeration_ask ():
0 commit comments