use of edu.cmu.tetrad.graph.Dag in project tetrad by cmu-phil.
the class PValueImproverEditor method setGraphWorkbench.
private void setGraphWorkbench(final GraphWorkbench graphWorkbench) {
JTabbedPane tabbedPane = new JTabbedPane();
this.graphWorkbench = graphWorkbench;
if (getOriginalSemIm() != null) {
setOriginalSemIm(new SemIm(getWrapper().getOriginalSemIm()));
}
this.newSemIm = getWrapper().getNewSemIm();
if (getNewSemIm() != null) {
SemImEditor newEditor = new SemImEditor(new SemImWrapper(getNewSemIm()));
final GraphWorkbench workbench = newEditor.getWorkbench();
workbench.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
if ("modelChanged".equals(propertyChangeEvent.getPropertyName())) {
System.out.println(propertyChangeEvent);
Graph graph = workbench.getGraph();
System.out.println(graph);
try {
new Dag(graph);
} catch (IllegalArgumentException e) {
return;
}
Scorer scorer = new DagScorer((DataSet) getWrapper().getDataModel());
scorer.score(graph);
getWrapper().setNewSemIm(scorer.getEstSem());
setGraphWorkbench(graphWorkbench);
}
}
});
tabbedPane.addTab("New Model", newEditor);
}
if (getOriginalSemIm() != null) {
SemImEditor originalEditor = new SemImEditor(new SemImWrapper(getOriginalSemIm()));
tabbedPane.addTab("Original Model", originalEditor);
}
if (graphWorkbench != null) {
tabbedPane.addTab("forbid_latent_common_causes", graphWorkbench);
}
panel.removeAll();
panel.add(tabbedPane, BorderLayout.CENTER);
panel.revalidate();
panel.repaint();
firePropertyChange("modelChanged", null, null);
}
use of edu.cmu.tetrad.graph.Dag 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.Dag 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.Dag in project tetrad by cmu-phil.
the class TestCellProbabilities method testCreateUsingBayesIm.
@Test
public void testCreateUsingBayesIm() {
RandomUtil.getInstance().setSeed(4828385834L);
Graph graph = GraphConverter.convert("X1-->X2,X1-->X3,X2-->X4,X3-->X4");
Dag dag = new Dag(graph);
BayesPm bayesPm = new BayesPm(dag);
BayesIm bayesIm = new MlBayesIm(bayesPm, MlBayesIm.RANDOM);
StoredCellProbs cellProbs = StoredCellProbs.createCellTable(bayesIm);
double prob = cellProbs.getCellProb(new int[] { 0, 0, 0, 0 });
assertEquals(0.0058, prob, 0.0001);
}
use of edu.cmu.tetrad.graph.Dag 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;
}
Aggregations