Search in sources :

Example 16 with Edge

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();
}
Also used : Edge(edu.cmu.tetrad.graph.Edge)

Example 17 with Edge

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());
            }
        }
    }
}
Also used : EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) SortedSet(java.util.SortedSet) IKnowledge(edu.cmu.tetrad.data.IKnowledge) TetradLogger(edu.cmu.tetrad.util.TetradLogger) Graph(edu.cmu.tetrad.graph.Graph) Parameters(edu.cmu.tetrad.util.Parameters) TetradSerializableUtils(edu.cmu.tetrad.util.TetradSerializableUtils) Node(edu.cmu.tetrad.graph.Node) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Edges(edu.cmu.tetrad.graph.Edges) List(java.util.List) KnowledgeBoxInput(edu.cmu.tetrad.data.KnowledgeBoxInput) Edge(edu.cmu.tetrad.graph.Edge) Knowledge2(edu.cmu.tetrad.data.Knowledge2) IKnowledge(edu.cmu.tetrad.data.IKnowledge) Node(edu.cmu.tetrad.graph.Node) Edge(edu.cmu.tetrad.graph.Edge)

Example 18 with Edge

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;
}
Also used : Edge(edu.cmu.tetrad.graph.Edge)

Example 19 with Edge

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;
}
Also used : Edge(edu.cmu.tetrad.graph.Edge)

Example 20 with Edge

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);
}
Also used : Graph(edu.cmu.tetrad.graph.Graph) Edge(edu.cmu.tetrad.graph.Edge) HashSet(java.util.HashSet)

Aggregations

Edge (edu.cmu.tetrad.graph.Edge)43 Node (edu.cmu.tetrad.graph.Node)23 Graph (edu.cmu.tetrad.graph.Graph)14 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)11 ArrayList (java.util.ArrayList)7 GraphNode (edu.cmu.tetrad.graph.GraphNode)5 Endpoint (edu.cmu.tetrad.graph.Endpoint)4 SessionNode (edu.cmu.tetrad.session.SessionNode)4 List (java.util.List)4 Knowledge2 (edu.cmu.tetrad.data.Knowledge2)3 Parameters (edu.cmu.tetrad.util.Parameters)3 SessionNodeWrapper (edu.cmu.tetradapp.model.SessionNodeWrapper)3 Point (java.awt.Point)3 HashSet (java.util.HashSet)3 TakesInitialGraph (edu.cmu.tetrad.algcomparison.utils.TakesInitialGraph)2 IKnowledge (edu.cmu.tetrad.data.IKnowledge)2 KnowledgeBoxInput (edu.cmu.tetrad.data.KnowledgeBoxInput)2 KnowledgeEdge (edu.cmu.tetrad.data.KnowledgeEdge)2 TetradLogger (edu.cmu.tetrad.util.TetradLogger)2 TetradSerializableUtils (edu.cmu.tetrad.util.TetradSerializableUtils)2