py-why / pywhy-graphs

[Experimental] Causal graphs that are networkx-compliant for the py-why ecosystem.
https://py-why.github.io/pywhy-graphs/dev/index.html
MIT License
46 stars 8 forks source link

Convert MAG to PAG #85

Open adam2392 opened 1 year ago

adam2392 commented 1 year ago

Is your feature request related to a problem? Please describe. A MAG is a mixed-edge graph with directed and bidirected edges and has the 'maximality' property.

This is a sub-procedure of https://github.com/py-why/pywhy-graphs/pull/73 and will enable that to function properly.

Describe the solution you'd like Implement a function mag_to_pag, which takes in a valid MAG and outputs the corresponding PAG.

Additional context @aryan26roy if you're still interested, this can be the next step before revisiting #73.

I presume tetrad has a function written in java. More importantly, the paper linked in the issue for #73 should contain the relevant algorithm written in the paper to convert a MAG to a PAG.

aryan26roy commented 1 year ago

@adam2392 I will take this up.

adam2392 commented 1 year ago

Perhaps it might make sense to also add a function that takes in a mixed-edge graph with directed and/or bidirected edges (e.g. an ADMG without undirected edges) and checks if it is a valid MAG.

According to Zhang 2008 (https://www.jmlr.org/papers/volume9/zhang08a/zhang08a.pdf), check:

  1. does graph contain any directed, or almost directed cycles?
  2. between any two non-adjacent nodes, is there an inducing path? (this is now possible because you have implemented the inducing path algorithm)

This is probably pretty expensive because it scales poorly wrt node count, but imo it's fine as long as we document it because I'm not aware of another cheaper way to check if a MAG is valid. I'm sure a way exists using some fancy Breadth-first-search.

aryan26roy commented 1 year ago

@adam2392 so do you want me to add a method for converting PAG to MAG first or the method for checking the validity of an MAG?

adam2392 commented 1 year ago

Perhaps checking validity of a MAG(?). There are some graphical examples in the paper.

aryan26roy commented 1 year ago

Yeah that sounds better to me too.