use of edu.cmu.tetrad.graph.EdgeListGraph in project tetrad by cmu-phil.
the class LoadContinuousDataSmithSim method readGraph.
public Graph readGraph(File file) {
try {
DataReader reader = new DataReader();
reader.setVariablesSupplied(false);
reader.setDelimiter(DelimiterType.COMMA);
DataSet data = reader.parseTabular(file);
List<Node> variables = data.getVariables();
List<Node> _variables = new ArrayList<>();
for (int i = 0; i < variables.size(); i++) {
_variables.add(new ContinuousVariable(variables.get(i).getName()));
}
Graph graph = new EdgeListGraph(_variables);
for (int i = 0; i < _variables.size(); i++) {
for (int j = 0; j < _variables.size(); j++) {
if (i == j)
continue;
if (data.getDouble(i, j) != 0) {
graph.addDirectedEdge(_variables.get(i), _variables.get(j));
}
}
}
return graph;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations