Class GraphTransforms

java.lang.Object
edu.cmu.tetrad.graph.GraphTransforms

public class GraphTransforms extends Object
Transformations that transform one graph into another.
Version:
$Id: $Id
Author:
josephramsey
  • Method Summary

    Modifier and Type
    Method
    Description
    static Graph
    Calculates the adjacency graph for the given Directed Acyclic Graph (DAG).
    static Graph
    Converts a completed partially directed acyclic graph (CPDAG) into a directed acyclic graph (DAG).
    static Graph
    dagFromCpdag(Graph graph, boolean verbose)
    Converts a completed partially directed acyclic graph (CPDAG) into a directed acyclic graph (DAG).
    static Graph
    dagFromCpdag(Graph graph, boolean meekPreventCycles, boolean verbose)
    Converts a completed partially directed acyclic graph (CPDAG) into a directed acyclic graph (DAG).
    static Graph
    dagFromCpdag(Graph graph, Knowledge knowledge)
    dagFromCpdag.
    static Graph
    dagFromCpdag(Graph cpdag, Knowledge knowledge, boolean verbose)
    Returns a random DAG from the given CPDAG.
    static Graph
    Returns the completed partially directed acyclic graph (CPDAG) for a given directed acyclic graph (DAG).
    static @NotNull Graph
    Converts a Directed Acyclic Graph (DAG) to a Maximal Ancestral Graph (MAG) by adding arrows to the edges.
    static @NotNull Graph
    dagToPag(Graph graph)
    Converts a Directed Acyclic Graph (DAG) to a Partial Ancestral Graph (PAG) using the DagToPag algorithm.
    static List<Graph>
    generateCpdagDags(Graph cpdag, boolean orientBidirectedEdges)
    Generates the list of DAGs in the given cpdag.
    static List<Graph>
    Returns a list of all possible graphs obtained by directing undirected edges in the given graph.
    static List<Graph>
    getDagsInCpdagMeek(Graph cpdag, Knowledge knowledge)
    Retrieves a list of directed acyclic graphs (DAGs) within the given completed partially directed acyclic graph (CPDAG) using the Meek rules.
    static Graph
    Converts a maximal ancestral graph (MAG) into a partial ancestral graph (PAG).
    static Graph
    revertToUnshieldedColliders(Graph graph, boolean circles)
    Reverts the provided graph to its unshielded colliders, with other endpoints oriented either as circles (PAG case) or tails (CPDAG case).
    static void
    transformCpdagIntoDag(Graph graph, Knowledge knowledge, boolean verbose)
    Transforms a completed partially directed acyclic graph (CPDAG) into a directed acyclic graph (DAG) by orienting the undirected edges in the CPDAG.
    static Graph
    Transforms a partial ancestral graph (PAG) into a maximal ancestral graph (MAG) using Zhang's 2008 Theorem 2.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • dagFromCpdag

      public static Graph dagFromCpdag(Graph graph)
      Converts a completed partially directed acyclic graph (CPDAG) into a directed acyclic graph (DAG). If the given CPDAG is not a PDAG (Partially Directed Acyclic Graph), returns null.
      Parameters:
      graph - the CPDAG to be converted into a DAG
      Returns:
      a directed acyclic graph (DAG) obtained from the given CPDAG. If the given CPDAG is not a PDAG, returns null.
    • dagFromCpdag

      public static Graph dagFromCpdag(Graph graph, boolean verbose)
      Converts a completed partially directed acyclic graph (CPDAG) into a directed acyclic graph (DAG). If the given CPDAG is not a PDAG (Partially Directed Acyclic Graph), returns null.
      Parameters:
      graph - the CPDAG to be converted into a DAG
      verbose - whether to print verbose output
      Returns:
      a directed acyclic graph (DAG) obtained from the given CPDAG. If the given CPDAG is not a PDAG, returns null.
    • dagFromCpdag

      public static Graph dagFromCpdag(Graph graph, boolean meekPreventCycles, boolean verbose)
      Converts a completed partially directed acyclic graph (CPDAG) into a directed acyclic graph (DAG). If the given CPDAG is not a PDAG (Partially Directed Acyclic Graph), returns null.
      Parameters:
      graph - the CPDAG to be converted into a DAG
      meekPreventCycles - whether to prevent cycles using the Meek rules by orienting additional arbitrary unshielded colliders in the graph
      verbose - whether to print verbose output
      Returns:
      a directed acyclic graph (DAG) obtained from the given CPDAG. If the given CPDAG is not a PDAG, returns null.
    • dagFromCpdag

      public static Graph dagFromCpdag(Graph graph, Knowledge knowledge)

      dagFromCpdag.

      Parameters:
      graph - a Graph
      knowledge - a Knowledge
      Returns:
      a Graph object
    • dagFromCpdag

      public static Graph dagFromCpdag(Graph cpdag, Knowledge knowledge, boolean verbose)
      Returns a random DAG from the given CPDAG. If the given CPDAG is not a PDAG, returns null.
      Parameters:
      cpdag - the CPDAG
      knowledge - the knowledge
      verbose - whether to print verbose output.
      Returns:
      a DAG from the given CPDAG. If the given CPDAG is not a PDAG, returns null.
    • transformCpdagIntoDag

      public static void transformCpdagIntoDag(Graph graph, Knowledge knowledge, boolean verbose)
      Transforms a completed partially directed acyclic graph (CPDAG) into a directed acyclic graph (DAG) by orienting the undirected edges in the CPDAG.
      Parameters:
      graph - The original graph from which the CPDAG was derived.
      knowledge - The knowledge available to check if a potential DAG violates any constraints.
      verbose - Whether to print verbose output.
    • zhangMagFromPag

      public static Graph zhangMagFromPag(Graph pag)
      Transforms a partial ancestral graph (PAG) into a maximal ancestral graph (MAG) using Zhang's 2008 Theorem 2.
      Parameters:
      pag - The partially ancestral graph to transform.
      Returns:
      The maximally ancestral graph obtained from the PAG.
    • generateCpdagDags

      public static List<Graph> generateCpdagDags(Graph cpdag, boolean orientBidirectedEdges)
      Generates the list of DAGs in the given cpdag.
      Parameters:
      cpdag - a Graph object
      orientBidirectedEdges - a boolean
      Returns:
      a List object
    • getDagsInCpdagMeek

      public static List<Graph> getDagsInCpdagMeek(Graph cpdag, Knowledge knowledge)
      Retrieves a list of directed acyclic graphs (DAGs) within the given completed partially directed acyclic graph (CPDAG) using the Meek rules.
      Parameters:
      cpdag - The completed partially directed acyclic graph (CPDAG) from which to retrieve the DAGs.
      knowledge - The knowledge available to check if a potential DAG violates any constraints.
      Returns:
      A List of Graph objects representing the DAGs within the CPDAG.
    • getAllGraphsByDirectingUndirectedEdges

      public static List<Graph> getAllGraphsByDirectingUndirectedEdges(Graph skeleton)
      Returns a list of all possible graphs obtained by directing undirected edges in the given graph.
      Parameters:
      skeleton - the graph to transform
      Returns:
      a list of all possible graphs obtained by directing undirected edges
    • dagToCpdag

      public static Graph dagToCpdag(Graph dag)
      Returns the completed partially directed acyclic graph (CPDAG) for a given directed acyclic graph (DAG).
      Parameters:
      dag - The input DAG.
      Returns:
      The CPDAG resulting from applying Meek Rules to the input DAG.
    • dagToPag

      @NotNull public static @NotNull Graph dagToPag(Graph graph)
      Converts a Directed Acyclic Graph (DAG) to a Partial Ancestral Graph (PAG) using the DagToPag algorithm.
      Parameters:
      graph - The input DAG to be converted.
      Returns:
      The resulting PAG obtained from the input DAG.
    • dagToMag

      @NotNull public static @NotNull Graph dagToMag(Graph dag)
      Converts a Directed Acyclic Graph (DAG) to a Maximal Ancestral Graph (MAG) by adding arrows to the edges.
      Parameters:
      dag - The input DAG to be converted.
      Returns:
      The resulting MAG obtained from the input DAG.
    • calcAdjacencyGraph

      public static Graph calcAdjacencyGraph(Graph dag)
      Calculates the adjacency graph for the given Directed Acyclic Graph (DAG).
      Parameters:
      dag - The input MAG.
      Returns:
      The adjacency graph represented by a Graph object.
    • revertToUnshieldedColliders

      public static Graph revertToUnshieldedColliders(Graph graph, boolean circles)
      Reverts the provided graph to its unshielded colliders, with other endpoints oriented either as circles (PAG case) or tails (CPDAG case). The operation orients a copy of the graph with no orientations, then iterates through the unshielded colliders (X --> Y <-- Z with ~adj(X, Z)) in the original graph and makes these orientations in the new graph.
      Parameters:
      graph - the input graph on which the operation is performed.
      circles - if other endpoints should otherwise be circles (PAG case), false if tails (CPDAG case).
      Returns:
      a new graph with the specified updates applied.
    • magToPag

      public static Graph magToPag(Graph mag)
      Converts a maximal ancestral graph (MAG) into a partial ancestral graph (PAG).
      Parameters:
      mag - the maximal ancestral graph (MAG) to be converted
      Returns:
      the resulting partial ancestral graph (PAG)