Package edu.cmu.tetrad.graph
Class GraphUtils
java.lang.Object
edu.cmu.tetrad.graph.GraphUtils
Basic graph utilities.
- Author:
- josephramsey
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addForbiddenReverseEdgesForDirectedEdges
(Graph graph, Knowledge knowledge) static void
addPagColoring
(Graph graph) Constructs a list of nodes from the givennodes
list at the given indices in that list.static Graph
bidirectedToUndirected
(Graph graph) static boolean
compatible
(Edge edge1, Edge edge2) static Graph
completeGraph
(Graph graph) static boolean
containsBidirectedEdge
(Graph graph) static Graph
Converts a string spec of a graph--for example, "X1-->X2, X1---X3, X2o->X4, X3<->X4" to a Graph.static int
countAdjErrors
(Graph graph1, Graph graph2) Counts the adjacencies that are in graph1 but not in graph2.static int
countArrowptErrors
(Graph graph1, Graph graph2) Counts the arrowheads that are in graph1 but not in graph2.static int
static int[][]
edgeMisclassificationCounts
(Graph leftGraph, Graph topGraph, boolean print) static String
edgeMisclassifications
(double[][] counts, NumberFormat nf) static String
edgeMisclassifications
(int[][] counts) static Graph
emptyGraph
(int numNodes) static void
fciOrientbk
(Knowledge knowledge, Graph graph, List<Node> variables) Orients according to background knowledgegetAmbiguousTriplesFromGraph
(Node node, Graph graph) static Node
getAssociatedNode
(Node errorNode, Graph graph) static Graph
getComparisonGraph
(Graph graph, Parameters params) static int
getDottedUnderlinedTriplesFromGraph
(Node node, Graph graph) static int
getIndegree
(Graph graph) static String
getIntersectionComparisonString
(List<Graph> graphs) static int
getNumCorrectArrowpts
(Graph correct, Graph estimated) static GraphUtils.TwoCycleErrors
getTwoCycleErrors
(Graph trueGraph, Graph estGraph) getUnderlinedTriplesFromGraph
(Node node, Graph graph) static void
gfciExtraEdgeRemovalStep
(Graph graph, Graph referenceCpdag, List<Node> nodes, SepsetProducer sepsets) The extra edge removal step for GFCI.static void
gfciR0
(Graph graph, Graph referenceCpdag, SepsetProducer sepsets, Knowledge knowledge) static String
graphAttributesToText
(Graph graph, String title) static String
graphEdgesToText
(Graph graph, String title) static String
graphNodeAttributesToText
(Graph graph, String title, char delimiter) static String
graphNodesToText
(Graph graph, String title, char delimiter) static String
graphToText
(Graph graph, boolean doPagColoring) static boolean
isClique
(Collection<Node> set, Graph graph) static boolean
static LinkedList<Triple>
listColliderTriples
(Graph graph) markovBlanket
(Node x, Graph G) Returns a Markov blanket of a node for a DAG, CPDAG, MAG, or PAG.static Graph
markovBlanketSubgraph
(Node target, Graph graph) Calculates the subgraph over the Markov blanket of a target node in a given DAG, CPDAG, MAG, or PAG.maximalCliques
(Graph graph, List<Node> nodes) static String
pathString
(Graph graph, Node... x) static String
pathString
(Graph graph, List<Node> path) static Graph
removeBidirectedOrientations
(Graph estCpdag) static void
removeNonSkeletonEdges
(Graph graph, Knowledge knowledge) static Graph
replaceNodes
(Graph originalGraph, List<Node> newVariables) Converts the given graph,originalGraph
, to use the new variables (with the same names as the old).replaceNodes
(List<Node> originalNodes, Graph graph) Converts the given list of nodes,originalNodes
, to use the replacement nodes for them by the same name in the givengraph
.replaceNodes
(List<Node> originalNodes, List<Node> newNodes) Converts the given list of nodes,originalNodes
, to use the new variables (with the same names as the old).static Graph
restrictToMeasured
(Graph graph) static Node
traverseSemiDirected
(Node node, Edge edge) static Graph
static String
triplesToText
(Set<Triple> triples, String title) static Graph
undirectedGraph
(Graph graph) static Graph
undirectedToBidirected
(Graph graph)
-
Constructor Details
-
GraphUtils
public GraphUtils()
-
-
Method Details
-
getAssociatedNode
- Returns:
- the node associated with a given error node. This should be the only child of the error node, E --> N.
-
isClique
- Returns:
- true if
set
is a clique ingraph
. R. Silva, June 2004
-
markovBlanketSubgraph
Calculates the subgraph over the Markov blanket of a target node in a given DAG, CPDAG, MAG, or PAG.- Parameters:
target
- a node in the given graph.graph
- a DAG, CPDAG, MAG, or PAG.
-
removeBidirectedOrientations
-
undirectedGraph
-
completeGraph
-
bidirectedToUndirected
- Returns:
- a new graph in which the bidirectred edges of the given graph have been changed to undirected edges.
-
undirectedToBidirected
- Returns:
- a new graph in which the undirectred edges of the given graph have been changed to bidirected edges.
-
pathString
-
pathString
-
replaceNodes
Converts the given graph,originalGraph
, to use the new variables (with the same names as the old).- Parameters:
originalGraph
- The graph to be converted.newVariables
- The new variables to use, with the same names as the old ones.- Returns:
- A new, converted, graph.
-
restrictToMeasured
-
replaceNodes
Converts the given list of nodes,originalNodes
, to use the new variables (with the same names as the old).- Parameters:
originalNodes
- The list of nodes to be converted.newNodes
- A list of new nodes, containing as a subset nodes with the same names as those inoriginalNodes
. the old ones.- Returns:
- The converted list of nodes.
-
countAdjErrors
Counts the adjacencies that are in graph1 but not in graph2.- Throws:
IllegalArgumentException
- if graph1 and graph2 are not namewise isomorphic.
-
countArrowptErrors
Counts the arrowheads that are in graph1 but not in graph2. -
getNumCorrectArrowpts
-
replaceNodes
Converts the given list of nodes,originalNodes
, to use the replacement nodes for them by the same name in the givengraph
.- Parameters:
originalNodes
- The list of nodes to be converted.graph
- A graph to be used as a source of new nodes.- Returns:
- A new, converted, graph.
-
emptyGraph
- Returns:
- an empty graph with the given number of nodes.
-
getAmbiguousTriplesFromGraph
- Returns:
- A list of triples of the form <X, Y, Z>, where <X, Y, Z> is a definite noncollider in the given graph.
-
getUnderlinedTriplesFromGraph
- Returns:
- A list of triples of the form <X, Y, Z>, where <X, Y, Z> is a definite noncollider in the given graph.
-
getDottedUnderlinedTriplesFromGraph
- Returns:
- A list of triples of the form <X, Y, Z>, where <X, Y, Z> is a definite noncollider in the given graph.
-
containsBidirectedEdge
-
listColliderTriples
-
asList
Constructs a list of nodes from the givennodes
list at the given indices in that list.- Parameters:
indices
- The indices of the desired nodes innodes
.nodes
- The list of nodes from which we select a sublist.- Returns:
- The sublist selected.
-
asSet
-
asSet
-
degree
-
getIntersectionComparisonString
-
edgeMisclassifications
-
edgeMisclassifications
-
addPagColoring
-
edgeMisclassificationCounts
-
maximalCliques
-
graphToText
-
graphNodeAttributesToText
-
graphAttributesToText
-
graphNodesToText
-
graphEdgesToText
-
triplesToText
-
getTwoCycleErrors
-
getDegree
-
getIndegree
-
traverseSemiDirected
-
getComparisonGraph
-
gfciExtraEdgeRemovalStep
public static void gfciExtraEdgeRemovalStep(Graph graph, Graph referenceCpdag, List<Node> nodes, SepsetProducer sepsets) The extra edge removal step for GFCI. This removed edges in triangles in the reference graph by looking for sepsets for edge a--b among the adjacents of a or the adjacents of b.- Parameters:
graph
- The graph being operated on and changed.referenceCpdag
- The reference graph, a CPDAG or a DAG obtained using such an algorithm.nodes
- The nodes in the graph.sepsets
- A SepsetProducer that will do the sepset search operation described.
-
addForbiddenReverseEdgesForDirectedEdges
-
removeNonSkeletonEdges
-
compatible
-
markovBlanket
Returns a Markov blanket of a node for a DAG, CPDAG, MAG, or PAG. This is not necessarily minimal (i.e. not necessarily a Markov Boundary).- Parameters:
x
- The target node.G
- The PAG.- Returns:
- A Markov blanket of the target node.
-
district
-
isDag
-
convert
Converts a string spec of a graph--for example, "X1-->X2, X1---X3, X2o->X4, X3<->X4" to a Graph. The spec consists of a comma separated list of edge specs of the forms just used in the previous sentence. Unconnected nodes may be listed separately--example: "X,Y->Z". To specify a node as latent, use "Latent()." Example: "Latent(L1),Y->L1." -
gfciR0
public static void gfciR0(Graph graph, Graph referenceCpdag, SepsetProducer sepsets, Knowledge knowledge) -
fciOrientbk
Orients according to background knowledge -
trimGraph
-