use of edu.cmu.tetrad.graph.Edge in project tetrad by cmu-phil.
the class AbstractWorkbench method directEdge.
/**
* Toggles endpoint A in the following sense: if it's a "o" make it a "-";
* if it's a "-", make it a ">"; if it's a ">", make it a "-".
*
* @param endpoint
* 1 for endpoint 1, 2 for endpoint 2.
*/
private void directEdge(IDisplayEdge graphEdge, int endpoint) {
Edge edge = graphEdge.getModelEdge();
if (edge == null) {
throw new IllegalStateException("Graph edge without model edge: " + graphEdge);
}
Edge newEdge;
if (endpoint == 1) {
newEdge = Edges.directedEdge(edge.getNode2(), edge.getNode1());
} else if (endpoint == 2) {
newEdge = Edges.directedEdge(edge.getNode1(), edge.getNode2());
} else {
throw new IllegalArgumentException("Endpoint number should be 1 or 2.");
}
getGraph().removeEdge(edge);
try {
boolean added = getGraph().addEdge(newEdge);
if (!added) {
getGraph().addEdge(edge);
JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Reorienting that edge would violate graph constraints.");
}
} catch (IllegalArgumentException e) {
getGraph().addEdge(edge);
JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Reorienting that edge would violate graph constraints.");
}
repaint();
}
use of edu.cmu.tetrad.graph.Edge in project tetrad by cmu-phil.
the class RequiredGraphModel method createKnowledge.
private void createKnowledge(Parameters params) {
IKnowledge knwl = getKnowledge();
if (knwl == null) {
return;
}
knwl.clear();
List<String> varNames = getVarNames();
getKnowledgeBoxInput().getVariableNames().stream().filter(e -> !e.startsWith("E_")).forEach(e -> {
varNames.add(e);
knwl.addVariable(e);
});
if (resultGraph == null) {
throw new NullPointerException("I couldn't find a parent graph.");
}
List<Node> nodes = resultGraph.getNodes();
int numOfNodes = nodes.size();
for (int i = 0; i < numOfNodes; i++) {
for (int j = i + 1; j < numOfNodes; j++) {
Node n1 = nodes.get(i);
Node n2 = nodes.get(j);
if (n1.getName().startsWith("E_") || n2.getName().startsWith("E_")) {
continue;
}
Edge edge = resultGraph.getEdge(n1, n2);
if (edge == null) {
continue;
} else if (edge.isDirected()) {
knwl.setRequired(edge.getNode1().getName(), edge.getNode2().getName());
} else if (Edges.isUndirectedEdge(edge)) {
knwl.setRequired(n1.getName(), n2.getName());
knwl.setRequired(n2.getName(), n1.getName());
}
}
}
}
use of edu.cmu.tetrad.graph.Edge in project tetrad by cmu-phil.
the class NumBidirectedEdges method getValue.
@Override
public double getValue(Graph trueGraph, Graph estGraph) {
int numBidirected = 0;
int numTotal = 0;
for (Edge edge : estGraph.getEdges()) {
if (Edges.isBidirectedEdge(edge)) {
numBidirected++;
}
numTotal++;
}
return numBidirected;
}
use of edu.cmu.tetrad.graph.Edge in project tetrad by cmu-phil.
the class PercentBidirectedEdges method getValue.
@Override
public double getValue(Graph trueGraph, Graph estGraph) {
int numBidirected = 0;
int numTotal = 0;
for (Edge edge : estGraph.getEdges()) {
if (Edges.isBidirectedEdge(edge)) {
numBidirected++;
}
numTotal++;
}
return numBidirected / (double) numTotal;
}
use of edu.cmu.tetrad.graph.Edge in project tetrad by cmu-phil.
the class PcStableMax method getNonadjacencies.
public Set<Edge> getNonadjacencies() {
Graph complete = GraphUtils.completeGraph(graph);
Set<Edge> nonAdjacencies = complete.getEdges();
Graph undirected = GraphUtils.undirectedGraph(graph);
nonAdjacencies.removeAll(undirected.getEdges());
return new HashSet<>(nonAdjacencies);
}
Aggregations