pgmpy / pgmpy

Python Library for learning (Structure and Parameter), inference (Probabilistic and Causal), and simulations in Bayesian Networks.

Home Page:https://pgmpy.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`DAG.get_independencies()` improvements

behrman opened this issue · comments

For the study questions in the book

J Pearl, M Glymour, NP Jewell. Causal Inference in Statistics: A Primer. Wiley, 2016.

I've created

Independencies play a central role in working with DAGs, and of the nine questions from the book involving independencies, the dagitty function impliedConditionalIndependencies() was able to solve all nine, while the pgmpy method DAG.get_independencies() was unable to solve any. The computation required for get_independencies() grows exponentially in the number of graph nodes, limiting it to small graphs. And even for small graphs, its exponential output is not very useful.

impliedConditionalIndependencies() (doc, pp. 17 - 18) is very well designed. If get_independencies() had the same default behavior as impliedConditionalIndependencies(), it would not require exponential computation, and it would be much more useful. It would be able to solve eight of the nine questions.

As a start to such an implementation, see (notebook, cell 14). To provide the full functionality of impliedConditionalIndependencies(), DAG would need a minimal_dseparators() method to provide all minimal d-separators. Then independence assertions could be added for each minimal d-separator. dagitty computes all minimal d-separators using the JavaScript function GraphAnalyzer.listMinimalSeparators() (code, lines 1143 - 1182), which implements Takata's algorithm.

Like impliedConditionalIndependencies(), my code orders independencies in the sorted order of the node pairs. Like impliedConditionalIndependencies(), it would also be good to print the assertion sets in sorted order.

@ankurankan

@behrman Thanks for pointing it out and the notebook. I will try to integrate that into the codebase, or you are also very welcome to open a pull request if you would like.

@ankurankan I just noticed that I failed to link to the code for the JavaScipt function GraphAnalyzer.listMinimalSeparators(). It's: (code, lines 1143 - 1182). The code looks straightforward, but as someone who does not understand the pgmpy codebase at all, I think I should leave the update to someone else.

Thanks so much for all you do!