File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -392,6 +392,22 @@ def weighted_sample(bn, e):
392392
393393def 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#_______________________________________________________________________________
You can’t perform that action at this time.
0 commit comments