Search in sources :

Example 6 with BayesPm

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);
    }
}
Also used : BayesPm(edu.cmu.tetrad.bayes.BayesPm) Test(org.junit.Test)

Example 7 with BayesPm

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));
    }
}
Also used : BayesPm(edu.cmu.tetrad.bayes.BayesPm) Test(org.junit.Test)

Example 8 with BayesPm

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);
}
Also used : Graph(edu.cmu.tetrad.graph.Graph) MlBayesIm(edu.cmu.tetrad.bayes.MlBayesIm) BayesIm(edu.cmu.tetrad.bayes.BayesIm) MlBayesIm(edu.cmu.tetrad.bayes.MlBayesIm) StoredCellProbs(edu.cmu.tetrad.bayes.StoredCellProbs) Dag(edu.cmu.tetrad.graph.Dag) BayesPm(edu.cmu.tetrad.bayes.BayesPm) Test(org.junit.Test)

Example 9 with BayesPm

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());
    }
}
Also used : MlBayesIm(edu.cmu.tetrad.bayes.MlBayesIm) Node(edu.cmu.tetrad.graph.Node) ArrayList(java.util.ArrayList) Dag(edu.cmu.tetrad.graph.Dag) Graph(edu.cmu.tetrad.graph.Graph) BayesPm(edu.cmu.tetrad.bayes.BayesPm) Test(org.junit.Test)

Example 10 with BayesPm

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);
}
Also used : MlBayesIm(edu.cmu.tetrad.bayes.MlBayesIm) BayesIm(edu.cmu.tetrad.bayes.BayesIm) MlBayesIm(edu.cmu.tetrad.bayes.MlBayesIm) BayesPm(edu.cmu.tetrad.bayes.BayesPm) Test(org.junit.Test)

Aggregations

BayesPm (edu.cmu.tetrad.bayes.BayesPm)38 MlBayesIm (edu.cmu.tetrad.bayes.MlBayesIm)23 BayesIm (edu.cmu.tetrad.bayes.BayesIm)18 Test (org.junit.Test)17 Node (edu.cmu.tetrad.graph.Node)14 Graph (edu.cmu.tetrad.graph.Graph)10 DataSet (edu.cmu.tetrad.data.DataSet)6 Dag (edu.cmu.tetrad.graph.Dag)6 DisplayNode (edu.cmu.tetradapp.workbench.DisplayNode)6 ArrayList (java.util.ArrayList)6 List (java.util.List)5 BayesProperties (edu.cmu.tetrad.bayes.BayesProperties)4 LargeScaleSimulation (edu.cmu.tetrad.sem.LargeScaleSimulation)4 Algorithm (edu.cmu.tetrad.algcomparison.algorithm.Algorithm)3 GraphNode (edu.cmu.tetrad.graph.GraphNode)3 Parameters (edu.cmu.tetrad.util.Parameters)3 GeneralBootstrapTest (edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest)3 NumberFormat (java.text.NumberFormat)3 RandomGraph (edu.cmu.tetrad.algcomparison.graph.RandomGraph)2 ChiSquare (edu.cmu.tetrad.algcomparison.independence.ChiSquare)2