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 classstatic class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddForbiddenReverseEdgesForDirectedEdges(Graph graph, Knowledge knowledge) static voidaddPagColoring(Graph graph) Constructs a list of nodes from the givennodeslist at the given indices in that list.static GraphbidirectedToUndirected(Graph graph) static booleancompatible(Edge edge1, Edge edge2) static GraphcompleteGraph(Graph graph) static booleancontainsBidirectedEdge(Graph graph) static GraphConverts a string spec of a graph--for example, "X1-->X2, X1---X3, X2o->X4, X3<->X4" to a Graph.static intcountAdjErrors(Graph graph1, Graph graph2) Counts the adjacencies that are in graph1 but not in graph2.static intcountArrowptErrors(Graph graph1, Graph graph2) Counts the arrowheads that are in graph1 but not in graph2.static intstatic int[][]edgeMisclassificationCounts(Graph leftGraph, Graph topGraph, boolean print) static StringedgeMisclassifications(double[][] counts, NumberFormat nf) static StringedgeMisclassifications(int[][] counts) static GraphemptyGraph(int numNodes) static voidfciOrientbk(Knowledge knowledge, Graph graph, List<Node> variables) Orients according to background knowledgegetAmbiguousTriplesFromGraph(Node node, Graph graph) static NodegetAssociatedNode(Node errorNode, Graph graph) static GraphgetComparisonGraph(Graph graph, Parameters params) static intgetDottedUnderlinedTriplesFromGraph(Node node, Graph graph) static intgetIndegree(Graph graph) static StringgetIntersectionComparisonString(List<Graph> graphs) static intgetNumCorrectArrowpts(Graph correct, Graph estimated) static GraphUtils.TwoCycleErrorsgetTwoCycleErrors(Graph trueGraph, Graph estGraph) getUnderlinedTriplesFromGraph(Node node, Graph graph) static voidgfciExtraEdgeRemovalStep(Graph graph, Graph referenceCpdag, List<Node> nodes, SepsetProducer sepsets) The extra edge removal step for GFCI.static voidgfciR0(Graph graph, Graph referenceCpdag, SepsetProducer sepsets, Knowledge knowledge) static StringgraphAttributesToText(Graph graph, String title) static StringgraphEdgesToText(Graph graph, String title) static StringgraphNodeAttributesToText(Graph graph, String title, char delimiter) static StringgraphNodesToText(Graph graph, String title, char delimiter) static StringgraphToText(Graph graph, boolean doPagColoring) static booleanisClique(Collection<Node> set, Graph graph) static booleanstatic 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 GraphmarkovBlanketSubgraph(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 StringpathString(Graph graph, Node... x) static StringpathString(Graph graph, List<Node> path) static GraphremoveBidirectedOrientations(Graph estCpdag) static voidremoveNonSkeletonEdges(Graph graph, Knowledge knowledge) static GraphreplaceNodes(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 GraphrestrictToMeasured(Graph graph) static NodetraverseSemiDirected(Node node, Edge edge) static Graphstatic StringtriplesToText(Set<Triple> triples, String title) static GraphundirectedGraph(Graph graph) static GraphundirectedToBidirected(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
setis 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 givennodeslist 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
-