Search in sources :

Example 26 with GraphNode

use of edu.cmu.tetrad.graph.GraphNode 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 27 with GraphNode

use of edu.cmu.tetrad.graph.GraphNode 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 28 with GraphNode

use of edu.cmu.tetrad.graph.GraphNode 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 29 with GraphNode

use of edu.cmu.tetrad.graph.GraphNode 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)

Example 30 with GraphNode

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

the class TestRowSummingUpdater method sampleBayesIm1.

private BayesIm sampleBayesIm1() {
    Node x = new GraphNode("x");
    Node z = new GraphNode("z");
    Dag graph = new Dag();
    graph.addNode(x);
    graph.addNode(z);
    graph.addDirectedEdge(x, z);
    BayesPm bayesPm = new BayesPm(graph);
    BayesIm bayesIm1 = new MlBayesIm(bayesPm);
    bayesIm1.setProbability(0, 0, 0, .3);
    bayesIm1.setProbability(0, 0, 1, .7);
    bayesIm1.setProbability(1, 0, 0, .8);
    bayesIm1.setProbability(1, 0, 1, .2);
    bayesIm1.setProbability(1, 1, 0, .4);
    bayesIm1.setProbability(1, 1, 1, .6);
    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

GraphNode (edu.cmu.tetrad.graph.GraphNode)41 Node (edu.cmu.tetrad.graph.Node)37 Dag (edu.cmu.tetrad.graph.Dag)20 Test (org.junit.Test)11 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)7 Graph (edu.cmu.tetrad.graph.Graph)7 DisplayNode (edu.cmu.tetradapp.workbench.DisplayNode)6 BayesIm (edu.cmu.tetrad.bayes.BayesIm)3 BayesPm (edu.cmu.tetrad.bayes.BayesPm)3 MlBayesIm (edu.cmu.tetrad.bayes.MlBayesIm)3 IndependenceFact (edu.cmu.tetrad.graph.IndependenceFact)3 ArrayList (java.util.ArrayList)3 FruchtermanReingoldLayout (edu.cmu.tetrad.graph.FruchtermanReingoldLayout)2 DiscreteVariable (edu.cmu.tetrad.data.DiscreteVariable)1 IndependenceFacts (edu.cmu.tetrad.data.IndependenceFacts)1 Endpoint (edu.cmu.tetrad.graph.Endpoint)1 SemGraph (edu.cmu.tetrad.graph.SemGraph)1 TimeLagGraph (edu.cmu.tetrad.graph.TimeLagGraph)1 IndependenceFactsModel (edu.cmu.tetradapp.model.IndependenceFactsModel)1 BufferedReader (java.io.BufferedReader)1