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

Skip to content

Commit cb069ea

Browse files
committed
Some more-readable doctests.
1 parent d7fbe0d commit cb069ea

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

probability.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ def sample(self, event):
267267
def enumeration_ask(X, e, bn):
268268
"""Return the conditional probability distribution of variable X
269269
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()
272272
'False: 0.716, True: 0.284'"""
273273
Q = ProbDist(X)
274274
for xi in bn.variable_values(X):
@@ -342,9 +342,8 @@ def rejection_sampling(X, e, bn, N):
342342
Raises a ZeroDivisionError if all the N samples are rejected,
343343
i.e., inconsistent with e.
344344
>>> 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()
348347
'False: 0.7, True: 0.3'
349348
"""
350349
counts = {True: 0, False: 0} # boldface N in Fig. 14.14
@@ -365,9 +364,8 @@ def likelihood_weighting(X, e, bn, N):
365364
"""Estimate the probability distribution of variable X given
366365
evidence e in BayesNet bn. [Fig. 14.15]
367366
>>> 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()
371369
'False: 0.702, True: 0.298'
372370
"""
373371
W = {True: 0.0, False: 0.0}

0 commit comments

Comments
 (0)