Skip to content
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

[ENH, MAINT] Refactor directed-undirected graph class #72

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

jaron-lee
Copy link
Collaborator

@jaron-lee jaron-lee commented Apr 6, 2023

Towards #65

Changes proposed in this pull request:

  • Creates a new directed/undirected graph class DiUnGraph
  • Refactors CPDAG to be a subclass of DiUnGraph
  • Create a new graph class Chain Graph which subclasses DiUnGraph
  • Implement functions that check if CPDAG and ChainGraph are valid instances

Before submitting

  • I've read and followed all steps in the Making a pull request
    section of the CONTRIBUTING docs.
  • I've updated or added any relevant docstrings following the syntax described in the
    Writing docstrings section of the CONTRIBUTING docs.
  • If this PR fixes a bug, I've added a test that will fail without my fix.
  • If this PR adds a new feature, I've added tests that sufficiently cover my new functionality.

After submitting

  • All GitHub Actions jobs for my pull request have passed.

Signed-off-by: Jaron Lee <[email protected]>
Signed-off-by: Jaron Lee <[email protected]>
@jaron-lee jaron-lee changed the title Refactor classes Refactor directed-undirected graph class Apr 6, 2023
of the sample induces association between ``A`` and ``B``) [1]_.


The implementation supports representation of both Lauritzen-Wermuth-Frydenberg (LWF)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this. Maybe citations?

self,
incoming_directed_edges=None,
incoming_undirected_edges=None,
directed_edge_name: str = "directed",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace around " = "

Copy link
Collaborator

@robertness robertness left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@robertness
Copy link
Collaborator

I know it's still a WIP but I approved in case you wanted to get initial work in.

@@ -184,6 +143,90 @@ def possible_parents(self, n: Node) -> Iterator[Node]:
"""
return self.sub_undirected_graph().neighbors(n)


class CPDAG(DiUnGraph, ConservativeMixin):
"""Completed partially directed acyclic graphs (CPDAG).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it is worth adding a note or warning even to the classes that validity is not guaranteed. Please use the validity check if you need to rigorously check that your construction is valid?

Same in chaingraph? Maybe also in the ADMG, and PAG too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is a good idea. I will address just CPDAG and Chain Graph in this PR but will look to redo the other classes in another PR.

Copy link
Collaborator

@adam2392 adam2392 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the direction of these changes. It keeps us lean but also doesn't commit to one design yet.

Signed-off-by: Jaron Lee <[email protected]>
Signed-off-by: Jaron Lee <[email protected]>
@codecov-commenter
Copy link

Codecov Report

Merging #72 (7d69f7f) into main (c1b4107) will increase coverage by 0.25%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #72      +/-   ##
==========================================
+ Coverage   84.42%   84.67%   +0.25%     
==========================================
  Files          34       35       +1     
  Lines        2555     2597      +42     
  Branches      687      695       +8     
==========================================
+ Hits         2157     2199      +42     
  Misses        251      251              
  Partials      147      147              
Impacted Files Coverage Δ
pywhy_graphs/algorithms/cg.py 100.00% <100.00%> (ø)
pywhy_graphs/classes/diungraph.py 85.45% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Collaborator

@adam2392 adam2392 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor fixes and then LGTM.

@@ -25,6 +25,7 @@ Version 0.1

Changelog
---------
- |Feature| Introduce chain graphs and validity checks, and refactor CPDAG and chain graphs to use a directed-undirected private class, by `Jaron Lee`_ (:pr:`73`)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically change log goes on the bottom. I think the Changelog CI check should get fixed that way

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh fair enough I was just following https://keepachangelog.com/en/1.0.0/ which has everything in reverse chronological order


# Search over all nodes.
for v in all_nodes:
queue = deque([])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a type annotation to queue to fix the mypy complaint

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do - also I have the pre-commit hooks PR which is open for review which will help me catch this :)))

# Fill queue with paths from v starting with outgoing directed edge
# OrderedDict used for O(1) set membership and ordering
for _, z in G_directed.out_edges(nbunch=v):
d = OrderedDict()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a type annotation to d to fix the mypy complaint



@pytest.fixture
def fig_g1_frydenberg():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add a docstring and a link to the reference for all the fixtures that come from some paper, so its back traceable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes that's a good idea, i have the reference in the function but not the test

@jaron-lee
Copy link
Collaborator Author

Some minor fixes and then LGTM.

I will also implement the corresponding changes for CPDAG before I unmark as draft but thanks for the early reviews on this PR

@jaron-lee jaron-lee changed the title Refactor directed-undirected graph class [ENH, MAINT] Refactor directed-undirected graph class Apr 20, 2023
@adam2392
Copy link
Collaborator

@jaron-lee hey know you're prolly busy doing more interesting things at your internship :)

Just wanted to check in to see if you think we should just do a release v0.1 first for now. I think we should def refactor by v0.2 into whatever this PR manifests?

@jaron-lee
Copy link
Collaborator Author

jaron-lee commented Jun 28, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants