Search in sources :

Example 31 with Dag

use of edu.cmu.tetrad.graph.Dag in project tetrad by cmu-phil.

the class TestFruchtermanReingoldLayout method testLayout2.

@Test
public void testLayout2() {
    Dag dag = new Dag();
    GraphNode x1 = new GraphNode("X1");
    GraphNode x2 = new GraphNode("X2");
    x1.setCenter(40, 5);
    x2.setCenter(50, 5);
    dag.addNode(x1);
    dag.addNode(x2);
    dag.addDirectedEdge(x1, x2);
    Dag dag2 = new Dag(dag);
    FruchtermanReingoldLayout layout = new FruchtermanReingoldLayout(dag);
    layout.doLayout();
    assertEquals(dag, dag2);
}
Also used : GraphNode(edu.cmu.tetrad.graph.GraphNode) Dag(edu.cmu.tetrad.graph.Dag) FruchtermanReingoldLayout(edu.cmu.tetrad.graph.FruchtermanReingoldLayout) Test(org.junit.Test)

Example 32 with Dag

use of edu.cmu.tetrad.graph.Dag in project tetrad by cmu-phil.

the class TestFruchtermanReingoldLayout method testLayout.

@Test
public void testLayout() {
    // Dag dag = DataGraphUtils.createRandomDag(40, 0, 80, 6, 6, 6, true);
    Dag dag = new Dag();
    GraphNode x1 = new GraphNode("X1");
    GraphNode x2 = new GraphNode("X2");
    GraphNode x3 = new GraphNode("X3");
    GraphNode x4 = new GraphNode("X4");
    GraphNode x5 = new GraphNode("X5");
    GraphNode x6 = new GraphNode("X6");
    GraphNode x7 = new GraphNode("X7");
    dag.addNode(x1);
    dag.addNode(x2);
    dag.addNode(x3);
    dag.addNode(x4);
    dag.addNode(x5);
    dag.addNode(x6);
    dag.addNode(x7);
    dag.addDirectedEdge(x1, x2);
    dag.addDirectedEdge(x2, x3);
    dag.addDirectedEdge(x4, x5);
    dag.addDirectedEdge(x5, x6);
    Dag dag2 = new Dag(dag);
    GraphUtils.circleLayout(dag, 200, 200, 150);
    FruchtermanReingoldLayout layout = new FruchtermanReingoldLayout(dag);
    layout.doLayout();
    assertEquals(dag, dag2);
}
Also used : GraphNode(edu.cmu.tetrad.graph.GraphNode) Dag(edu.cmu.tetrad.graph.Dag) FruchtermanReingoldLayout(edu.cmu.tetrad.graph.FruchtermanReingoldLayout) Test(org.junit.Test)

Example 33 with Dag

use of edu.cmu.tetrad.graph.Dag in project tetrad by cmu-phil.

the class TestUpdatedBayesIm method testCompound.

@Test
public void testCompound() {
    Node x0Node = new GraphNode("X0");
    Node x1Node = new GraphNode("X1");
    Node x2Node = new GraphNode("X2");
    Node x3Node = new GraphNode("X3");
    Node x4Node = new GraphNode("X4");
    Dag graph = new Dag();
    graph.addNode(x0Node);
    graph.addNode(x1Node);
    graph.addNode(x2Node);
    graph.addNode(x3Node);
    graph.addNode(x4Node);
    graph.addDirectedEdge(x0Node, x1Node);
    graph.addDirectedEdge(x0Node, x2Node);
    graph.addDirectedEdge(x1Node, x3Node);
    graph.addDirectedEdge(x2Node, x3Node);
    graph.addDirectedEdge(x4Node, x0Node);
    graph.addDirectedEdge(x4Node, x2Node);
    BayesPm bayesPm = new BayesPm(graph);
    MlBayesIm bayesIm = new MlBayesIm(bayesPm, MlBayesIm.RANDOM);
    UpdatedBayesIm updatedIm1 = new UpdatedBayesIm(bayesIm);
    assertEquals(bayesIm, updatedIm1);
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {
            Evidence evidence1 = updatedIm1.getEvidence();
            evidence1.getProposition().disallowComplement(i, 0);
            UpdatedBayesIm updatedIm2 = new UpdatedBayesIm(updatedIm1, evidence1);
            Evidence evidence2 = updatedIm2.getEvidence();
            evidence2.getProposition().setToTautology();
            evidence2.getProposition().disallowComplement(j, 0);
            CptInvariantMarginalCalculator marginals1 = new CptInvariantMarginalCalculator(updatedIm2, evidence2);
            double marginal1 = marginals1.getMarginal(0, 0);
            Evidence evidence3 = updatedIm1.getEvidence();
            evidence3.getProposition().disallowComplement(i, 0);
            evidence3.getProposition().disallowComplement(j, 0);
            CptInvariantMarginalCalculator marginals2 = new CptInvariantMarginalCalculator(updatedIm1, evidence3);
            double marginal2 = marginals2.getMarginal(0, 0);
            assertEquals(marginal1, marginal2, 1.0e-2);
        }
    }
}
Also used : GraphNode(edu.cmu.tetrad.graph.GraphNode) Node(edu.cmu.tetrad.graph.Node) GraphNode(edu.cmu.tetrad.graph.GraphNode) Dag(edu.cmu.tetrad.graph.Dag) Test(org.junit.Test)

Example 34 with Dag

use of edu.cmu.tetrad.graph.Dag in project tetrad by cmu-phil.

the class TestRowSummingUpdater method testUpdate4.

public void testUpdate4() {
    Node x0Node = new GraphNode("X0");
    Node x1Node = new GraphNode("X1");
    Node x2Node = new GraphNode("X2");
    Node x3Node = new GraphNode("X3");
    Dag graph = new Dag();
    graph.addNode(x0Node);
    graph.addNode(x1Node);
    graph.addNode(x2Node);
    graph.addNode(x3Node);
    graph.addDirectedEdge(x0Node, x1Node);
    graph.addDirectedEdge(x0Node, x2Node);
    graph.addDirectedEdge(x1Node, x3Node);
    graph.addDirectedEdge(x2Node, x3Node);
    BayesPm bayesPm = new BayesPm(graph);
    MlBayesIm bayesIm = new MlBayesIm(bayesPm, MlBayesIm.RANDOM);
    // int x0 = bayesIm.getNodeIndex(x0Node);
    // int x1 = bayesIm.getNodeIndex(x1Node);
    int x2 = bayesIm.getNodeIndex(x2Node);
    int x3 = bayesIm.getNodeIndex(x3Node);
    Evidence evidence = Evidence.tautology(bayesIm);
    evidence.getProposition().setCategory(x2, 0);
    BayesUpdater updater1 = new CptInvariantUpdater(bayesIm);
    updater1.setEvidence(evidence);
    BayesUpdater updater2 = new RowSummingExactUpdater(bayesIm);
    updater2.setEvidence(evidence);
    double marginal1 = updater1.getMarginal(x3, 0);
    double marginal2 = updater2.getMarginal(x3, 0);
    assertEquals(marginal1, marginal2, 0.000001);
}
Also used : GraphNode(edu.cmu.tetrad.graph.GraphNode) Node(edu.cmu.tetrad.graph.Node) GraphNode(edu.cmu.tetrad.graph.GraphNode) Dag(edu.cmu.tetrad.graph.Dag)

Example 35 with Dag

use of edu.cmu.tetrad.graph.Dag in project tetrad by cmu-phil.

the class TestRowSummingUpdater method sampleBayesIm0.

private BayesIm sampleBayesIm0() {
    Node z = new GraphNode("z");
    Dag graph = new Dag();
    graph.addNode(z);
    BayesPm bayesPm = new BayesPm(graph);
    BayesIm bayesIm1 = new MlBayesIm(bayesPm);
    bayesIm1.setProbability(0, 0, 0, .3);
    bayesIm1.setProbability(0, 0, 1, .7);
    return bayesIm1;
}
Also used : GraphNode(edu.cmu.tetrad.graph.GraphNode) Node(edu.cmu.tetrad.graph.Node) GraphNode(edu.cmu.tetrad.graph.GraphNode) Dag(edu.cmu.tetrad.graph.Dag)

Aggregations

Dag (edu.cmu.tetrad.graph.Dag)53 Node (edu.cmu.tetrad.graph.Node)41 Graph (edu.cmu.tetrad.graph.Graph)21 GraphNode (edu.cmu.tetrad.graph.GraphNode)21 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)12 SemIm (edu.cmu.tetrad.sem.SemIm)10 SemPm (edu.cmu.tetrad.sem.SemPm)10 DataSet (edu.cmu.tetrad.data.DataSet)7 BayesPm (edu.cmu.tetrad.bayes.BayesPm)6 MlBayesIm (edu.cmu.tetrad.bayes.MlBayesIm)6 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)6 BayesIm (edu.cmu.tetrad.bayes.BayesIm)5 DiscreteVariable (edu.cmu.tetrad.data.DiscreteVariable)3 FruchtermanReingoldLayout (edu.cmu.tetrad.graph.FruchtermanReingoldLayout)2 TetradMatrix (edu.cmu.tetrad.util.TetradMatrix)2 LinkedList (java.util.LinkedList)2 StoredCellProbs (edu.cmu.tetrad.bayes.StoredCellProbs)1 ColtDataSet (edu.cmu.tetrad.data.ColtDataSet)1 CovarianceMatrixOnTheFly (edu.cmu.tetrad.data.CovarianceMatrixOnTheFly)1