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.13k stars 186 forks source link

GES graph node names issue #128

Closed kenneth-lee-ch closed 8 months ago

kenneth-lee-ch commented 1 year ago

Issue I was trying to use the ges function and evaluate its performance. It throws a KeyError due to None type in node_map inside the graph class output by GES (see 'Error messge'). I am wondering if the ges.py should provide an argument in the class to add nodenames like pc.py. I don't see anywhere in ges.py that updates the argument node_map in the estimated graph class. Since I got the same error with pc.py, but after providing a list of node names to node_names in pc.py, PC was working fine.

Data format snapshot

Screenshot 2023-08-14 at 1 37 15 AM

Code to reproduce

This is the code I used following the guidelines in the TestGES.py

ges_g = ges(X.to_numpy(), score_func='local_score_BDeu', maxP=None, parameters=None)
ges_ac = ArrowConfusion(true_cpdag, ges_g['G'])

Error message

Traceback (most recent call last):
  File "/Users/lee4094/Github/loci-po/experiment.py", line 443, in <module>
    ges_ac = ArrowConfusion(true_cpdag, ges_g['G'])
  File "/Users/lee4094/miniconda3/envs/locipo/lib/python3.10/site-packages/causallearn/graph/ArrowConfusion.py", line 45, in __init__
    if est.get_endpoint(est.get_node(nodes_name[i]), est.get_node(nodes_name[j])) == Endpoint.ARROW:
  File "/Users/lee4094/miniconda3/envs/locipo/lib/python3.10/site-packages/causallearn/graph/GeneralGraph.py", line 615, in get_endpoint
    edge = self.get_edge(node1, node2)
  File "/Users/lee4094/miniconda3/envs/locipo/lib/python3.10/site-packages/causallearn/graph/GeneralGraph.py", line 533, in get_edge
    i = self.node_map[node1]
KeyError: None
kunwuz commented 1 year ago

Thanks so much. Is this #130 (thanks to @Boyle-Coffee and @chenweiDelight) a solution of it?