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