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] Add the ability to check the validity of a PAG #100

Merged
merged 60 commits into from
Jul 15, 2024

Conversation

aryan26roy
Copy link
Collaborator

Fixes #67

Changes proposed in this pull request:

  • Add a function that takes in a PAG and checks if it is valid or not.

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 <[email protected]>
@aryan26roy
Copy link
Collaborator Author

aryan26roy commented Nov 14, 2023

Just to list the procedure out:

  • Convert the PAG to MAG
  • Check if the MAG is valid or not
  • Convert the MAG back to PAG
  • Check if the converted and original PAGs are equivalent or not

@adam2392 is this the right pseudo-algorithm?

@adam2392
Copy link
Collaborator

Just to list the procedure out:

  • Convert the PAG to MAG
  • Check if the MAG is valid or not
  • Convert the MAG back to PAG
  • Check if the converted and original PAGs are equivalent or not

@adam2392 is this the right pseudo-algorithm?

Yes with the added check at the very beginning that the graph is a valid PAG.

@aryan26roy
Copy link
Collaborator Author

Yes with the added check at the very beginning that the graph is a valid PAG.

For this, is it enough to check if the graph has any circle edges or not?

@adam2392
Copy link
Collaborator

Same skeleton as MAG so checking acyclicity, ancestral, and maximalist of the non-circle edge subgraph.

A PAG could be fully oriented which results in no circle edges.

@aryan26roy
Copy link
Collaborator Author

  • Check if the converted and original PAGs are equivalent or not

For this, I think I have to determine that the two PAGs have the same set of conditional independence relations since they might be structurally different yet markov equivalent?

@adam2392
Copy link
Collaborator

adam2392 commented Nov 16, 2023

  • Check if the converted and original PAGs are equivalent or not

For this, I think I have to determine that the two PAGs have the same set of diff conditional independence relations since they might be structurally different yet markov equivalent?

No that is only the case for MAGs.

The two PAGs should be exactly the same, otherwise they encode some set of conditional independences. This assumes that all of the FCI orientation rules no longer can be applied to the PAG (i.e. it is as oriented as possible).

@aryan26roy
Copy link
Collaborator Author

Ah so simply checking that all of the edges are the same in both the PAGs should suffice.

@aryan26roy
Copy link
Collaborator Author

Same skeleton as MAG so checking acyclicity, ancestral, and maximalist of the non-circle edge subgraph.

Hey @adam2392 I am done with the applications, so back to work! One question though, when checking acyclicity in the non-circle edge subgraph, do I only look for directed cycles? Or is the cycle supposed to be direction agnostic?

Signed-off-by: Aryan Roy <[email protected]>
@adam2392
Copy link
Collaborator

adam2392 commented Jan 4, 2024

Nice! Congrats.

Can you remind me what part requires the acyclicity check?

@aryan26roy
Copy link
Collaborator Author

Yes with the added check at the very beginning that the graph is a valid PAG.

Before actually checking for the validity, you asked me to check if it was valid-valid.

@aryan26roy
Copy link
Collaborator Author

Maybe there is a better term for it somewhere.

@adam2392
Copy link
Collaborator

adam2392 commented Jan 4, 2024

Ah I see. Yeah it's just the same check as a MAG

That's cuz we can't have cycles in the directed edges or almost directed cycles.

You would only do this for the non circle edges tho. So any edge with a circle endpoint is dropped.

A fully oriented PAG is just a MAG

@aryan26roy
Copy link
Collaborator Author

Ah I see. Yeah it's just the same check as a MAG

That's cuz we can't have cycles in the directed edges or almost directed cycles.

You would only do this for the non circle edges tho. So any edge with a circle endpoint is dropped.

A fully oriented PAG is just a MAG

Got it!

@aryan26roy
Copy link
Collaborator Author

@adam2392 right now I am checking for cycles, almost directed cycles and for inducing paths between any two non-adjacent nodes. Is that enough?

@adam2392
Copy link
Collaborator

adam2392 commented Jan 6, 2024

Yep!

@aryan26roy
Copy link
Collaborator Author

@adam2392 How do I add dodiscover to the list of dependencies?

@adam2392
Copy link
Collaborator

adam2392 commented Jan 8, 2024

For now, just run locally and check it.

Dodiscover isn't on pypi yet but planning on making a release.

@aryan26roy
Copy link
Collaborator Author

@adam2392 can you describe how to convert a mag back to pag? Is it simply running the FCI algorithm using dodiscover?

@adam2392
Copy link
Collaborator

@adam2392 can you describe how to convert a mag back to pag? Is it simply running the FCI algorithm using dodiscover?

Yes

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.

Left some comments on the example.

examples/intro/checking_validity_of_a_pag.py Outdated Show resolved Hide resolved
examples/intro/checking_validity_of_a_pag.py Show resolved Hide resolved
examples/intro/checking_validity_of_a_pag.py Outdated Show resolved Hide resolved
examples/intro/checking_validity_of_a_pag.py Outdated Show resolved Hide resolved
@aryan26roy
Copy link
Collaborator Author

@adam2392 Now the example is complete (along with some review suggestions being incorporated).
I also changed the function call in intro_causal_graphs.py from "is_d_separator" -> "d_separated" since it was failing for me.

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.

Looking good! I think last round of comments. Please read the example over and see if it makes sense.

Thanks for the efforts @aryan26roy!

examples/intro/checking_validity_of_a_pag.py Outdated Show resolved Hide resolved
examples/intro/checking_validity_of_a_pag.py Outdated Show resolved Hide resolved
pywhy_graphs/algorithms/pag.py Show resolved Hide resolved
pywhy_graphs/algorithms/pag.py Show resolved Hide resolved
examples/intro/checking_validity_of_a_pag.py Outdated Show resolved Hide resolved
examples/intro/checking_validity_of_a_pag.py Outdated Show resolved Hide resolved
examples/intro/checking_validity_of_a_pag.py Outdated Show resolved Hide resolved
examples/intro/checking_validity_of_a_pag.py Outdated Show resolved Hide resolved
examples/intro/checking_validity_of_a_pag.py Show resolved Hide resolved
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.

LGTM once CI passes

@aryan26roy
Copy link
Collaborator Author

This was a big one!

@adam2392 adam2392 merged commit 31ad037 into py-why:main Jul 15, 2024
24 of 25 checks passed
@adam2392
Copy link
Collaborator

Thanks for the PR @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.

Checking the validity of a constructed PAG
2 participants