Search in sources :

Example 1 with EdgeTypeProbability

use of edu.cmu.tetrad.graph.EdgeTypeProbability in project tetrad by cmu-phil.

the class JsonUtils method parseJSONObjectToEdgeTypeProperty.

public static EdgeTypeProbability parseJSONObjectToEdgeTypeProperty(JSONObject jObj) {
    String _edgeType = jObj.getString("edgeType");
    EdgeType edgeType = EdgeType.nil;
    switch(_edgeType) {
        case "ta":
            edgeType = EdgeType.ta;
            break;
        case "at":
            edgeType = EdgeType.at;
            break;
        case "ca":
            edgeType = EdgeType.ca;
            break;
        case "ac":
            edgeType = EdgeType.ac;
            break;
        case "cc":
            edgeType = EdgeType.cc;
            break;
        case "aa":
            edgeType = EdgeType.aa;
            break;
        case "tt":
            edgeType = EdgeType.tt;
            break;
    }
    double probability = jObj.getDouble("probability");
    EdgeTypeProbability edgeTypeProbability = new EdgeTypeProbability(edgeType, probability);
    return edgeTypeProbability;
}
Also used : EdgeTypeProbability(edu.cmu.tetrad.graph.EdgeTypeProbability) EdgeType(edu.cmu.tetrad.graph.EdgeTypeProbability.EdgeType)

Example 2 with EdgeTypeProbability

use of edu.cmu.tetrad.graph.EdgeTypeProbability in project tetrad by cmu-phil.

the class AbstractWorkbench method handleMouseEntered.

private void handleMouseEntered(MouseEvent e) {
    Object source = e.getSource();
    if (source instanceof DisplayEdge) {
        IDisplayEdge displayEdge = (DisplayEdge) source;
        Edge edge = displayEdge.getModelEdge();
        if (graph.containsEdge(edge)) {
            // Bootstrapping Distribution
            List<EdgeTypeProbability> edgeProb = edge.getEdgeTypeProbabilities();
            if (edgeProb != null) {
                String endpoint1 = edge.getEndpoint1().toString();
                switch(endpoint1) {
                    case "Tail":
                        endpoint1 = "-";
                        break;
                    case "Arrow":
                        endpoint1 = "&lt;";
                        break;
                    case "Circle":
                        endpoint1 = "o";
                        break;
                    case "Star":
                        endpoint1 = "&#42;";
                        break;
                    case "Null":
                        endpoint1 = "Null";
                        break;
                }
                String endpoint2 = edge.getEndpoint2().toString();
                switch(endpoint2) {
                    case "Tail":
                        endpoint2 = "-";
                        break;
                    case "Arrow":
                        endpoint2 = "&gt;";
                        break;
                    case "Circle":
                        endpoint2 = "o";
                        break;
                    case "Star":
                        endpoint2 = "&#42;";
                        break;
                    case "Null":
                        endpoint2 = "Null";
                        break;
                }
                String text = "<html>" + edge.getNode1().getName() + " " + endpoint1 + "-" + endpoint2 + " " + edge.getNode2().getName() + "<br>";
                String n1 = edge.getNode1().getName();
                String n2 = edge.getNode2().getName();
                List<String> nodes = new ArrayList<>();
                nodes.add(n1);
                nodes.add(n2);
                Collections.sort(nodes);
                for (EdgeTypeProbability edgeTypeProb : edgeProb) {
                    String _type = "" + edgeTypeProb.getEdgeType();
                    switch(edgeTypeProb.getEdgeType()) {
                        case nil:
                            _type = "no edge";
                            break;
                        case ta:
                            _type = "--&gt;";
                            _type = nodes.get(0) + " " + _type + " " + nodes.get(1);
                            break;
                        case at:
                            _type = "&lt;--";
                            _type = nodes.get(0) + " " + _type + " " + nodes.get(1);
                            break;
                        case ca:
                            _type = "o-&gt;";
                            _type = nodes.get(0) + " " + _type + " " + nodes.get(1);
                            break;
                        case ac:
                            _type = "&lt;-o";
                            _type = nodes.get(0) + " " + _type + " " + nodes.get(1);
                            break;
                        case cc:
                            _type = "o-o";
                            _type = nodes.get(0) + " " + _type + " " + nodes.get(1);
                            break;
                        case aa:
                            _type = "&lt;-&gt;";
                            _type = nodes.get(0) + " " + _type + " " + nodes.get(1);
                            break;
                        case tt:
                            _type = "---";
                            _type = nodes.get(0) + " " + _type + " " + nodes.get(1);
                            break;
                        default:
                            break;
                    }
                    if (edgeTypeProb.getProbability() > 0) {
                        text += "[" + _type + "]:" + String.format("%.4f", edgeTypeProb.getProbability());
                        text += "<br>";
                    }
                }
                // Commented out by Zhou
                // JLabel edgeTypeDistLabel = new JLabel(text);
                // edgeTypeDistLabel.setOpaque(true);
                // edgeTypeDistLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
                // setEdgeLabel(edge, edgeTypeDistLabel);
                // Use tooltip instead of label - Added by Zhou
                setEdgeToolTip(edge, text);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) EdgeTypeProbability(edu.cmu.tetrad.graph.EdgeTypeProbability) Edge(edu.cmu.tetrad.graph.Edge)

Aggregations

EdgeTypeProbability (edu.cmu.tetrad.graph.EdgeTypeProbability)2 Edge (edu.cmu.tetrad.graph.Edge)1 EdgeType (edu.cmu.tetrad.graph.EdgeTypeProbability.EdgeType)1 ArrayList (java.util.ArrayList)1