use of edu.cmu.tetrad.graph.GraphNode in project tetrad by cmu-phil.
the class ScoredGraphsDisplay method pasteSubsession.
public void pasteSubsession(List sessionElements, Point upperLeft) {
getWorkbench().pasteSubgraph(sessionElements, upperLeft);
getWorkbench().deselectAll();
for (int i = 0; i < sessionElements.size(); i++) {
Object o = sessionElements.get(i);
if (o instanceof GraphNode) {
Node modelNode = (Node) o;
getWorkbench().selectNode(modelNode);
}
}
getWorkbench().selectConnectingEdges();
}
use of edu.cmu.tetrad.graph.GraphNode in project tetrad by cmu-phil.
the class TestBayesXml method sampleBayesIm3.
private static BayesIm sampleBayesIm3() {
Node a = new GraphNode("a");
a.setNodeType(NodeType.LATENT);
a.setCenterX(5);
a.setCenterY(5);
Node b = new GraphNode("b");
Node c = new GraphNode("c");
Dag graph;
graph = new Dag();
graph.addNode(a);
graph.addNode(b);
graph.addNode(c);
graph.addDirectedEdge(a, b);
graph.addDirectedEdge(a, c);
graph.addDirectedEdge(b, c);
BayesPm bayesPm = new BayesPm(graph);
bayesPm.setNumCategories(b, 3);
return new MlBayesIm(bayesPm, MlBayesIm.RANDOM);
}
use of edu.cmu.tetrad.graph.GraphNode in project tetrad by cmu-phil.
the class TestBayesXml method sampleBayesIm1.
private static BayesIm sampleBayesIm1() {
Node a = new GraphNode("a");
Node b = new GraphNode("b");
Node c = new GraphNode("c");
Dag graph;
graph = new Dag();
graph.addNode(a);
graph.addNode(b);
graph.addNode(c);
graph.addDirectedEdge(a, b);
graph.addDirectedEdge(a, c);
graph.addDirectedEdge(b, c);
BayesPm bayesPm = new BayesPm(graph);
bayesPm.setNumCategories(b, 3);
BayesIm bayesIm1 = new MlBayesIm(bayesPm);
bayesIm1.setProbability(0, 0, 0, .3);
bayesIm1.setProbability(0, 0, 1, .7);
bayesIm1.setProbability(1, 0, 0, .3);
bayesIm1.setProbability(1, 0, 1, .4);
bayesIm1.setProbability(1, 0, 2, .3);
bayesIm1.setProbability(1, 1, 0, .6);
bayesIm1.setProbability(1, 1, 1, .1);
bayesIm1.setProbability(1, 1, 2, .3);
bayesIm1.setProbability(2, 0, 0, .9);
bayesIm1.setProbability(2, 0, 1, .1);
bayesIm1.setProbability(2, 1, 0, .1);
bayesIm1.setProbability(2, 1, 1, .9);
bayesIm1.setProbability(2, 2, 0, .5);
bayesIm1.setProbability(2, 2, 1, .5);
bayesIm1.setProbability(2, 3, 0, .2);
bayesIm1.setProbability(2, 3, 1, .8);
bayesIm1.setProbability(2, 4, 0, .6);
bayesIm1.setProbability(2, 4, 1, .4);
bayesIm1.setProbability(2, 5, 0, .7);
bayesIm1.setProbability(2, 5, 1, .3);
return bayesIm1;
}
use of edu.cmu.tetrad.graph.GraphNode in project tetrad by cmu-phil.
the class TestCptInvariantUpdater method sampleBayesIm2.
private BayesIm sampleBayesIm2() {
Node a = new GraphNode("a");
Node b = new GraphNode("b");
Node c = new GraphNode("c");
Dag graph;
graph = new Dag();
graph.addNode(a);
graph.addNode(b);
graph.addNode(c);
graph.addDirectedEdge(a, b);
graph.addDirectedEdge(a, c);
graph.addDirectedEdge(b, c);
BayesPm bayesPm = new BayesPm(graph);
bayesPm.setNumCategories(b, 3);
BayesIm bayesIm1 = new MlBayesIm(bayesPm);
bayesIm1.setProbability(0, 0, 0, .3);
bayesIm1.setProbability(0, 0, 1, .7);
bayesIm1.setProbability(1, 0, 0, .3);
bayesIm1.setProbability(1, 0, 1, .4);
bayesIm1.setProbability(1, 0, 2, .3);
bayesIm1.setProbability(1, 1, 0, .6);
bayesIm1.setProbability(1, 1, 1, .1);
bayesIm1.setProbability(1, 1, 2, .3);
bayesIm1.setProbability(2, 0, 0, .9);
bayesIm1.setProbability(2, 0, 1, .1);
bayesIm1.setProbability(2, 1, 0, .1);
bayesIm1.setProbability(2, 1, 1, .9);
bayesIm1.setProbability(2, 2, 0, .5);
bayesIm1.setProbability(2, 2, 1, .5);
bayesIm1.setProbability(2, 3, 0, .2);
bayesIm1.setProbability(2, 3, 1, .8);
bayesIm1.setProbability(2, 4, 0, .6);
bayesIm1.setProbability(2, 4, 1, .4);
bayesIm1.setProbability(2, 5, 0, .7);
bayesIm1.setProbability(2, 5, 1, .3);
return bayesIm1;
}
use of edu.cmu.tetrad.graph.GraphNode in project tetrad by cmu-phil.
the class TestCptInvariantUpdater method testUpdate4.
@Test
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);
}
Aggregations