Skip to content

feat: add is_mpdag and meek_closure functions for PDAGs#233

Merged
frederikfabriciusbjerre merged 9 commits intomainfrom
feat/meeks+is_mpdag
Mar 11, 2026
Merged

feat: add is_mpdag and meek_closure functions for PDAGs#233
frederikfabriciusbjerre merged 9 commits intomainfrom
feat/meeks+is_mpdag

Conversation

@frederikfabriciusbjerre
Copy link
Copy Markdown
Owner

@frederikfabriciusbjerre frederikfabriciusbjerre commented Feb 28, 2026

This PR 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.

Closes #165

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.
Copy link
Copy Markdown
Collaborator

@jolars jolars left a comment

Choose a reason for hiding this comment

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

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?

Comment thread R/operations.R
#'
#' @family operations
#' @concept operations
#'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we add a reference here?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Yes

Comment thread R/operations.R
Comment thread R/queries.R
#'
#' @family queries
#' @concept queries
#'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Best to add a reference here too, maybe?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Sure, will look into it.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Couldn't find a reference (this is just applying meeks and seeing if it changed).

Comment thread R/queries.R
#' @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).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Minor nit: I am not sure the -- are actually correctly treated as an en-dash in the R docs.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Will take a look when I have time

@frederikfabriciusbjerre frederikfabriciusbjerre merged commit cec3228 into main Mar 11, 2026
9 checks passed
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.

feat: Add is_mpdag functionality

2 participants