feat: add is_mpdag and meek_closure functions for PDAGs#233
Merged
frederikfabriciusbjerre merged 9 commits intomainfrom Mar 11, 2026
Merged
feat: add is_mpdag and meek_closure functions for PDAGs#233frederikfabriciusbjerre merged 9 commits intomainfrom
frederikfabriciusbjerre merged 9 commits intomainfrom
Conversation
This commit introduces two new functions: `is_mpdag()`, which checks if a given PDAG is closed under Meek's orientation rules, and `meek_closure()`, which applies these rules to orient all implied edges in a PDAG. Additionally, the NAMESPACE and documentation files have been updated to reflect these changes, and tests have been added to ensure functionality.
This commit modifies the `meek_closure` function to return a mutated CAUGI if the graph is a DAG, and updates the documentation for `is_mpdag` to clarify its purpose as checking for Maximally oriented Partially Directed Acyclic Graphs (MPDAGs). Unused example code has been removed for clarity.
This commit refactors the `meek_closure` function to improve readability and performance by introducing a type alias `NodeSet` for `BTreeSet<u32>`. The implementation now utilizes more concise methods for initializing parent, child, and undirected node sets. Additionally, the logic for edge orientation has been streamlined, enhancing clarity and maintainability. Tests have been updated to ensure correct behavior in edge cases.
…n logic This commit adds a new helper function `try_orient` to encapsulate the logic for applying Meek-style orientations while preserving acyclicity in the PDAG. The existing orientation calls within the `meek_closure` function have been updated to utilize this new function, improving code clarity and maintainability.
jolars
approved these changes
Mar 2, 2026
Collaborator
jolars
left a comment
There was a problem hiding this comment.
LGTM, but I cannot much tell how valid this is as an implementation of the rules. Did you find any implementation + tests in some other package to validate against?
| #' | ||
| #' @family operations | ||
| #' @concept operations | ||
| #' |
Collaborator
There was a problem hiding this comment.
Can we add a reference here?
| #' | ||
| #' @family queries | ||
| #' @concept queries | ||
| #' |
Collaborator
There was a problem hiding this comment.
Best to add a reference here too, maybe?
Owner
Author
There was a problem hiding this comment.
Sure, will look into it.
Owner
Author
There was a problem hiding this comment.
Couldn't find a reference (this is just applying meeks and seeing if it changed).
| #' @description Checks if the given `caugi` graph is a | ||
| #' Maximally oriented Partially Directed Acyclic Graph | ||
| #' (MPDAG), i.e. a PDAG where no additional edge orientations | ||
| #' are implied by Meek's rules (R1--R4). |
Collaborator
There was a problem hiding this comment.
Minor nit: I am not sure the -- are actually correctly treated as an en-dash in the R docs.
Owner
Author
There was a problem hiding this comment.
Will take a look when I have time
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR introduces two new functions:
is_mpdag(), which checks if a given PDAG is closed under Meek's orientation rules, andmeek_closure(), which applies these rules to orient all implied edges in a PDAG. Additionally, the NAMESPACE and documentation files have been updated to reflect these changes, and tests have been added to ensure functionality.Closes #165