Package edu.cmu.tetrad.graph
Class GraphUtils
java.lang.Object
edu.cmu.tetrad.graph.GraphUtils
Basic graph utilities.
- Author:
- Joseph Ramsey
-
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) adjacenciesComplement(Graph graph1, Graph graph2) static booleanallAdjacenciesAreDirected(Node node, 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 arrowpoints 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) getAmbiguousTriplesFromGraph(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) getNoncollidersFromGraph(Node node, Graph graph) 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 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) static GraphmarkovBlanketDag(Node target, Graph dag) Calculates the Markov blanket of a target in a DAG.maximalCliques(Graph graph, List<Node> nodes) static intnumBidirected(Graph result) static intnumDirectionalErrors(Graph result, Graph cpdag) static StringpathString(Graph graph, Node... x) static StringpathString(Graph graph, List<Node> path) static GraphremoveBidirectedEdges(Graph estCpdag) 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 voidretainUnshieldedColliders(Graph graph, Knowledge knowledge) Retains only the unshielded colliders of the given graph.static NodetraverseSemiDirected(Node node, Edge edge) static 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
-
markovBlanketDag
Calculates the Markov blanket of a target in a DAG. This includes the target, the parents of the target, the children of the target, the parents of the children of the target, edges from parents to target, target to children, parents of children to children, and parent to parents of children. (Edges among children are implied by the inclusion of edges from parents of children to children.) Edges among parents and among parents of children not explicitly included above are not included. (Joseph Ramsey 8/6/04)- Parameters:
target- a node in the given DAG.dag- the DAG with respect to which a Markov blanket DAG is to be calculated. All the nodes and edges of the Markov Blanket DAG are in this DAG.
-
allAdjacenciesAreDirected
-
removeBidirectedOrientations
-
removeBidirectedEdges
-
undirectedGraph
-
completeGraph
-
adjacenciesComplement
- Returns:
- the edges that are in
graph1but not ingraph2, as a list of undirected edges..
-
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 arrowpoints 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.
-
getNoncollidersFromGraph
- Returns:
- A list of triples of the form X, Y, Z, where X, Y, Z is a definite noncollider in the given graph.
-
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
-
numDirectionalErrors
-
numBidirected
-
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.
-
retainUnshieldedColliders
Retains only the unshielded colliders of the given graph.- Parameters:
graph- The graph to retain unshielded colliders in.
-
addForbiddenReverseEdgesForDirectedEdges
-
removeNonSkeletonEdges
-
compatible
-
pagMb
-
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".
-