use of edu.cmu.tetrad.graph.Triple in project tetrad by cmu-phil.
the class FciOrientT method findCollidersUsingSepsets.
/**
* Step C of PC; orients colliders using specified sepset. That is, orients x *-* y *-* z as x *-> y <-* z just in
* case y is in Sepset({x, z}).
*/
public List<Triple> findCollidersUsingSepsets(SepsetProducer sepsetProducer, Graph graph, boolean verbose) {
TetradLogger.getInstance().log("details", "Starting Collider Orientation:");
List<Triple> colliders = new ArrayList<>();
List<Node> nodes = graph.getNodes();
for (Node b : nodes) {
List<Node> adjacentNodes = graph.getAdjacentNodes(b);
if (adjacentNodes.size() < 2) {
continue;
}
ChoiceGenerator cg = new ChoiceGenerator(adjacentNodes.size(), 2);
int[] combination;
while ((combination = cg.next()) != null) {
Node a = adjacentNodes.get(combination[0]);
Node c = adjacentNodes.get(combination[1]);
// Skip triples that are shielded.
if (graph.isAdjacentTo(a, c)) {
continue;
}
List<Node> sepset = sepsetProducer.getSepset(a, c);
//
if (sepset == null)
continue;
if (!sepset.contains(b)) {
if (verbose) {
System.out.println("Collider orientation <" + a + ", " + b + ", " + c + "> sepset = " + sepset);
}
colliders.add(new Triple(a, b, c));
TetradLogger.getInstance().log("colliderOrientations", SearchLogUtils.colliderOrientedMsg(a, b, c, sepset));
}
}
}
TetradLogger.getInstance().log("details", "Finishing Collider Orientation.");
return colliders;
}
use of edu.cmu.tetrad.graph.Triple in project tetrad by cmu-phil.
the class FciOrientT method addColliders.
private void addColliders(Graph graph, final SepsetProducer sepsetProducer, IKnowledge knowledge) {
List<Triple> colliders = findCollidersUsingSepsets(sepsetProducer, graph, verbose);
for (Triple collider : colliders) {
Node a = collider.getX();
Node b = collider.getY();
Node c = collider.getZ();
if (!(isArrowpointAllowed(a, b, graph) && isArrowpointAllowed(c, b, graph))) {
continue;
}
graph.setEndpoint(a, b, Endpoint.ARROW);
graph.setEndpoint(c, b, Endpoint.ARROW);
}
}
use of edu.cmu.tetrad.graph.Triple in project tetrad by cmu-phil.
the class TriplesAction method actionPerformed.
/**
* Copies a parentally closed selection of session nodes in the frontmost
* session editor to the clipboard.
*/
public void actionPerformed(ActionEvent e) {
Box b = Box.createVerticalBox();
JTextArea textArea = new JTextArea();
JScrollPane scroll = new JScrollPane(textArea);
scroll.setPreferredSize(new Dimension(600, 600));
textArea.append("Underlinings:");
boolean allEmpty = true;
List<Node> nodes = graph.getNodes();
Collections.sort(nodes, new Comparator<Node>() {
public int compare(Node node1, Node node2) {
return node1.getName().compareTo(node2.getName());
}
});
for (int i = 0; i < nodes.size(); i++) {
Node node = nodes.get(i);
List<String> types = graph.getTriplesClassificationTypes();
List<List<Triple>> triplesList = graph.getTriplesLists(node);
boolean existsClassification = false;
for (List<Triple> list : triplesList) {
if (!list.isEmpty()) {
existsClassification = true;
}
}
if (!existsClassification) {
continue;
}
textArea.append("\n\nNode " + node);
for (int j = 0; j < types.size(); j++) {
String type = types.get(j);
List<Triple> triples = triplesList.get(j);
if (!triples.isEmpty()) {
textArea.append("\n\n ");
textArea.append(type + niceList(triples));
}
}
allEmpty = false;
}
if (allEmpty) {
textArea.append("\n\nAll triple classifications can be read from the graph.");
}
Box b2 = Box.createHorizontalBox();
b2.add(scroll);
textArea.setCaretPosition(0);
b.add(b2);
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(b);
EditorWindow window = new EditorWindow(panel, "Underlinings", "Close", false, JOptionUtils.centeringComp());
DesktopController.getInstance().addEditorWindow(window, JLayeredPane.PALETTE_LAYER);
window.setVisible(true);
// JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), b,
// "Graph Properties", JOptionPane.PLAIN_MESSAGE);
}
use of edu.cmu.tetrad.graph.Triple in project tetrad by cmu-phil.
the class JsonUtils method parseJSONObjectToTetradGraph.
public static Graph parseJSONObjectToTetradGraph(JSONObject jObj) {
// Node
List<Node> nodes = parseJSONArrayToTetradNodes(jObj.getJSONArray("nodes"));
EdgeListGraphSingleConnections graph = new EdgeListGraphSingleConnections(nodes);
// Edge
Set<Edge> edges = parseJSONArrayToTetradEdges(graph, jObj.getJSONArray("edgesSet"));
for (Edge edge : edges) {
graph.addEdge(edge);
}
// ambiguousTriples
Set<Triple> ambiguousTriples = parseJSONArrayToTetradTriples(jObj.getJSONArray("ambiguousTriples"));
for (Triple triple : ambiguousTriples) {
graph.addAmbiguousTriple(triple.getX(), triple.getY(), triple.getZ());
}
// underLineTriples
Set<Triple> underLineTriples = parseJSONArrayToTetradTriples(jObj.getJSONArray("underLineTriples"));
for (Triple triple : underLineTriples) {
graph.addUnderlineTriple(triple.getX(), triple.getY(), triple.getZ());
}
// dottedUnderLineTriples
Set<Triple> dottedUnderLineTriples = parseJSONArrayToTetradTriples(jObj.getJSONArray("dottedUnderLineTriples"));
for (Triple triple : dottedUnderLineTriples) {
graph.addDottedUnderlineTriple(triple.getX(), triple.getY(), triple.getZ());
}
// stuffRemovedSinceLastTripleAccess
boolean stuffRemovedSinceLastTripleAccess = jObj.getBoolean("stuffRemovedSinceLastTripleAccess");
graph.setStuffRemovedSinceLastTripleAccess(stuffRemovedSinceLastTripleAccess);
// highlightedEdges
Set<Edge> highlightedEdges = parseJSONArrayToTetradEdges(graph, jObj.getJSONArray("highlightedEdges"));
for (Edge edge : highlightedEdges) {
graph.setHighlighted(edge, true);
}
return graph;
}
use of edu.cmu.tetrad.graph.Triple in project tetrad by cmu-phil.
the class JsonUtils method parseJSONArrayToTetradTriples.
public static Set<Triple> parseJSONArrayToTetradTriples(JSONArray jArray) {
Set<Triple> triples = new HashSet<>();
for (int i = 0; i < jArray.length(); i++) {
Triple triple = parseJSONArrayToTetradTriple(jArray.getJSONObject(i));
triples.add(triple);
}
return triples;
}
Aggregations