Search in sources :

Example 1 with StoredCellProbs

use of edu.cmu.tetrad.bayes.StoredCellProbs 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 2 with StoredCellProbs

use of edu.cmu.tetrad.bayes.StoredCellProbs in project tetrad by cmu-phil.

the class TestCellProbabilities method testCreateRandom.

@Test
public void testCreateRandom() {
    RandomUtil.getInstance().setSeed(4828385834L);
    DiscreteVariable x = new DiscreteVariable("X", 3);
    DiscreteVariable y = new DiscreteVariable("Y", 3);
    DiscreteVariable z = new DiscreteVariable("Z", 3);
    DiscreteVariable w = new DiscreteVariable("W", 2);
    List<Node> variables = new LinkedList<>();
    variables.add(x);
    variables.add(y);
    variables.add(z);
    variables.add(w);
    StoredCellProbs cellProbabilities = StoredCellProbs.createRandomCellTable(variables);
    double prob = cellProbabilities.getCellProb(new int[] { 0, 0, 0, 0 });
    assertEquals(0.002, prob, 0.0001);
}
Also used : DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable) Node(edu.cmu.tetrad.graph.Node) StoredCellProbs(edu.cmu.tetrad.bayes.StoredCellProbs) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

StoredCellProbs (edu.cmu.tetrad.bayes.StoredCellProbs)2 Test (org.junit.Test)2 BayesIm (edu.cmu.tetrad.bayes.BayesIm)1 BayesPm (edu.cmu.tetrad.bayes.BayesPm)1 MlBayesIm (edu.cmu.tetrad.bayes.MlBayesIm)1 DiscreteVariable (edu.cmu.tetrad.data.DiscreteVariable)1 Dag (edu.cmu.tetrad.graph.Dag)1 Graph (edu.cmu.tetrad.graph.Graph)1 Node (edu.cmu.tetrad.graph.Node)1 LinkedList (java.util.LinkedList)1