use of edu.cmu.tetrad.bayes.BayesPm in project tetrad by cmu-phil.
the class TestBayesPm method testInitializeRandom.
@Test
public void testInitializeRandom() {
Graph graph = GraphConverter.convert("X1-->X2,X1-->X3,X2-->X4,X3-->X4");
Dag dag = new Dag(graph);
BayesPm bayesPm = new BayesPm(dag, 2, 5);
List<Node> nodes = dag.getNodes();
for (Node node1 : nodes) {
int numValues = bayesPm.getNumCategories(node1);
assertTrue("Number of values out of range: " + numValues, numValues >= 2 && numValues <= 5);
}
}
use of edu.cmu.tetrad.bayes.BayesPm in project tetrad by cmu-phil.
the class TestBayesPm method testInitializeFixed.
@Test
public void testInitializeFixed() {
Graph graph = GraphConverter.convert("X1-->X2,X1-->X3,X2-->X4,X3-->X4");
Dag dag = new Dag(graph);
BayesPm bayesPm = new BayesPm(dag, 3, 3);
List<Node> nodes = dag.getNodes();
for (Node node1 : nodes) {
assertEquals(3, bayesPm.getNumCategories(node1));
}
}
use of edu.cmu.tetrad.bayes.BayesPm in project tetrad by cmu-phil.
the class TestCellProbabilities method testCreateUsingBayesIm.
@Test
public void testCreateUsingBayesIm() {
RandomUtil.getInstance().setSeed(4828385834L);
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);
StoredCellProbs cellProbs = StoredCellProbs.createCellTable(bayesIm);
double prob = cellProbs.getCellProb(new int[] { 0, 0, 0, 0 });
assertEquals(0.0058, prob, 0.0001);
}
use of edu.cmu.tetrad.bayes.BayesPm in project tetrad by cmu-phil.
the class TestDataLoadersRoundtrip method testDiscreteRoundtrip.
@Test
public void testDiscreteRoundtrip() {
setUp();
try {
for (int i = 0; i < 1; i++) {
List<Node> nodes = new ArrayList<>();
for (int j = 0; j < 5; j++) {
nodes.add(new ContinuousVariable("X" + (j + 1)));
}
Graph randomGraph = new Dag(GraphUtils.randomGraph(nodes, 0, 8, 30, 15, 15, false));
Dag dag = new Dag(randomGraph);
BayesPm bayesPm1 = new BayesPm(dag);
MlBayesIm bayesIm1 = new MlBayesIm(bayesPm1, MlBayesIm.RANDOM);
DataSet dataSet = bayesIm1.simulateData(10, false);
new File("target/test_data").mkdir();
FileWriter fileWriter = new FileWriter("target/test_data/roundtrip.dat");
Writer writer = new PrintWriter(fileWriter);
DataWriter.writeRectangularData(dataSet, writer, '\t');
writer.close();
File file = new File("target/test_data/roundtrip.dat");
DataReader reader = new DataReader();
reader.setKnownVariables(dataSet.getVariables());
DataSet _dataSet = reader.parseTabular(file);
assertTrue(dataSet.equals(_dataSet));
}
} catch (IOException e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of edu.cmu.tetrad.bayes.BayesPm in project tetrad by cmu-phil.
the class TestGFci method testRandomDiscreteData.
@Test
public void testRandomDiscreteData() {
int sampleSize = 1000;
Graph g = GraphConverter.convert("X1-->X2,X1-->X3,X1-->X4,X2-->X3,X2-->X4,X3-->X4");
Dag dag = new Dag(g);
BayesPm bayesPm = new BayesPm(dag);
BayesIm bayesIm = new MlBayesIm(bayesPm, MlBayesIm.RANDOM);
DataSet data = bayesIm.simulateData(sampleSize, false);
IndependenceTest test = new IndTestChiSquare(data, 0.05);
BDeuScore bDeuScore = new BDeuScore(data);
bDeuScore.setSamplePrior(1.0);
bDeuScore.setStructurePrior(1.0);
GFci gFci = new GFci(test, bDeuScore);
gFci.setFaithfulnessAssumed(true);
long start = System.currentTimeMillis();
gFci.search();
long stop = System.currentTimeMillis();
System.out.println("Elapsed " + (stop - start) + " ms");
DagToPag dagToPag = new DagToPag(g);
dagToPag.setVerbose(false);
}
Aggregations