Search in sources :

Example 41 with Edge

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

the class ExploreAutisticsNeurotypicals method getAllTrekEdges.

public static List<Edge> getAllTrekEdges(List<List<Graph>> graphs, int maxLength) {
    List<Node> nodes = graphs.get(0).get(0).getNodes();
    ContinuousVariable group = new ContinuousVariable("Group");
    nodes.add(group);
    graphs = reconcileNodes(graphs);
    int numGraphs = getNumGraphs(graphs);
    DataSet dataSet = new BoxDataSet(new VerticalDoubleDataBox(numGraphs, nodes.size()), nodes);
    for (int i = 0; i < dataSet.getNumRows(); i++) {
        for (int j = 0; j < dataSet.getNumColumns(); j++) {
            dataSet.setDouble(i, j, 0);
        }
    }
    Node fusiformLeft = graphs.get(0).get(0).getNode("Fusiform_L");
    Node fusiformRight = graphs.get(0).get(0).getNode("Fusiform_R");
    Set<Edge> trekEdges = new HashSet<>();
    for (int _group = 0; _group < graphs.size(); _group++) {
        List<Graph> __graphs = graphs.get(_group);
        for (Graph graph : __graphs) {
            List<List<Node>> treks = GraphUtils.treks(graph, fusiformLeft, fusiformRight, maxLength);
            for (List<Node> trek : treks) {
                for (int i = 0; i < trek.size() - 2; i++) {
                    trekEdges.add(graph.getEdge(trek.get(i), trek.get(i + 1)));
                }
            }
        }
    }
    return new ArrayList<>(trekEdges);
}
Also used : Node(edu.cmu.tetrad.graph.Node) ArrayList(java.util.ArrayList) Graph(edu.cmu.tetrad.graph.Graph) ArrayList(java.util.ArrayList) List(java.util.List) Edge(edu.cmu.tetrad.graph.Edge) HashSet(java.util.HashSet)

Example 42 with Edge

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

the class TestAutisticClassification method trainTest.

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

Example 43 with Edge

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

the class TestAutisticClassification method test.

private int test(int i, List<String> filenames, List<Graph> graphs, List<Boolean> types, List<List<Edge>> ret) {
    Graph testGraph = graphs.get(i);
    List<Edge> forAutisismIfPresent = ret.get(0);
    List<Edge> forAutisismIfAbsent = ret.get(1);
    List<Edge> forTypicalIfPresent = ret.get(2);
    List<Edge> forTypicalIfAbsent = ret.get(3);
    List<Edge> presentAutistic = new ArrayList<>();
    List<Edge> absentAutistic = new ArrayList<>();
    List<Edge> presentTypical = new ArrayList<>();
    List<Edge> absentTypical = new ArrayList<>();
    for (Edge edge : forAutisismIfPresent) {
        if (testGraph.containsEdge(edge)) {
            presentAutistic.add(edge);
        }
    }
    for (Edge edge : forAutisismIfAbsent) {
        if (!testGraph.containsEdge(edge)) {
            absentAutistic.add(edge);
        }
    }
    for (Edge edge : forTypicalIfPresent) {
        if (testGraph.containsEdge(edge)) {
            presentTypical.add(edge);
        }
    }
    for (Edge edge : forTypicalIfAbsent) {
        if (!testGraph.containsEdge(edge)) {
            absentTypical.add(edge);
        }
    }
    boolean autistic = false;
    boolean typical = false;
    if (!absentAutistic.isEmpty()) {
        autistic = true;
    }
    if (!presentAutistic.isEmpty()) {
        autistic = true;
    }
    if (!presentTypical.isEmpty()) {
        typical = true;
    }
    if (!absentTypical.isEmpty()) {
        typical = true;
    }
    String name = "" + (i + 1) + ". " + filenames.get(i) + ". ";
    if (autistic && !typical) {
        System.out.println(name + ". Autistic");
    } else if (typical && !autistic) {
        System.out.println(name + ". Typical");
    }
    if (autistic && !typical) {
        for (Edge aPresent : presentAutistic) {
            System.out.println("..... present autistic " + aPresent);
        }
        for (Edge anAbsent : absentAutistic) {
            System.out.println("..... absent autistic " + anAbsent);
        }
    }
    if (typical && !autistic) {
        for (Edge aPresent : presentTypical) {
            System.out.println("..... present typical " + aPresent);
        }
        for (Edge anAbsent : absentTypical) {
            System.out.println("..... absent typical " + anAbsent);
        }
    }
    if (autistic && !typical) {
        if (types.get(i)) {
            return 1;
        } else {
            return -1;
        }
    }
    if (typical && !autistic) {
        if (!types.get(i)) {
            return 1;
        } else {
            return -1;
        }
    }
    return 0;
}
Also used : Graph(edu.cmu.tetrad.graph.Graph) 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