From 86bd6076aef481d8363524234b4292e31d2f0839 Mon Sep 17 00:00:00 2001 From: Steven Yang Date: Thu, 16 Mar 2023 14:22:48 -0700 Subject: [PATCH] Fix bug in all_events In case any `variables` exist in `e`, the former implementation would generate wrong results. ```py all_events("Alarm", alarm_net, {"Earthquake": F}) # before, would yield event with E: F ``` --- probability4e.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/probability4e.py b/probability4e.py index d413a55ae..c2068af44 100644 --- a/probability4e.py +++ b/probability4e.py @@ -591,9 +591,12 @@ def all_events(variables, bn, e): else: X, rest = variables[0], variables[1:] for e1 in all_events(rest, bn, e): - for x in bn.variable_values(X): - yield extend(e1, X, x) - + if X in e: + yield e1 + else: + for x in bn.variable_values(X): + yield extend(e1, X, x) + # ______________________________________________________________________________ # 13.3.4 Clustering algorithms