@@ -267,8 +267,8 @@ def sample(self, event):
267
267
def enumeration_ask (X , e , bn ):
268
268
"""Return the conditional probability distribution of variable X
269
269
given evidence e, from BayesNet bn. [Fig. 14.9]
270
- >>> enumeration_ask('Burglary',
271
- ... {'JohnCalls': True, 'MaryCalls': True}, burglary ).show_approx()
270
+ >>> enumeration_ask('Burglary', dict(JohnCalls=T, MaryCalls=T), burglary
271
+ ... ).show_approx()
272
272
'False: 0.716, True: 0.284'"""
273
273
Q = ProbDist (X )
274
274
for xi in bn .variable_values (X ):
@@ -342,9 +342,8 @@ def rejection_sampling(X, e, bn, N):
342
342
Raises a ZeroDivisionError if all the N samples are rejected,
343
343
i.e., inconsistent with e.
344
344
>>> seed(47)
345
- >>> p = rejection_sampling('Burglary',
346
- ... {'JohnCalls': True, 'MaryCalls': True}, burglary, 10000)
347
- >>> p.show_approx()
345
+ >>> rejection_sampling('Burglary', dict(JohnCalls=T, MaryCalls=T),
346
+ ... burglary, 10000).show_approx()
348
347
'False: 0.7, True: 0.3'
349
348
"""
350
349
counts = {True : 0 , False : 0 } # boldface N in Fig. 14.14
@@ -365,9 +364,8 @@ def likelihood_weighting(X, e, bn, N):
365
364
"""Estimate the probability distribution of variable X given
366
365
evidence e in BayesNet bn. [Fig. 14.15]
367
366
>>> seed(1017)
368
- >>> p = likelihood_weighting('Burglary',
369
- ... {'JohnCalls': True, 'MaryCalls': True}, burglary, 10000)
370
- >>> p.show_approx()
367
+ >>> likelihood_weighting('Burglary', dict(JohnCalls=T, MaryCalls=T),
368
+ ... burglary, 10000).show_approx()
371
369
'False: 0.702, True: 0.298'
372
370
"""
373
371
W = {True : 0.0 , False : 0.0 }
0 commit comments