py-why / causal-learn

Causal Discovery in Python. It also includes (conditional) independence tests and score functions.
https://causal-learn.readthedocs.io/en/latest/
MIT License
1.04k stars 174 forks source link

Fixed indexing error in dag2pag #144

Closed PhilippFaller closed 8 months ago

PhilippFaller commented 8 months ago

The indices in the sepset may not be compatible with the indices used in the PAG, when ruleR3(PAG, sepset, ...) is called. This is, because the indices in the sepset depend on the order of nodes. On the other hand, the indices returned by the PAG.node_map()-call within ruleR3 depend on the order of observed_nodes, which is random, as nodes are converted to a set before being passed to the constructor of the PAG.

This pull request proposes a simple reindexing before the call of ruleR3 and ruleR4b.

kunwuz commented 8 months ago

Thanks for your PR! And thanks so much @zhi-yi-huang for the prompt review :)