Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d67fb5

Browse files
committed
Assume variables are Boolean in fewer places.
1 parent cb069ea commit 5d67fb5

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

probability.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def rejection_sampling(X, e, bn, N):
346346
... burglary, 10000).show_approx()
347347
'False: 0.7, True: 0.3'
348348
"""
349-
counts = {True: 0, False: 0} # boldface N in Fig. 14.14
349+
counts = dict((x, 0) for x in bn.variable_values(X)) # bold N in Fig. 14.14
350350
for j in xrange(N):
351351
sample = prior_sample(bn) # boldface x in Fig. 14.14
352352
if consistent_with(sample, e):
@@ -368,7 +368,7 @@ def likelihood_weighting(X, e, bn, N):
368368
... burglary, 10000).show_approx()
369369
'False: 0.702, True: 0.298'
370370
"""
371-
W = {True: 0.0, False: 0.0}
371+
W = dict((x, 0) for x in bn.variable_values(X))
372372
for j in xrange(N):
373373
sample, weight = weighted_sample(bn, e) # boldface x, w in Fig. 14.15
374374
W[sample[X]] += weight

0 commit comments

Comments
 (0)