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);
}
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();
}
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;
}
Aggregations