Issue with Causal Inference query() in last version (0.1.21)
jaimeperezsanchez opened this issue · comments
Subject of the issue
I was trying out some Causal Inference stuff, and using the query() function I get NaN probabilities.
This occurs in version 0.1.21. I have tried version 0.1.19 and the error does not occur there.
Your environment
- pgmpy version = 0.1.21
- Python version = Python 3.8.16
- Operating System = Ubuntu (Google Colab)
Steps to reproduce
from pgmpy.inference import CausalInference
causal_model = CausalInference(DAG_model)
#DAG_model is an instance of BayesianNetwork (from pgmpy.models) that has been fited with some data using Maximum Likelihood Estimator
do_results = causal_model.query(["Output"], do={'Treatment': 1}, adjustment_set=["X", "Y"])
print(do_results)
I have created a simple notebook in Google Colab where you can run the example with the data I am using: link to the notebook
Expected behaviour
Something like
+-----------+-----------------+
| Output | phi(Output) |
+======+========+
| Output(0) | 0.7884 |
+-----------+-----------------+
| Output(1) | 0.2116 |
+-----------+-----------------+
Actual behaviour
+-----------+-----------------+
| Output | phi(Output) |
+======+========+
| Output(0) | nan |
+-----------+-----------------+
| Output(1) | nan |
+-----------+-----------------+
@jaimeperezsanchez Thanks for reporting this. Seems to be a bug in the inference algorithm, looking into it.
@ankurankan In case it helps with debuggin, I'm having similar issues in Version 0.1.23, and traced it back to the "greedy" elimination order used in the ExactInference query method. If I override the default elimination_order parameter with other options, I get numbers instead of NaNs.
@gweesip I think this issue was fixed in v0.1.24. Could you try updating pgmpy? If you still see the error, could you share your code so that I can reproduce the issue.
@ankurankan Updated and no more issues. Thanks!