New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transient exception when using exact inference #1691
Comments
@fcmwork Thanks for reporting this. This does seem like a bug; I will have a look at it. In the meantime, you could also use Variable Elimination for inference. |
@ankurankan thank you for your prompt answer. Have you been able to reproduce it? I am wondering if you are willing to share a full pipdeptree of your testing environment I could try to figure out if there are any differences. |
@fcmwork I am using the latest versions of all the dependencies. I have been able to reproduce it, the issue seems to be in the initialization of factors of the JunctionTree. The DiscreteFactors in the JunctionTree seem to not have all the state names. In [4]: asia_infer.junction_tree
Out[4]: <pgmpy.models.JunctionTree.JunctionTree at 0x7f3111e1eb00>
In [5]: asia_infer.junction_tree.nodes()
Out[5]: NodeView((('bronc', 'dysp', 'either'), ('bronc', 'xray', 'lung', 'either', 'tub'), ('bronc', 'xray', 'lung', 'asia', 'tub'), ('bronc', 'xray', 'lung', 'asia', 'smoke')))
In [7]: asia_infer.junction_tree.factors
Out[7]:
[<DiscreteFactor representing phi(bronc:2, dysp:2, either:2) at 0x7f3111e5d660>,
<DiscreteFactor representing phi(lung:2, bronc:2, xray:2, either:2, tub:2) at 0x7f3111e5c040>,
<DiscreteFactor representing phi(lung:2, bronc:2, asia:2, xray:2, tub:2) at 0x7f3111e5c160>,
<DiscreteFactor representing phi(lung:2, bronc:2, asia:2, xray:2, smoke:2) at 0x7f3111e5cee0>]
In [8]: asia_infer.junction_tree.factors[0]
Out[8]: <DiscreteFactor representing phi(bronc:2, dysp:2, either:2) at 0x7f3111e5d660>
In [9]: asia_infer.junction_tree.factors[0].state_names
Out[9]: {'bronc': ['yes', 'no'], 'dysp': ['yes', 'no'], 'either': ['yes', 'no']}
In [10]: asia_infer.junction_tree.factors[1].state_names
Out[10]:
{'bronc': [0, 1],
'xray': ['yes', 'no'],
'lung': ['yes', 'no'],
'either': ['yes', 'no'],
'tub': ['yes', 'no']}
In [11]: asia_infer.junction_tree.factors[2].state_names
Out[11]:
{'bronc': [0, 1],
'xray': [0, 1],
'lung': [0, 1],
'asia': ['yes', 'no'],
'tub': ['yes', 'no']}
In [12]: asia_infer.junction_tree.factors[3].state_names
Out[12]:
{'bronc': ['yes', 'no'],
'xray': [0, 1],
'lung': ['yes', 'no'],
'asia': [0, 1],
'smoke': ['yes', 'no']} |
Subject of the issue
Transient exception when using exact inference
I am trying to perform exact inference in a Bayesian network using the Junction Tree algporithm.
However I encounter a transient error when performing the infer.query() call, apparently showing that the subtrees do not have a correct mapping between state name -> state index. Sometime it works, sometimes not, with a rate of about 50% for me. Both pgmpy=0.1.24 and pgmpy==0.1.23
Your environment
Steps to reproduce
The code is taken from the example notebook and is provided below for reproduction.
Expected behaviour
proper return giving the result of the query
+------------+---------+-------------------+
| bronc | asia | phi(bronc,asia) |
+============+=========+===================+
| bronc(yes) | asia(0) | 0.0060 |
+------------+---------+-------------------+
| bronc(yes) | asia(1) | 0.5940 |
+------------+---------+-------------------+
| bronc(no) | asia(0) | 0.0040 |
+------------+---------+-------------------+
| bronc(no) | asia(1) | 0.3960 |
+------------+---------+-------------------+
Actual behaviour
Not systematically but frequently (about 25% of the attempt) I get the following exception. Note that this happens with various forms of query, but seems to get more frequent with more query variables and can reach up to 75%. Note that the example exception is obtained with pgmpy==0.1.24 but is the same with 0.1.23 and also with other python versions
The text was updated successfully, but these errors were encountered: