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

[DOCS] Add an example for the Inducing Path function #83

Merged
merged 26 commits into from
Jul 6, 2023

Conversation

aryan26roy
Copy link
Collaborator

Closes #81

Changes proposed in this pull request:

  • Add an example in examples/intro

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: Aryan Roy <aryanroy5678@gmail.com>
Signed-off-by: Aryan Roy <aryanroy5678@gmail.com>
@aryan26roy
Copy link
Collaborator Author

@adam2392 How do you want me to proceed with this? Should I include scenarios where there is no path as well? And are the comments like this ok?

@adam2392
Copy link
Collaborator

adam2392 commented Jun 21, 2023

@adam2392 How do you want me to proceed with this? Should I include scenarios where there is no path as well? And are the comments like this ok?

The goal is to educate the user and serve as a quick reminder for yourself as a dev in case you need to review something.

I would proceed in sections:

  1. setup the data and graph
  2. draw the graph, perhaps comment that there is only 1 inducing path relative to L and S. This one inducing path is why the MAG in Figure 2 of the paper contains an extra adjacency
  3. Run the inducing path algorithm and actually verify this 1 inducing path and verify a few non-inducing path examples as well
  4. Show and explain what happens when we include the node into set S

Lmk if that makes sense

Also I would add the example inside the intro/ folder, rather than making a new subfolder inside examples/ since this is a fundamental introduction to causal graphs.

Signed-off-by: Aryan Roy <aryanroy5678@gmail.com>
@aryan26roy
Copy link
Collaborator Author

@adam2392 What do you think?

Signed-off-by: Aryan Roy <aryanroy5678@gmail.com>
Signed-off-by: Aryan Roy <aryanroy5678@gmail.com>
@adam2392
Copy link
Collaborator

Yes I think this is a good start and direction!

Can you take a look at the other examples and use "# %%" to break up into sections where it makes sense?

It makes the final rendering easier to read.

Signed-off-by: Aryan Roy <aryanroy5678@gmail.com>
@aryan26roy
Copy link
Collaborator Author

@adam2392 How about now?

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.

There are a few comments I left. The most major one is that I'm surprised the code ran if you used a PAG with circle-edges.

An inducing path definition only mentions directed and bidirected edges, so for any graph with other kinds of edges (e.g. CPDAG or PAG) it is not defined what it is.

examples/intro/inducing_path.py Show resolved Hide resolved
examples/intro/inducing_path.py Outdated Show resolved Hide resolved
examples/intro/inducing_path.py Outdated Show resolved Hide resolved
examples/intro/inducing_path.py Outdated Show resolved Hide resolved
examples/intro/inducing_path.py Show resolved Hide resolved
examples/intro/inducing_path.py Outdated Show resolved Hide resolved
examples/intro/inducing_path.py Outdated Show resolved Hide resolved
examples/intro/inducing_path.py Outdated Show resolved Hide resolved
examples/intro/inducing_path.py Outdated Show resolved Hide resolved
examples/intro/inducing_path.py Outdated Show resolved Hide resolved
aryan26roy and others added 9 commits June 24, 2023 09:39
Co-authored-by: Adam Li <adam2392@gmail.com>
Signed-off-by: Aryan Roy <50577809+aryan26roy@users.noreply.github.com>
Co-authored-by: Adam Li <adam2392@gmail.com>
Signed-off-by: Aryan Roy <50577809+aryan26roy@users.noreply.github.com>
Co-authored-by: Adam Li <adam2392@gmail.com>
Signed-off-by: Aryan Roy <50577809+aryan26roy@users.noreply.github.com>
Co-authored-by: Adam Li <adam2392@gmail.com>
Signed-off-by: Aryan Roy <50577809+aryan26roy@users.noreply.github.com>
Co-authored-by: Adam Li <adam2392@gmail.com>
Signed-off-by: Aryan Roy <50577809+aryan26roy@users.noreply.github.com>
Co-authored-by: Adam Li <adam2392@gmail.com>
Signed-off-by: Aryan Roy <50577809+aryan26roy@users.noreply.github.com>
Co-authored-by: Adam Li <adam2392@gmail.com>
Signed-off-by: Aryan Roy <50577809+aryan26roy@users.noreply.github.com>
Co-authored-by: Adam Li <adam2392@gmail.com>
Signed-off-by: Aryan Roy <50577809+aryan26roy@users.noreply.github.com>
Signed-off-by: Aryan Roy <aryanroy5678@gmail.com>
@aryan26roy
Copy link
Collaborator Author

@adam2392 can you take a look now?

Signed-off-by: Aryan Roy <aryanroy5678@gmail.com>
@adam2392
Copy link
Collaborator

Can you add a test in inducing_path that a graph should only have directed and/or bidirected edges? Otw, and inducing path doesn't make sense to run.

E.g. I would expect it to return an error if passed a PAG.

Signed-off-by: Adam Li <adam2392@gmail.com>
Signed-off-by: Aryan Roy <aryanroy5678@gmail.com>
@aryan26roy
Copy link
Collaborator Author

Can you add a test in inducing_path that a graph should only have directed and/or bidirected edges? Otw, and inducing path doesn't make sense to run.

Do you want me to add it to this PR or create a new issue and a new PR?

@adam2392
Copy link
Collaborator

You can just add it here since it's just a line just checking the types of edges present.

Signed-off-by: Aryan Roy <aryanroy5678@gmail.com>
@aryan26roy
Copy link
Collaborator Author

@adam2392 there's one problem. There is no graph class that is only has directed and bidirected edges. Even ADMG can have undirected edges. Do you want me to just check if the argument is an instance of PAG or CPDAG instead?

@adam2392
Copy link
Collaborator

@adam2392 there's one problem. There is no graph class that is only has directed and bidirected edges. Even ADMG can have undirected edges. Do you want me to just check if the argument is an instance of PAG or CPDAG instead?

I wouldn't check the class as we are going to eventually try to refactor that so there is no explicit PAG/CPDAG class.

Instead, I would check the edge types for right now 'directed', 'bidirected' keywords.

@aryan26roy
Copy link
Collaborator Author

Instead, I would check the edge types for right now 'directed', 'bidirected' keywords.

The problem is PAG would pass this test. It can have both of these edge types.

Signed-off-by: Aryan Roy <aryanroy5678@gmail.com>
@adam2392
Copy link
Collaborator

Instead, I would check the edge types for right now 'directed', 'bidirected' keywords.

The problem is PAG would pass this test. It can have both of these edge types.

We don't want any other edge. It can only have these types of edges.

@aryan26roy
Copy link
Collaborator Author

@adam2392 Unless you're ok with instances of PAG class being valid as long as they only have directed and bidirected edges. Otherwise there is no way to differentiate between the different types.

Signed-off-by: Aryan Roy <aryanroy5678@gmail.com>
@aryan26roy
Copy link
Collaborator Author

@adam2392 I added the check. Also, I can't get the references to render, can you take a look at both?

Signed-off-by: Aryan Roy <aryanroy5678@gmail.com>
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.

Co-authored-by: Adam Li <adam2392@gmail.com>
Signed-off-by: Aryan Roy <50577809+aryan26roy@users.noreply.github.com>
@aryan26roy
Copy link
Collaborator Author

@adam2392 The last run didn't make any documentation artifacts?

@adam2392
Copy link
Collaborator

Are you able to see the status of the circle CI docs build? The artifacts are listed there.

@aryan26roy
Copy link
Collaborator Author

Now I can see it! I guess github was glitching out for me. Anyway, are you happy with the current state?

Comment on lines 568 to 573
edges = G.edges()

for elem in edges.keys():
if elem not in {"directed", "bidirected"}:
if len(edges[elem]) != 0:
raise ValueError("Inducing Path is not defined for this graph.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would instead do something like:

if any(edge_type not in {'directed', 'bidirected'} for edge_type in G.edge_types):
     raise...

See: https://www.pywhy.org/pywhy-graphs/dev/generated/pywhy_graphs.networkx.MixedEdgeGraph.html#pywhy_graphs.networkx.MixedEdgeGraph

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@adam2392 If I use this test all of the ADMG classes are raising errors as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh okay I see. Can you add a comment marking this as something we should fix in the future # XXX: fix this when graph classes are refactored to only check for directed/bidirected edge types?

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 changes. Otw LGTM and can merge one these are addressed.

examples/intro/inducing_path.py Outdated Show resolved Hide resolved
examples/intro/inducing_path.py Outdated Show resolved Hide resolved
Comment on lines 568 to 573
edges = G.edges()

for elem in edges.keys():
if elem not in {"directed", "bidirected"}:
if len(edges[elem]) != 0:
raise ValueError("Inducing Path is not defined for this graph.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh okay I see. Can you add a comment marking this as something we should fix in the future # XXX: fix this when graph classes are refactored to only check for directed/bidirected edge types?

Signed-off-by: Adam Li <adam2392@gmail.com>
Signed-off-by: Adam Li <adam2392@gmail.com>
Signed-off-by: Adam Li <adam2392@gmail.com>
@adam2392 adam2392 merged commit 881df16 into py-why:main Jul 6, 2023
@adam2392
Copy link
Collaborator

adam2392 commented Jul 6, 2023

Thanks @aryan26roy !

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.

Update intro folder of Sphinx examples/ to show intuition and concepts of inducing path
2 participants