use of edu.cmu.tetrad.graph.GraphNode in project tetrad by cmu-phil.
the class TestRowSummingUpdater method testUpdate5.
@Test
public void testUpdate5() {
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);
int x1 = bayesIm.getNodeIndex(x1Node);
int x2 = bayesIm.getNodeIndex(x2Node);
int x3 = bayesIm.getNodeIndex(x3Node);
Evidence evidence = Evidence.tautology(bayesIm);
evidence.getProposition().setCategory(x1, 1);
evidence.getProposition().setCategory(x2, 0);
evidence.getNodeIndex("X1");
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);
}
use of edu.cmu.tetrad.graph.GraphNode in project tetrad by cmu-phil.
the class TestSem method constructGraph2.
private Graph constructGraph2() {
Graph graph = new EdgeListGraph();
Node x1 = new GraphNode("X1");
Node x2 = new GraphNode("X2");
Node x3 = new GraphNode("X3");
Node x4 = new GraphNode("X4");
Node x5 = new GraphNode("X5");
Node x6 = new GraphNode("X6");
Node x7 = new GraphNode("X7");
Node x8 = new GraphNode("X8");
graph.addNode(x1);
graph.addNode(x2);
graph.addNode(x3);
graph.addNode(x4);
graph.addNode(x5);
graph.addNode(x6);
graph.addNode(x7);
graph.addNode(x8);
graph.addDirectedEdge(x1, x2);
graph.addDirectedEdge(x2, x3);
graph.addDirectedEdge(x2, x6);
graph.addDirectedEdge(x3, x7);
graph.addDirectedEdge(x4, x5);
graph.addDirectedEdge(x4, x6);
graph.addDirectedEdge(x5, x3);
graph.addDirectedEdge(x6, x8);
graph.addDirectedEdge(x6, x7);
return graph;
}
use of edu.cmu.tetrad.graph.GraphNode in project tetrad by cmu-phil.
the class TestSem method constructGraph1.
private Graph constructGraph1() {
Graph graph = new EdgeListGraph();
Node x1 = new GraphNode("X1");
Node x2 = new GraphNode("X2");
Node x3 = new GraphNode("X3");
Node x4 = new GraphNode("X4");
Node x5 = new GraphNode("X5");
graph.addNode(x1);
graph.addNode(x2);
graph.addNode(x3);
graph.addNode(x4);
graph.addNode(x5);
graph.addDirectedEdge(x1, x2);
graph.addDirectedEdge(x2, x3);
graph.addDirectedEdge(x3, x4);
graph.addDirectedEdge(x1, x4);
graph.addDirectedEdge(x4, x5);
return graph;
}
use of edu.cmu.tetrad.graph.GraphNode in project tetrad by cmu-phil.
the class TestSemUpdater method constructGraph1.
private Graph constructGraph1() {
Graph graph = new EdgeListGraph();
Node x1 = new GraphNode("X1");
Node x2 = new GraphNode("X2");
Node x3 = new GraphNode("X3");
Node x4 = new GraphNode("X4");
Node x5 = new GraphNode("X5");
graph.addNode(x1);
graph.addNode(x2);
graph.addNode(x3);
graph.addNode(x4);
graph.addNode(x5);
graph.addDirectedEdge(x1, x2);
graph.addDirectedEdge(x2, x3);
graph.addDirectedEdge(x3, x4);
graph.addDirectedEdge(x1, x4);
graph.addDirectedEdge(x4, x5);
return graph;
}
use of edu.cmu.tetrad.graph.GraphNode in project tetrad by cmu-phil.
the class TestTimeLagGraph method test1.
@Test
public void test1() {
TimeLagGraph graph = new TimeLagGraph();
Node x0 = new GraphNode("X");
Node y0 = new GraphNode("Y");
assertTrue(graph.addNode(x0));
assertTrue(graph.addNode(y0));
assertFalse(graph.setMaxLag(2));
Node x1 = graph.getNode("X", 1);
assertTrue(graph.addDirectedEdge(x1, y0));
assertTrue(graph.setMaxLag(4));
assertTrue(graph.setNumInitialLags(2));
assertFalse(graph.setMaxLag(3));
assertTrue(graph.setMaxLag(5));
Node y1 = graph.getNode("Y", 1);
assertTrue(graph.addDirectedEdge(y1, x0));
assertTrue(graph.setMaxLag(1));
assertFalse(graph.setMaxLag(0));
assertFalse(graph.removeHighLagEdges(0));
assertTrue(graph.addDirectedEdge(x0, y0));
}
Aggregations