-
Notifications
You must be signed in to change notification settings - Fork 231
Rewrite CITests as a class && re-use covariance matrix for fisherz #46
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
11e2d90
main change: integrate CITests functions to a class
MarkDana 5794310
Apply changes of cit to PC and MVPC
MarkDana a803c0e
Apply changes of cit to FCI
MarkDana 8da1655
Apply changes of cit to CDNOD
MarkDana a809b9f
data, cache etc. are unnecessary for graph class. removed
MarkDana df9a2b4
remove unnecessary cache from fas
MarkDana f653504
apply changes of cit to SkeletonDiscovery
MarkDana 9ea7945
respective tests to ensure modification on cit makes no logical diffe…
MarkDana 5edd04a
nits: two coding style issues fixed
MarkDana d9e87b0
random seed: two tests w/ or wo/ randomness
MarkDana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| from causallearn.graph.Node import Node | ||
| from causallearn.utils.GraphUtils import GraphUtils | ||
| from causallearn.utils.PCUtils.Helper import list_union, powerset | ||
| from causallearn.utils.cit import CIT | ||
|
|
||
|
|
||
| class CausalGraph: | ||
|
|
@@ -34,10 +35,7 @@ def __init__(self, no_of_var: int, node_names: List[str] | None = None): | |
| for i in range(no_of_var): | ||
| for j in range(i + 1, no_of_var): | ||
| self.G.add_edge(Edge(nodes[i], nodes[j], Endpoint.TAIL, Endpoint.TAIL)) | ||
|
|
||
| self.data = None # store the data | ||
| self.test = None # store the name of the conditional independence test | ||
| self.corr_mat = None # store the correlation matrix of the data | ||
| self.test: CIT | None = None | ||
| self.sepset = np.empty((no_of_var, no_of_var), object) # store the collection of sepsets | ||
| self.definite_UC = [] # store the list of definite unshielded colliders | ||
| self.definite_non_UC = [] # store the list of definite unshielded non-colliders | ||
|
|
@@ -47,35 +45,17 @@ def __init__(self, no_of_var: int, node_names: List[str] | None = None): | |
| self.nx_skel = nx.Graph() # store the undirected graph | ||
| self.labels = {} | ||
| self.prt_m = {} # store the parents of missingness indicators | ||
| self.mvpc = False | ||
| self.cardinalities = None # only works when self.data is discrete, i.e. self.test is chisq or gsq | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
| self.is_discrete = False | ||
| self.citest_cache = dict() | ||
| self.data_hash_key = None | ||
| self.ci_test_hash_key = None | ||
|
|
||
| def set_ind_test(self, indep_test, mvpc=False): | ||
|
|
||
|
|
||
| def set_ind_test(self, indep_test): | ||
| """Set the conditional independence test that will be used""" | ||
| # assert name_of_test in ["Fisher_Z", "Chi_sq", "G_sq"] | ||
| self.mvpc = mvpc | ||
| self.test = indep_test | ||
| self.ci_test_hash_key = hash(indep_test) | ||
|
|
||
| def ci_test(self, i: int, j: int, S) -> float: | ||
| """Define the conditional independence test""" | ||
| # assert i != j and not i in S and not j in S | ||
| if self.mvpc: | ||
| return self.test(self.data, self.nx_skel, self.prt_m, i, j, S) | ||
|
|
||
| i, j = (i, j) if (i < j) else (j, i) | ||
| ijS_key = (i, j, frozenset(S), self.data_hash_key, self.ci_test_hash_key) | ||
| if ijS_key in self.citest_cache: | ||
| return self.citest_cache[ijS_key] | ||
| # if discrete, assert self.test is chisq or gsq, pass into cardinalities | ||
| pValue = self.test(self.data, i, j, S, self.cardinalities) if self.is_discrete \ | ||
| else self.test(self.data, i, j, S) | ||
| self.citest_cache[ijS_key] = pValue | ||
| return pValue | ||
| if self.test.method == 'mc_fisherz': return self.test(i, j, S, self.nx_skel, self.prt_m) | ||
| return self.test(i, j, S) | ||
|
|
||
| def neighbors(self, i: int): | ||
| """Find the neighbors of node i in adjmat""" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
for the attributes you deleted, did you make sure that no code referenced it anymore? :)
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.
I verified this by PyCharm -> Find Usages and there is no other usages in the project.
Is this a reliable way to find usages or do you have any other recommendations?
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.
I don't know. Maybe try it using other variables to see whether it did a great job? Normally these kind of things should rely on simple tests (if we have 100% test coverage hhh) && smart IDE.