@@ -228,7 +228,7 @@ def __init__(self, X, parents, cpt):
228228
229229 def p (self , value , event ):
230230 """Return the conditional probability
231- P(X=value | parents = parent_values), where parent_values
231+ P(X=value | parents= parent_values), where parent_values
232232 are the values of parents in event. (event must assign each
233233 parent a value.)
234234 >>> bn = BayesNode('X', 'Burglary', {T: 0.2, F: 0.625})
@@ -241,8 +241,8 @@ def p(self, value, event):
241241 def sample (self , event ):
242242 """Sample from the distribution for this variable conditioned
243243 on event's values for parent_vars. That is, return True/False
244- at random according with the conditional probability given
245- event ."""
244+ at random according with the conditional probability given the
245+ parents ."""
246246 return random () <= self .p (True , event )
247247
248248node = BayesNode
@@ -289,22 +289,27 @@ def enumerate_all(vars, e, bn):
289289 for y in bn .variable_values (Y ))
290290
291291#______________________________________________________________________________
292- # elimination_ask: implementation is incomplete
293292
294- def elimination_ask (X , e , bn ):
293+ def elimination_ask (X , e , bn , order = reversed ):
295294 "[Fig. 14.11]"
296295 factors = []
297- for var in reverse (bn .vars ):
296+ for var in order (bn .vars ):
298297 factors .append (Factor (var , e ))
299298 if is_hidden (var , X , e ):
300299 factors = sum_out (var , factors )
301300 return pointwise_product (factors ).normalize ()
302301
302+ def is_hidden (var , X , e ):
303+ return var != X and var not in e
304+
305+ def Factor (var , e ):
306+ NotImplemented
307+
303308def pointwise_product (factors ):
304- pass
309+ NotImplemented
305310
306311def sum_out (var , factors ):
307- pass
312+ NotImplemented
308313
309314#______________________________________________________________________________
310315
0 commit comments