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);
}
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);
}
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);
}
}
}
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);
}
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;
}
Aggregations