Skip to content

Commit 21f0549

Browse files
committed
Partly fill in gibbs_ask().
1 parent d22bc74 commit 21f0549

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

probability.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,22 @@ def weighted_sample(bn, e):
392392

393393
def gibbs_ask(X, e, bn, N):
394394
"""[Fig. 14.16]"""
395+
counts = {True: 0, False: 0} # boldface N in Fig. 14.16
396+
Z = [var for var in bn.variables if var not in e]
397+
state = dict(e) # boldface x in Fig. 14.16
398+
for Zi in Z:
399+
state[Zi] = choice([True, False])
400+
for j in xrange(N):
401+
for Zi in Z:
402+
state[Zi] = (random() < P_markov_blanket(Zi, state, bn))
403+
counts[state[X]] += 1
404+
return ProbDist(X, counts)
405+
406+
def P_markov_blanket(X, e, bn):
407+
"""Return P(X | mb) where mb denotes that the variables in the
408+
Markov blanket of X take their values from event e (which must
409+
assign a value to each). The Markov blanket of X is X's parents,
410+
children, and children's parents."""
395411
unimplemented()
396412

397413
#_______________________________________________________________________________

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy