Skip to content

Commit

Permalink
Refactor cycle resolution and add setter methods in GFci
Browse files Browse the repository at this point in the history
Refactor `resolveAlmostCycles1` by removing the redundant `anyChange` parameter and clean up commented code. Add new setter methods in `GFci` for discriminating path tail and collider rules, improving configurability.
  • Loading branch information
jdramsey committed Aug 14, 2024
1 parent f745d69 commit 37ebfeb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
33 changes: 18 additions & 15 deletions tetrad-lib/src/main/java/edu/cmu/tetrad/graph/GraphUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2920,7 +2920,7 @@ public static Graph repairFaultyPag(Graph pag, FciOrient fciOrient, Knowledge kn
pag = new EdgeListGraph(pag);
fciOrient.setKnowledge(knowledge);

// anyChange = resolveAlmostCycles1(pag, knowledge, unshieldedColliders, verbose, anyChange);
// boolean anyChange = resolveAlmostCycles1(pag, knowledge, unshieldedColliders, verbose);
boolean anyChange = removeAlmostCycles2(unshieldedColliders, fciOrient, pag, knowledge, verbose);

if (checkCyclicity) {
Expand Down Expand Up @@ -2959,8 +2959,9 @@ public static Graph repairFaultyPag(Graph pag, FciOrient fciOrient, Knowledge kn
return pag;
}

private static boolean resolveAlmostCycles1(Graph pag, Knowledge knowledge, Set<Triple> unshieldedColliders, boolean verbose, boolean anyChange) {
private static boolean resolveAlmostCycles1(Graph pag, Knowledge knowledge, Set<Triple> unshieldedColliders, boolean verbose) {
boolean changed;
boolean anyChange = false;

do {
changed = false;
Expand All @@ -2981,19 +2982,20 @@ private static boolean resolveAlmostCycles1(Graph pag, Knowledge knowledge, Set<
pag.removeEdge(x, y);
pag.addDirectedEdge(x, y);

List<Node> into = pag.getNodesInTo(x, Endpoint.ARROW);

for (Node _into : into) {
// pag.setEndpoint(_into, x, Endpoint.CIRCLE);
if (pag.isAdjacentTo(_into, x) && !pag.isAdjacentTo(_into, y)) {
pag.setEndpoint(_into, x, Endpoint.CIRCLE);
pag.addNondirectedEdge(_into, y);
}

if (unshieldedColliders != null) {
unshieldedColliders.remove(new Triple(_into, x, y));
}
}
// List<Node> into = pag.getNodesInTo(x, Endpoint.ARROW);
//
// for (Node _into : into) {
//// pag.setEndpoint(_into, x, Endpoint.CIRCLE);
//
// if (pag.isAdjacentTo(_into, x) && !pag.isAdjacentTo(_into, y)) {
// pag.setEndpoint(_into, x, Endpoint.CIRCLE);
// pag.addNondirectedEdge(_into, y);
// }
//
// if (unshieldedColliders != null) {
// unshieldedColliders.remove(new Triple(_into, x, y));
// }
// }

if (verbose) {
TetradLogger.getInstance().log("FAULTY PAG CORRECTION: Because " + x + " ~~> " + y + ", oriented " + y + " <-> " + x + " as " + x + " -> " + y + ".");
Expand Down Expand Up @@ -3030,6 +3032,7 @@ private static boolean resolveAlmostCycles1(Graph pag, Knowledge knowledge, Set<
}
}
} while (changed);

return anyChange;
}

Expand Down
18 changes: 18 additions & 0 deletions tetrad-lib/src/main/java/edu/cmu/tetrad/search/GFci.java
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,22 @@ public void setAblationLeaveOutFinalOrientation(boolean ablationLeaveOutFinalOri
public void setSepsetFinderMethod(int sepsetFinderMethod) {
this.sepsetFinderMethod = sepsetFinderMethod;
}

/**
* Sets whether the discriminating path tail rule should be used.
*
* @param doDiscriminatingPathTailRule True, if so.
*/
public void setDoDiscriminatingPathTailRule(boolean doDiscriminatingPathTailRule) {
this.doDiscriminatingPathTailRule = doDiscriminatingPathTailRule;
}

/**
* Sets whether the discriminating path collider rule should be used.
*
* @param doDiscriminatingPathColliderRule True, if so.
*/
public void setDoDiscriminatingPathColliderRule(boolean doDiscriminatingPathColliderRule) {
this.doDiscriminatingPathColliderRule = doDiscriminatingPathColliderRule;
}
}

0 comments on commit 37ebfeb

Please sign in to comment.