use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.
the class TestDataSetCellProbs method testCreateUsingBayesIm.
@Test
public void testCreateUsingBayesIm() {
Graph graph = GraphConverter.convert("X1-->X2,X1-->X3,X2-->X4,X3-->X4");
Dag dag = new Dag(graph);
BayesPm bayesPm = new BayesPm(dag);
BayesIm bayesIm = new MlBayesIm(bayesPm, MlBayesIm.RANDOM);
BayesImProbs bayesImProbs = new BayesImProbs(bayesIm);
DataSet dataSet = bayesIm.simulateData(1000, false);
CellTableProbs dataSetProbs = new CellTableProbs(dataSet);
int[] cell = new int[4];
for (int i = 0; i < 200; i++) {
for (int j = 0; j < 4; j++) {
cell[j] = RandomUtil.getInstance().nextInt(bayesIm.getNumColumns(j));
}
double count1 = bayesImProbs.getCellProb(cell);
double count2 = dataSetProbs.getCellProb(cell);
assertEquals(count1, count2, .05);
}
}
use of edu.cmu.tetrad.data.DataSet 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.DataSet 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.DataSet in project tetrad by cmu-phil.
the class SpecialDataClark method createData.
@Override
public void createData(Parameters parameters) {
Graph graph = randomGraph.createGraph(parameters);
dataSets = new ArrayList<>();
graphs = new ArrayList<>();
for (int i = 0; i < parameters.getInt("numRuns"); i++) {
System.out.println("Simulating dataset #" + (i + 1));
if (parameters.getBoolean("differentGraphs") && i > 0) {
graph = randomGraph.createGraph(parameters);
}
graphs.add(graph);
DataSet dataSet = simulate(graph, parameters);
dataSet.setName("" + (i + 1));
dataSets.add(dataSet);
}
}
use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.
the class Cfci method search.
@Override
public Graph search(DataModel dataSet, Parameters parameters) {
if (parameters.getInt("bootstrapSampleSize") < 1) {
edu.cmu.tetrad.search.Cfci search = new edu.cmu.tetrad.search.Cfci(test.getTest(dataSet, parameters));
search.setKnowledge(knowledge);
search.setCompleteRuleSetUsed(parameters.getBoolean("completeRuleSetUsed"));
search.setDepth(parameters.getInt("depth"));
return search.search();
} else {
Cfci algorithm = new Cfci(test);
DataSet data = (DataSet) dataSet;
GeneralBootstrapTest search = new GeneralBootstrapTest(data, algorithm, parameters.getInt("bootstrapSampleSize"));
search.setKnowledge(knowledge);
BootstrapEdgeEnsemble edgeEnsemble = BootstrapEdgeEnsemble.Highest;
switch(parameters.getInt("bootstrapEnsemble", 1)) {
case 0:
edgeEnsemble = BootstrapEdgeEnsemble.Preserved;
break;
case 1:
edgeEnsemble = BootstrapEdgeEnsemble.Highest;
break;
case 2:
edgeEnsemble = BootstrapEdgeEnsemble.Majority;
}
search.setEdgeEnsemble(edgeEnsemble);
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean("verbose"));
return search.search();
}
}
Aggregations