Search in sources :

Example 1 with Edge

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

the class TestAutisticClassification method printFiles.

private void printFiles(List<Graph> _graphs, List<Boolean> types, int i, List<List<Edge>> ret) {
    try {
        List<Edge> sublist = ret.get(4);
        File dir2 = new File("/Users/jdramsey/Downloads/alldata");
        dir2.mkdirs();
        PrintStream out = new PrintStream(new File(dir2, "data" + (i + 1) + ".txt"));
        for (int j = 0; j < sublist.size(); j++) {
            out.print("X" + (j + 1) + "\t");
        }
        out.println("T");
        for (int k = 0; k < _graphs.size(); k++) {
            for (Edge edge : sublist) {
                out.print(_graphs.get(k).containsEdge(edge) ? "1\t" : "0\t");
            }
            out.println(types.get(k) ? "1" : "0");
        }
        out.close();
        File dir3 = new File("/Users/jdramsey/Downloads/allkeys");
        dir3.mkdirs();
        PrintStream keyOut = new PrintStream(new File(dir3, "key" + (i + 1) + ".txt"));
        for (int j = 0; j < sublist.size(); j++) {
            keyOut.println("X" + (j + 1) + ". " + sublist.get(j));
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}
Also used : PrintStream(java.io.PrintStream) FileNotFoundException(java.io.FileNotFoundException) Edge(edu.cmu.tetrad.graph.Edge) File(java.io.File)

Example 2 with Edge

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

the class TestAutisticClassification method train.

private List<List<Edge>> train(List<Graph> trainingGraphs, List<Edge> allEdges, List<Boolean> types) {
    double[] truth = getTruth(trainingGraphs, types);
    List<Edge> forAutismIfPresent = new ArrayList<>();
    List<Edge> forAutismIfAbsent = new ArrayList<>();
    List<Edge> forTypicalIfPresent = new ArrayList<>();
    List<Edge> forTypicalIfAbsent = new ArrayList<>();
    for (Edge edge : allEdges) {
        double[] est = getEst(trainingGraphs, edge);
        if (cond(est, truth, 1, 1, cutoffPresent)) {
            forAutismIfPresent.add(edge);
        }
        if (cond(est, truth, 0, 1, cutoffAbsent)) {
            forAutismIfAbsent.add(edge);
        }
        if (cond(est, truth, 1, 0, cutoffPresent)) {
            forTypicalIfPresent.add(edge);
        }
        if (cond(est, truth, 0, 0, cutoffAbsent)) {
            forTypicalIfAbsent.add(edge);
        }
    }
    Set<Edge> sublist = new HashSet<>();
    sublist.addAll(forAutismIfPresent);
    sublist.addAll(forAutismIfAbsent);
    sublist.addAll(forTypicalIfPresent);
    sublist.addAll(forTypicalIfAbsent);
    List<Edge> _sublist = new ArrayList<>(sublist);
    // return from train.
    List<List<Edge>> ret = new ArrayList<>();
    ret.add(forAutismIfPresent);
    ret.add(forAutismIfAbsent);
    ret.add(forTypicalIfPresent);
    ret.add(forTypicalIfAbsent);
    ret.add(_sublist);
    return ret;
}
Also used : Edge(edu.cmu.tetrad.graph.Edge)

Example 3 with Edge

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

the class TestAutisticClassification method getAllEdges.

private List<Edge> getAllEdges(List<Graph> _graphs, List<Boolean> types, List<Graph> trainingGraphs) {
    Map<Edge, Double> autisticEdgeCount = new HashMap<>();
    Map<Edge, Double> typicalEdgeCount = new HashMap<>();
    Set<Edge> allEdgesSet = new HashSet<>();
    for (int k = 0; k < trainingGraphs.size(); k++) {
        for (Edge edge : trainingGraphs.get(k).getEdges()) {
            if (types.get(k)) {
                countEdge(autisticEdgeCount, edge);
            } else {
                countEdge(typicalEdgeCount, edge);
            }
        }
        allEdgesSet.addAll(_graphs.get(k).getEdges());
    }
    return new ArrayList<>(allEdgesSet);
}
Also used : Edge(edu.cmu.tetrad.graph.Edge)

Example 4 with Edge

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

the class TestAutisticClassification method leaveOneOut.

private void leaveOneOut(FaskGraphs train) {
    int numTp = 0;
    int numFp = 0;
    int numUnclassified = 0;
    for (int i = 0; i < train.getGraphs().size(); i++) {
        List<Graph> trainingGraphs = new ArrayList<>(train.getGraphs());
        trainingGraphs.remove(train.getGraphs().get(i));
        List<Edge> allEdges = getAllEdges(train.getGraphs(), train.getTypes(), trainingGraphs);
        List<List<Edge>> ret = train(trainingGraphs, allEdges, train.getTypes());
        int _class = test(i, train.getFilenames(), train.getGraphs(), train.getTypes(), ret);
        if (_class == 1)
            numTp++;
        if (_class == -1)
            numFp++;
        if (_class == 0)
            numUnclassified++;
        printFiles(train.getGraphs(), train.getTypes(), i, ret);
    }
    System.out.println();
    System.out.println("# TP = " + numTp);
    System.out.println("# FP = " + numFp);
    System.out.println("# Unclassified = " + numUnclassified);
    NumberFormat nf = new DecimalFormat("0.00");
    System.out.println("Precision = " + nf.format((numTp / (double) (numTp + numFp))));
    System.out.println();
}
Also used : Graph(edu.cmu.tetrad.graph.Graph) DecimalFormat(java.text.DecimalFormat) Edge(edu.cmu.tetrad.graph.Edge) NumberFormat(java.text.NumberFormat)

Example 5 with Edge

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

the class SessionEditor method getSelectedModelComponents.

/**
 * @return a list of all the SessionNodeWrappers (TetradNodes) and
 * SessionNodeEdges that are model components for the respective
 * SessionNodes and SessionEdges selected in the workbench. Note that the
 * workbench, not the SessionEditorNodes themselves, keeps track of the
 * selection.
 */
public List getSelectedModelComponents() {
    List selectedComponents = getWorkbench().getSelectedComponents();
    List selectedModelComponents = new ArrayList();
    for (Object comp : selectedComponents) {
        if (comp instanceof SessionEditorNode) {
            SessionEditorNode editorNode = (SessionEditorNode) comp;
            Node modelNode = editorNode.getModelNode();
            selectedModelComponents.add(modelNode);
        } else if (comp instanceof SessionEditorEdge) {
            SessionEditorEdge editorEdge = (SessionEditorEdge) comp;
            Edge modelEdge = getWorkbench().getModelEdge(editorEdge);
            selectedModelComponents.add(modelEdge);
        }
    }
    return selectedModelComponents;
}
Also used : Node(edu.cmu.tetrad.graph.Node) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Edge(edu.cmu.tetrad.graph.Edge)

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