-
Notifications
You must be signed in to change notification settings - Fork 18
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
numpy style docstrings #84
Merged
robertness
merged 1 commit into
py-why:GIN-algorithm
from
HarshaSatyavardhan:GIN-algorithm
Jan 11, 2023
Merged
Changes from all commits
Commits
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 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 |
---|---|---|
|
@@ -3,19 +3,30 @@ | |
TODO: Need type hints | ||
""" | ||
from causallearn.search.HiddenCausal.GIN.GIN import GIN as GIN_ | ||
|
||
from pywhy_graphs import CPDAG | ||
|
||
class GIN: | ||
"""Wrapper for GIN in the causal-learn package. | ||
|
||
Parameters | ||
---------- | ||
indep_test_method : str | ||
The method to use for testing independence, by default "kci" | ||
alpha : float | ||
The significance level for independence tests, by default 0.05 | ||
|
||
Attributes | ||
---------- | ||
graph_ : CPDAG | ||
The estimated causal graph. | ||
causal_learn_graph : CausalGraph | ||
The causal graph object from causal-learn. | ||
causal_ordering : list of str | ||
The causal ordering of the variables. | ||
""" | ||
Dodiscover wrapper for GIN in causal-learn package | ||
""" | ||
def __init__(self, indep_test_method="kci", alpha=0.05): | ||
""" | ||
Using default parameters from GIN. | ||
TODO: Add full set of GIN parameters with default | ||
TODO: Add a base class | ||
""" | ||
def __init__(self, indep_test_method: str="kci", alpha: float=0.05): | ||
"""Initialize GIN object with specified parameters.""" | ||
|
||
self.graph_ = None # Should be in a base class | ||
|
||
# GIN default parameters. | ||
|
@@ -27,8 +38,33 @@ def __init__(self, indep_test_method="kci", alpha=0.05): | |
self.causal_ordering = None | ||
|
||
def _causal_learn_to_pdag(self, cl_graph): | ||
"""""" | ||
"""Convert a causal-learn graph to a CPDAG object. | ||
|
||
Parameters | ||
---------- | ||
cl_graph : CausalGraph | ||
The causal-learn graph to be converted. | ||
|
||
Returns | ||
------- | ||
pdag : CPDAG | ||
The equivalent CPDAG object. | ||
""" | ||
def _extract_edgelists(adj_mat, names): | ||
"""Extracts directed and undirected edges from an adjacency matrix. | ||
|
||
Parameters: | ||
- adj_mat: numpy array | ||
The adjacency matrix of the graph. | ||
- names: list of str | ||
The names of the nodes in the graph. | ||
|
||
Returns: | ||
- directed_edges: list of tuples | ||
The directed edges of the graph. | ||
- undirected_edges: list of sets | ||
The undirected edges of the graph. | ||
""" | ||
directed_edges = [] | ||
undirected_edges = [] | ||
for i, row in enumerate(adj_mat): | ||
|
@@ -51,8 +87,21 @@ def _extract_edgelists(adj_mat, names): | |
return pdag | ||
|
||
|
||
def fit(self, data, context): | ||
def fit(self, data: 'DataFrame', context: 'DataFrame'): | ||
"""Fit to data. | ||
|
||
Parameters | ||
---------- | ||
data : DataFrame | ||
The data to fit to. | ||
context : DataFrame | ||
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. see comment above |
||
The context variables to use as constraints. | ||
|
||
Returns | ||
------- | ||
self : GIN | ||
The fitted GIN object. | ||
|
||
TODO: How to apply context constraints? Need to create issue""" | ||
causal_learn_graph, ordering = GIN_( | ||
data.to_numpy(), | ||
|
@@ -61,4 +110,4 @@ def fit(self, data, context): | |
) | ||
self.causal_learn_graph = causal_learn_graph | ||
self.causal_ordering = ordering | ||
self.graph_ = self._causal_learn_to_pdag(causal_learn_graph) | ||
self.graph_ = self._causal_learn_to_pdag(causal_learn_graph) |
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.
a context is an instance of the Context class.