Search in sources :

Example 1 with Dag

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);
}
Also used : DagScorer(edu.cmu.tetrad.sem.DagScorer) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) DataSet(edu.cmu.tetrad.data.DataSet) Scorer(edu.cmu.tetrad.sem.Scorer) DagScorer(edu.cmu.tetrad.sem.DagScorer) Dag(edu.cmu.tetrad.graph.Dag) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) GraphWorkbench(edu.cmu.tetradapp.workbench.GraphWorkbench) SemImWrapper(edu.cmu.tetradapp.model.SemImWrapper) SemIm(edu.cmu.tetrad.sem.SemIm)

Example 2 with Dag

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);
}
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 3 with Dag

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;
}
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 4 with Dag

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);
}
Also used : Graph(edu.cmu.tetrad.graph.Graph) MlBayesIm(edu.cmu.tetrad.bayes.MlBayesIm) BayesIm(edu.cmu.tetrad.bayes.BayesIm) MlBayesIm(edu.cmu.tetrad.bayes.MlBayesIm) StoredCellProbs(edu.cmu.tetrad.bayes.StoredCellProbs) Dag(edu.cmu.tetrad.graph.Dag) BayesPm(edu.cmu.tetrad.bayes.BayesPm) Test(org.junit.Test)

Example 5 with Dag

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

Dag (edu.cmu.tetrad.graph.Dag)53 Node (edu.cmu.tetrad.graph.Node)41 Graph (edu.cmu.tetrad.graph.Graph)21 GraphNode (edu.cmu.tetrad.graph.GraphNode)21 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)12 SemIm (edu.cmu.tetrad.sem.SemIm)10 SemPm (edu.cmu.tetrad.sem.SemPm)10 DataSet (edu.cmu.tetrad.data.DataSet)7 BayesPm (edu.cmu.tetrad.bayes.BayesPm)6 MlBayesIm (edu.cmu.tetrad.bayes.MlBayesIm)6 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)6 BayesIm (edu.cmu.tetrad.bayes.BayesIm)5 DiscreteVariable (edu.cmu.tetrad.data.DiscreteVariable)3 FruchtermanReingoldLayout (edu.cmu.tetrad.graph.FruchtermanReingoldLayout)2 TetradMatrix (edu.cmu.tetrad.util.TetradMatrix)2 LinkedList (java.util.LinkedList)2 StoredCellProbs (edu.cmu.tetrad.bayes.StoredCellProbs)1 ColtDataSet (edu.cmu.tetrad.data.ColtDataSet)1 CovarianceMatrixOnTheFly (edu.cmu.tetrad.data.CovarianceMatrixOnTheFly)1