use of edu.cmu.tetrad.data.DataReader in project tetrad by cmu-phil.
the class TestDeltaSextadTest method testBollenExampleb.
@Test
public void testBollenExampleb() {
DataSet data = null;
try {
String name = "src/test/resources/dataLG.txt";
DataReader reader = new DataReader();
data = reader.parseTabular(new File(name));
} catch (IOException e) {
e.printStackTrace();
}
int m1 = 0;
int m2 = 1;
int m3 = 2;
int m4 = 3;
int m5 = 4;
int m6 = 5;
IntSextad t1 = new IntSextad(m1, m2, m3, m4, m5, m6);
IntSextad t2 = new IntSextad(m1, m2, m4, m3, m5, m6);
IntSextad t3 = new IntSextad(m1, m2, m5, m3, m4, m6);
IntSextad t4 = new IntSextad(m1, m2, m6, m3, m4, m5);
IntSextad t5 = new IntSextad(m1, m3, m4, m2, m5, m6);
IntSextad t6 = new IntSextad(m1, m3, m5, m2, m4, m6);
IntSextad t7 = new IntSextad(m1, m3, m6, m2, m4, m5);
IntSextad t8 = new IntSextad(m1, m4, m5, m2, m3, m6);
IntSextad t9 = new IntSextad(m1, m4, m6, m2, m3, m5);
IntSextad t10 = new IntSextad(m1, m5, m6, m2, m3, m4);
DeltaSextadTest test = new DeltaSextadTest(data);
IntSextad[] _sextads = { t2, t5, t10, t3, t6 };
double p = test.getPValue(_sextads);
assertEquals(0.21, p, 0.01);
_sextads = new IntSextad[] { t10 };
p = test.getPValue(_sextads);
assertEquals(0.30, p, 0.01);
// This should throw an exception but doesn't.
// MySextad[] _sextads = {t1, t2, t3, t4, t5, t6, t7, t8, t9, t10};
}
use of edu.cmu.tetrad.data.DataReader in project tetrad by cmu-phil.
the class LoadContinuousDataAndSingleGraph method createData.
@Override
public void createData(Parameters parameters) {
this.dataSets = new ArrayList<>();
File dir = new File(path + "/" + subdir);
if (dir.exists()) {
File[] files = dir.listFiles();
for (File file : files) {
if (!file.getName().endsWith(".txt"))
continue;
System.out.println("Loading data from " + file.getAbsolutePath());
DataReader reader = new DataReader();
reader.setVariablesSupplied(true);
try {
DataSet dataSet = reader.parseTabular(file);
dataSets.add(dataSet);
if (!(dataSet.isContinuous())) {
throw new IllegalArgumentException("Not a continuous data set: " + dataSet.getName());
}
} catch (Exception e) {
System.out.println("Couldn't parse " + file.getAbsolutePath());
}
}
}
File dir2 = new File(path + "/graph");
if (dir2.exists()) {
File[] files = dir2.listFiles();
if (files.length != 1) {
throw new IllegalArgumentException("Expecting exactly one graph file.");
}
File file = files[0];
System.out.println("Loading graph from " + file.getAbsolutePath());
this.graph = GraphUtils.loadGraphTxt(file);
// if (!graph.isAdjacentTo(graph.getNode("X3"), graph.getNode("X4"))) {
// graph.addUndirectedEdge(graph.getNode("X3"), graph.getNode("X4"));
// }
GraphUtils.circleLayout(this.graph, 225, 200, 150);
}
if (parameters.get("numRuns") != null) {
parameters.set("numRuns", parameters.get("numRuns"));
} else {
parameters.set("numRuns", dataSets.size());
}
System.out.println();
}
use of edu.cmu.tetrad.data.DataReader in project tetrad by cmu-phil.
the class ExternalAlgorithmPcalgPc method search.
/**
* Reads in the relevant graph from the file (see above) and returns it.
*/
public Graph search(DataModel dataSet, Parameters parameters) {
int index = getIndex(dataSet);
File file = new File(path, "/results/" + extDir + "/" + (simIndex + 1) + "/graph." + index + ".txt");
System.out.println(file.getAbsolutePath());
try {
DataReader reader = new DataReader();
reader.setVariablesSupplied(true);
DataSet dataSet2 = reader.parseTabular(file);
System.out.println("Loading graph from " + file.getAbsolutePath());
Graph graph = loadGraphPcAlgMatrix(dataSet2);
GraphUtils.circleLayout(graph, 225, 200, 150);
return graph;
} catch (IOException e) {
throw new RuntimeException("Couldn't parse graph.");
}
}
use of edu.cmu.tetrad.data.DataReader in project tetrad by cmu-phil.
the class LoadContinuousDataAndGraphs method createData.
@Override
public void createData(Parameters parameters) {
this.dataSets = new ArrayList<>();
if (new File(path + "/data").exists()) {
int numDataSets = new File(path + "/data").listFiles().length;
try {
for (int i = 0; i < numDataSets; i++) {
File file2 = new File(path + "/graph/graph." + (i + 1) + ".txt");
System.out.println("Loading graph from " + file2.getAbsolutePath());
this.graphs.add(GraphUtils.loadGraphTxt(file2));
edu.cmu.tetrad.graph.GraphUtils.circleLayout(this.graphs.get(i), 225, 200, 150);
File file1 = new File(path + "/data/data." + (i + 1) + ".txt");
System.out.println("Loading data from " + file1.getAbsolutePath());
DataReader reader = new DataReader();
reader.setVariablesSupplied(true);
dataSets.add(reader.parseTabular(file1));
}
File paramFile = new File(path, "parameters.txt");
System.out.println("Loading parameters from " + paramFile.getAbsolutePath());
BufferedReader r = new BufferedReader(new FileReader(paramFile));
String line;
while ((line = r.readLine()) != null) {
if (line.contains(" = ")) {
String[] tokens = line.split(" = ");
String key = tokens[0];
String value = tokens[1];
usedParameters.add(key);
try {
double _value = Double.parseDouble(value);
parameters.set(key, _value);
} catch (NumberFormatException e) {
if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
parameters.set(key, Boolean.valueOf(value));
} else {
parameters.set(key, value);
}
}
System.out.println(key + " : " + value);
}
}
parameters.set("numRuns", numDataSets);
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of edu.cmu.tetrad.data.DataReader in project tetrad by cmu-phil.
the class LoadDataFromFileWithoutGraph method createData.
@Override
public void createData(Parameters parameters) {
try {
File file = new File(path);
System.out.println("Loading data from " + file.getAbsolutePath());
DataReader reader = new DataReader();
reader.setVariablesSupplied(false);
this.dataSet = reader.parseTabular(file);
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations