Search in sources :

Example 1 with SemIm

use of edu.cmu.tetrad.sem.SemIm 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 SemIm

use of edu.cmu.tetrad.sem.SemIm in project tetrad by cmu-phil.

the class TestDM method test2.

@Test
public void test2() {
    // setting seed for debug.
    RandomUtil.getInstance().setSeed(29483818483L);
    Graph graph = emptyGraph(8);
    graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X2"));
    graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X3"));
    graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X2"));
    graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X3"));
    graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X6"));
    graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X7"));
    graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X6"));
    graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X7"));
    graph.addDirectedEdge(new ContinuousVariable("X4"), new ContinuousVariable("X6"));
    graph.addDirectedEdge(new ContinuousVariable("X4"), new ContinuousVariable("X7"));
    graph.addDirectedEdge(new ContinuousVariable("X5"), new ContinuousVariable("X6"));
    graph.addDirectedEdge(new ContinuousVariable("X5"), new ContinuousVariable("X7"));
    SemPm pm = new SemPm(graph);
    SemIm im = new SemIm(pm);
    DataSet data = im.simulateData(100000, false);
    DMSearch search = new DMSearch();
    search.setInputs(new int[] { 0, 1, 4, 5 });
    search.setOutputs(new int[] { 2, 3, 6, 7 });
    search.setData(data);
    search.setTrueInputs(search.getInputs());
    Graph foundGraph = search.search();
    print("Test Case 2");
    Graph trueGraph = new EdgeListGraph();
    trueGraph.addNode(new ContinuousVariable("X0"));
    trueGraph.addNode(new ContinuousVariable("X1"));
    trueGraph.addNode(new ContinuousVariable("X2"));
    trueGraph.addNode(new ContinuousVariable("X3"));
    trueGraph.addNode(new ContinuousVariable("X4"));
    trueGraph.addNode(new ContinuousVariable("X5"));
    trueGraph.addNode(new ContinuousVariable("X6"));
    trueGraph.addNode(new ContinuousVariable("X7"));
    trueGraph.addNode(new ContinuousVariable("L0"));
    trueGraph.addNode(new ContinuousVariable("L1"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("L0"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("L0"));
    trueGraph.addDirectedEdge(new ContinuousVariable("L0"), new ContinuousVariable("X2"));
    trueGraph.addDirectedEdge(new ContinuousVariable("L0"), new ContinuousVariable("X3"));
    // trueGraph.addDirectedEdge(new ContinuousVariable("L0"), new ContinuousVariable("X1"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("L1"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("L1"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X4"), new ContinuousVariable("L1"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X5"), new ContinuousVariable("L1"));
    trueGraph.addDirectedEdge(new ContinuousVariable("L1"), new ContinuousVariable("X6"));
    trueGraph.addDirectedEdge(new ContinuousVariable("L1"), new ContinuousVariable("X7"));
    assertTrue(foundGraph.equals(trueGraph));
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) DataSet(edu.cmu.tetrad.data.DataSet) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) SemPm(edu.cmu.tetrad.sem.SemPm) SemIm(edu.cmu.tetrad.sem.SemIm) DMSearch(edu.cmu.tetrad.search.DMSearch) Test(org.junit.Test)

Example 3 with SemIm

use of edu.cmu.tetrad.sem.SemIm in project tetrad by cmu-phil.

the class TestDM method rtest13.

@Ignore
public void rtest13() {
    // setting seed for debug.
    RandomUtil.getInstance().setSeed(29483818483L);
    Graph graph = emptyGraph(12);
    Node X0 = graph.getNode("X0");
    Node X1 = graph.getNode("X1");
    Node X2 = graph.getNode("X2");
    Node X3 = graph.getNode("X3");
    Node X4 = graph.getNode("X4");
    Node X5 = graph.getNode("X5");
    Node X6 = graph.getNode("X6");
    Node X7 = graph.getNode("X7");
    Node X8 = graph.getNode("X8");
    Node X9 = graph.getNode("X9");
    Node X10 = graph.getNode("X10");
    Node X11 = graph.getNode("X11");
    graph.addDirectedEdge(X0, X6);
    graph.addDirectedEdge(X1, X6);
    graph.addDirectedEdge(X1, X7);
    graph.addDirectedEdge(X1, X8);
    graph.addDirectedEdge(X2, X8);
    graph.addDirectedEdge(X3, X8);
    graph.addDirectedEdge(X3, X9);
    graph.addDirectedEdge(X3, X10);
    graph.addDirectedEdge(X3, X9);
    graph.addDirectedEdge(X4, X10);
    graph.addDirectedEdge(X4, X11);
    graph.addDirectedEdge(X5, X11);
    // 
    // graph.addDirectedEdge(X1, X8);
    // graph.addDirectedEdge(X2, X6);
    // graph.addDirectedEdge(X2, X7);
    // graph.addDirectedEdge(X2, X8);
    // 
    // 
    // graph.addDirectedEdge(X3, X8);
    // graph.addDirectedEdge(X3, X7);
    // graph.addDirectedEdge(X4, X8);
    // graph.addDirectedEdge(X4, X7);
    // 
    // 
    // graph.addDirectedEdge(X5, X8);
    RandomUtil.getInstance().setSeed(29483818483L);
    SemPm pm = new SemPm(graph);
    SemIm im = new SemIm(pm);
    DataSet data = im.simulateData(100000, false);
    DMSearch search = new DMSearch();
    search.setInputs(new int[] { 0, 1, 2, 3, 4, 5 });
    search.setOutputs(new int[] { 6, 7, 8, 9, 10, 11 });
    search.setData(data);
    search.setTrueInputs(search.getInputs());
    search.search();
    print("");
    print("" + search.getDmStructure());
    print("graph.existsDirectedCycle: " + search.getDmStructure().latentStructToEdgeListGraph(search.getDmStructure()).existsDirectedCycle());
    print("Graph structure: " + search);
    assertTrue(true);
}
Also used : EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) DataSet(edu.cmu.tetrad.data.DataSet) Node(edu.cmu.tetrad.graph.Node) SemPm(edu.cmu.tetrad.sem.SemPm) SemIm(edu.cmu.tetrad.sem.SemIm) DMSearch(edu.cmu.tetrad.search.DMSearch) Ignore(org.junit.Ignore)

Example 4 with SemIm

use of edu.cmu.tetrad.sem.SemIm in project tetrad by cmu-phil.

the class TestDM method rtest12.

@Ignore
public void rtest12() {
    // setting seed for debug.
    RandomUtil.getInstance().setSeed(29483818483L);
    Graph graph = emptyGraph(9);
    Node X0 = graph.getNode("X0");
    Node X1 = graph.getNode("X1");
    Node X2 = graph.getNode("X2");
    Node X3 = graph.getNode("X3");
    Node X4 = graph.getNode("X4");
    Node X5 = graph.getNode("X5");
    Node X6 = graph.getNode("X6");
    Node X7 = graph.getNode("X7");
    Node X8 = graph.getNode("X8");
    graph.addDirectedEdge(X0, X6);
    graph.addDirectedEdge(X0, X7);
    graph.addDirectedEdge(X0, X8);
    graph.addDirectedEdge(X1, X6);
    graph.addDirectedEdge(X1, X7);
    graph.addDirectedEdge(X1, X8);
    graph.addDirectedEdge(X2, X6);
    graph.addDirectedEdge(X2, X7);
    graph.addDirectedEdge(X2, X8);
    graph.addDirectedEdge(X3, X8);
    graph.addDirectedEdge(X3, X7);
    graph.addDirectedEdge(X4, X8);
    graph.addDirectedEdge(X4, X7);
    graph.addDirectedEdge(X5, X8);
    RandomUtil.getInstance().setSeed(29483818483L);
    SemPm pm = new SemPm(graph);
    SemIm im = new SemIm(pm);
    DataSet data = im.simulateData(100000, false);
    DMSearch search = new DMSearch();
    search.setInputs(new int[] { 0, 1, 2, 3, 4, 5 });
    search.setOutputs(new int[] { 6, 7, 8 });
    search.setData(data);
    search.setTrueInputs(search.getInputs());
    search.search();
    print("");
    print("" + search.getDmStructure());
    print("graph.existsDirectedCycle: " + search.getDmStructure().latentStructToEdgeListGraph(search.getDmStructure()).existsDirectedCycle());
    print("Graph structure: " + search);
    assertTrue(true);
}
Also used : EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) DataSet(edu.cmu.tetrad.data.DataSet) Node(edu.cmu.tetrad.graph.Node) SemPm(edu.cmu.tetrad.sem.SemPm) SemIm(edu.cmu.tetrad.sem.SemIm) DMSearch(edu.cmu.tetrad.search.DMSearch) Ignore(org.junit.Ignore)

Example 5 with SemIm

use of edu.cmu.tetrad.sem.SemIm in project tetrad by cmu-phil.

the class TestDM method test10.

// 
@Test
public void test10() {
    // setting seed for debug.
    RandomUtil.getInstance().setSeed(29483818483L);
    Graph graph = emptyGraph(5);
    graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X2"));
    graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X3"));
    graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X3"));
    graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X4"));
    SemPm pm = new SemPm(graph);
    SemIm im = new SemIm(pm);
    DataSet data = im.simulateData(100000, false);
    DMSearch search = new DMSearch();
    search.setUseFges(false);
    search.setInputs(new int[] { 0, 1 });
    search.setOutputs(new int[] { 2, 3, 4 });
    search.setData(data);
    search.setTrueInputs(search.getInputs());
    search.search();
    print("Test Case 10");
    // Trying to quiet the output for unit tests.
    if (false) {
        System.out.println(search.getDmStructure());
    }
    assertTrue(true);
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) DataSet(edu.cmu.tetrad.data.DataSet) SemPm(edu.cmu.tetrad.sem.SemPm) SemIm(edu.cmu.tetrad.sem.SemIm) DMSearch(edu.cmu.tetrad.search.DMSearch) Test(org.junit.Test)

Aggregations

SemIm (edu.cmu.tetrad.sem.SemIm)81 SemPm (edu.cmu.tetrad.sem.SemPm)71 Test (org.junit.Test)46 DataSet (edu.cmu.tetrad.data.DataSet)28 ArrayList (java.util.ArrayList)28 Graph (edu.cmu.tetrad.graph.Graph)26 Node (edu.cmu.tetrad.graph.Node)19 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)16 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)16 SemEstimator (edu.cmu.tetrad.sem.SemEstimator)15 Dag (edu.cmu.tetrad.graph.Dag)10 DMSearch (edu.cmu.tetrad.search.DMSearch)9 StandardizedSemIm (edu.cmu.tetrad.sem.StandardizedSemIm)9 TetradMatrix (edu.cmu.tetrad.util.TetradMatrix)7 NumberFormat (java.text.NumberFormat)7 GraphNode (edu.cmu.tetrad.graph.GraphNode)5 IndependenceTest (edu.cmu.tetrad.search.IndependenceTest)4 DecimalFormat (java.text.DecimalFormat)4 List (java.util.List)4 CovarianceMatrix (edu.cmu.tetrad.data.CovarianceMatrix)3