-
Notifications
You must be signed in to change notification settings - Fork 231
Refactored unit tests for FCI #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
tofuwen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for your awesome work!!! :)
| if self.existsSemidirectedPath(node_r, node_x, graph) or self.existsSemidirectedPath(node_r, node_b, graph): | ||
| if self.existOnePathWithPossibleParents(previous, node_r, node_x, node_b, graph): | ||
| return True | ||
| return True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems the code logic got changed here.....
Is it because our original implementation has bug?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this will cause "RecursionError: maximum recursion depth exceeded while calling a Python object". And I compared the code in Tetrad and it seems that these two lines of code are not needed.
tests/TestFCI.py
Outdated
| from causallearn.utils.GraphUtils import GraphUtils | ||
| from causallearn.utils.PCUtils.BackgroundKnowledge import BackgroundKnowledge | ||
|
|
||
| sys.path.append("") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests/TestFCI.py
Outdated
| ground_truth_dag.add_directed_edge(ground_truth_nodes[0], ground_truth_nodes[1]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[0], ground_truth_nodes[2]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[1], ground_truth_nodes[3]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[2], ground_truth_nodes[3]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please do a for loop here, instead of manually add every edge.
e.g.
for node_1, node2 in [(0, 1), (0, 2), (1, 3), (2, 3)]:
ground_truth_dag.add_directed_edge(ground_truth_nodes[node_1], ground_truth_nodes[node_1])
tests/TestFCI.py
Outdated
| ground_truth_dag.add_directed_edge(ground_truth_nodes[7], ground_truth_nodes[0]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[7], ground_truth_nodes[1]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[8], ground_truth_nodes[3]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[8], ground_truth_nodes[4]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[2], ground_truth_nodes[5]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[2], ground_truth_nodes[6]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[5], ground_truth_nodes[1]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[6], ground_truth_nodes[3]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[3], ground_truth_nodes[0]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[1], ground_truth_nodes[4]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, maybe use for loop
tests/TestFCI.py
Outdated
| ground_truth_dag.add_directed_edge(ground_truth_nodes[0], ground_truth_nodes[2]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[1], ground_truth_nodes[2]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[2], ground_truth_nodes[3]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[2], ground_truth_nodes[4]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
tests/TestFCI.py
Outdated
| ground_truth_dag.add_directed_edge(ground_truth_nodes[7], ground_truth_nodes[0]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[7], ground_truth_nodes[5]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[8], ground_truth_nodes[0]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[8], ground_truth_nodes[6]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[9], ground_truth_nodes[3]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[9], ground_truth_nodes[4]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[9], ground_truth_nodes[6]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[0], ground_truth_nodes[1]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[0], ground_truth_nodes[2]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[1], ground_truth_nodes[2]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[2], ground_truth_nodes[4]) | ||
| ground_truth_dag.add_directed_edge(ground_truth_nodes[5], ground_truth_nodes[6]) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
|
btw, could you update your description to contain more details on the bug you fixed? We should write a better descriptions in general (i.e. for every possible PRs) for people who check this PR later. |
|
...Someone must have been concerned about cycles in the graph.
Joe
…On Mon, Sep 5, 2022 at 1:54 AM Zhiyi Huang ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In causallearn/search/ConstraintBased/FCI.py
<#68 (comment)>:
> @@ -82,8 +82,7 @@ def existOnePathWithPossibleParents(self, previous, node_w: Node, node_x: Node,
continue
if self.existsSemidirectedPath(node_r, node_x, graph) or self.existsSemidirectedPath(node_r, node_b, graph):
- if self.existOnePathWithPossibleParents(previous, node_r, node_x, node_b, graph):
- return True
+ return True
Yes, this will cause "RecursionError: maximum recursion depth exceeded
while calling a Python object". And I compared the code
<https://github.com/cmu-phil/tetrad/blob/70b0506af635d4f8906b3e29124bb5d01343768b/tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java#L4768>
in Tetrad and it seems that these two lines of code are not needed.
—
Reply to this email directly, view it on GitHub
<#68 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACLFSRYJIX6MW4YIGG7ELWLV4WDJZANCNFSM56N3OPEQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
|
Yeah, I share the same concern as Joe. Could you please ask the owner (or whoever familiar with the code) about the context why we need Someone added this previously before, so I guess very likely it's for fixing some bugs. And by removing this line, it's likely you are introducing new bugs. So we better get to know the context and figure out the solutions instead of directly deleting it. |
|
@zhi-yi-huang any updates regarding this PR? :) Sorry for the late reply though hhhh |
|
Sorry, I was a little busy a while ago. The latest code has been pushed to GitHub. Special thanks to @jdramsey @chenweiDelight @wean2016 for helping to fix FCI and Fas algorithm. |
|
Thanks for the awesome work, @zhi-yi-huang !!!! This is great and really non-trivial, you fixed a tons of bugs that makes the package significantly better! One final thing: since you changed GeneralGraph.py, could you run all other tests to make sure your changes doesn't break any other tests? After all tests passed, I think we are ready to push this PR. cc @kunwuz I think we should work on enabling auto tests for all our PR. Could you do some research to see how we can enable this for our packages? :) |
Sure, I will explore it in the near future. Btw, since I'm not very familiar with that, any suggestions (perhaps based on previous experiences) are super welcome. For this PR, maybe we could push it after finishing some necessary tests that @zhi-yi-huang and @tofuwen think could be necessary. |
|
yeah, for this PR, after @zhi-yi-huang run all other tests, we can push it. |
|
@MarkDana could you help review the failed PC tests in this PR? :) |
|
@tofuwen Oh thanks for reminding! Will do it later tomorrow. |
|
@zhi-yi-huang Seems that this pr contains changes of the following aspects (correct me if I have misunderstandings):
The problem that causes failed tests on PC should be in 2 I guess:
I didn't check details into your modified graph operations, but maybe you could start from this. Also, just a kind reminder - after bugs about graphs are fixed, we need to regenerate all benchmark files (e.g., Thanks a lot 🍺! |
|
@zhi-yi-huang any updates? :) Did you find the bug? Hopefully to merge this PR in the near future to make causal-learn better! |
|
The problem that causes failed tests on PC should be in The original After updating to the |
|
@zhi-yi-huang Thanks so much for your awesome! I can definitely see you spent lots of efforts on this PR and this is definitely not a trivial task. Just to make sure, the current PR can pass ALL of our tests, right? (NOT just PC test and your new test) cc @MarkDana to review PC related |
|
Hi @zhi-yi-huang Thanks for your efforts! Could you please commit your changes (e.g., |
|
There are some tests that fail:
These tests do not pass in the main branch code either. And it doesn't look like the changed in this PR affects these tests.
|
|
Hi all, since this PR has already been for a while, please let me know if there is anything else before we can merge this. |
|
H @kunwuz! @zhi-yi-huang identified some flaws in the original Thanks so much everyone (especially @zhi-yi-huang ) for your efforts! |
Signed-off-by: ZhiyiHuang <huangzhiyi.chn@gmail.com>
Signed-off-by: ZhiyiHuang <huangzhiyi.chn@gmail.com>
Signed-off-by: ZhiyiHuang <huangzhiyi.chn@gmail.com>
Signed-off-by: ZhiyiHuang <huangzhiyi.chn@gmail.com>
Signed-off-by: ZhiyiHuang <huangzhiyi.chn@gmail.com>
Signed-off-by: wean2016 <weanyq@gmail.com> Signed-off-by: ZhiyiHuang <huangzhiyi.chn@gmail.com>
Signed-off-by: wean2016 <weanyq@gmail.com> Signed-off-by: ZhiyiHuang <huangzhiyi.chn@gmail.com>
Signed-off-by: wean2016 <weanyq@gmail.com> Signed-off-by: ZhiyiHuang <huangzhiyi.chn@gmail.com>
Signed-off-by: wean2016 <weanyq@gmail.com> Signed-off-by: ZhiyiHuang <huangzhiyi.chn@gmail.com>
|
Hi @zhi-yi-huang Awesome! I just reviewed this pr and it is good to me. As an additional check, all modifications on the benchmark CPDAG results are in the form @kunwuz I think this pr is ready to go!! Thanks everyone (especially @zhi-yi-huang) for your efforts!! Thanks 🍺🍺 |
Updates
Description
previousin function getPossibleDsep is not updated.dpathis used to record whether there is a directed path between two variables. But the previous implementation does not determine whether the edges are fully directed or not.remove_edgefunction, not every call of functionremove_edgeneeds to reconstitutedpath, it only has an effect ondpathwhen a directed edge is removed. In order to reduce unnecessary reconstruction, so I made a modification to theremove_edgefunction.Test Plan
python -m unittest tests.TestFCI # should passpython -m unittest tests.TestPC # should pass