Search in sources :

Example 6 with DMSearch

use of edu.cmu.tetrad.search.DMSearch in project tetrad by cmu-phil.

the class TestDM method rtest7.

// Test cases after here serve as examples and/or were used to diagnose a no longer applicable problem.
// Still have to clean up.
@Ignore
public void rtest7() {
    print("test 7");
    DMSearch result = readAndSearchData("src/edu/cmu/tetradproj/amurrayw/testcase7.txt", new int[] { 0, 1 }, new int[] { 2, 3 }, true, new int[] { 0, 1 });
    File file = new File("src/edu/cmu/tetradproj/amurrayw/output_test7.txt");
    try {
        FileOutputStream out = new FileOutputStream(file);
        PrintStream outStream = new PrintStream(out);
        outStream.println(result.getDmStructure().latentStructToEdgeListGraph(result.getDmStructure()));
        outStream.println();
    } catch (java.io.FileNotFoundException e) {
        print("Can't write to file.");
    }
    print("DONE");
}
Also used : PrintStream(java.io.PrintStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) DMSearch(edu.cmu.tetrad.search.DMSearch) Ignore(org.junit.Ignore)

Example 7 with DMSearch

use of edu.cmu.tetrad.search.DMSearch in project tetrad by cmu-phil.

the class TestDM method test4.

// Three latent fork case
@Test
public void test4() {
    // setting seed for debug.
    RandomUtil.getInstance().setSeed(29483818483L);
    Graph graph = emptyGraph(6);
    graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X3"));
    graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X3"));
    graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X4"));
    graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X5"));
    graph.addDirectedEdge(new ContinuousVariable("X2"), new ContinuousVariable("X5"));
    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 });
    search.setOutputs(new int[] { 3, 4, 5 });
    search.setData(data);
    search.setTrueInputs(search.getInputs());
    Graph foundGraph = search.search();
    print("Three Latent Fork Case");
    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("L0"));
    trueGraph.addNode(new ContinuousVariable("L1"));
    trueGraph.addNode(new ContinuousVariable("L2"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("L0"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("L0"));
    trueGraph.addDirectedEdge(new ContinuousVariable("L0"), new ContinuousVariable("X3"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("L1"));
    trueGraph.addDirectedEdge(new ContinuousVariable("L1"), new ContinuousVariable("X4"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("L2"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X2"), new ContinuousVariable("L2"));
    trueGraph.addDirectedEdge(new ContinuousVariable("L2"), new ContinuousVariable("X5"));
    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 8 with DMSearch

use of edu.cmu.tetrad.search.DMSearch in project tetrad by cmu-phil.

the class TestDM method test6.

// Four latent case.
@Test
public void test6() {
    // setting seed for debug.
    RandomUtil.getInstance().setSeed(29483818483L);
    Graph graph = emptyGraph(8);
    graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X4"));
    graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X5"));
    graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X6"));
    graph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("X7"));
    graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X5"));
    graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X6"));
    graph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("X7"));
    graph.addDirectedEdge(new ContinuousVariable("X2"), new ContinuousVariable("X6"));
    graph.addDirectedEdge(new ContinuousVariable("X2"), new ContinuousVariable("X7"));
    graph.addDirectedEdge(new ContinuousVariable("X3"), new ContinuousVariable("X7"));
    SemPm pm = new SemPm(graph);
    SemIm im = new SemIm(pm);
    DataSet data = im.simulateData(1000, false);
    DMSearch search = new DMSearch();
    search.setInputs(new int[] { 0, 1, 2, 3 });
    search.setOutputs(new int[] { 4, 5, 6, 7 });
    search.setData(data);
    search.setTrueInputs(search.getInputs());
    Graph foundGraph = search.search();
    print("Four Latent Case");
    print("search.getDmStructure().latentStructToEdgeListGraph(search.getDmStructure())");
    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.addNode(new ContinuousVariable("L2"));
    trueGraph.addNode(new ContinuousVariable("L3"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("L0"));
    trueGraph.addDirectedEdge(new ContinuousVariable("L0"), new ContinuousVariable("X4"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("L1"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("L1"));
    trueGraph.addDirectedEdge(new ContinuousVariable("L1"), new ContinuousVariable("X5"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("L2"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("L2"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X2"), new ContinuousVariable("L2"));
    trueGraph.addDirectedEdge(new ContinuousVariable("L2"), new ContinuousVariable("X6"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X0"), new ContinuousVariable("L3"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X1"), new ContinuousVariable("L3"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X2"), new ContinuousVariable("L3"));
    trueGraph.addDirectedEdge(new ContinuousVariable("X3"), new ContinuousVariable("L3"));
    trueGraph.addDirectedEdge(new ContinuousVariable("L3"), 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 9 with DMSearch

use of edu.cmu.tetrad.search.DMSearch in project tetrad by cmu-phil.

the class TestDM method test1.

@Test
public void test1() {
    // setting seed for debug.
    RandomUtil.getInstance().setSeed(29483818483L);
    NodeEqualityMode.setEqualityMode(NodeEqualityMode.Type.NAME);
    Graph graph = emptyGraph(4);
    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"));
    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 });
    search.setOutputs(new int[] { 2, 3 });
    search.setData(data);
    search.setTrueInputs(search.getInputs());
    Graph foundGraph = search.search();
    print("Test Case 1");
    // System.out.println(search.getDmStructure());
    // System.out.println(foundGraph);
    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("L0"));
    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"));
    assertEquals(trueGraph, foundGraph);
}
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 10 with DMSearch

use of edu.cmu.tetrad.search.DMSearch in project tetrad by cmu-phil.

the class TestDM method rtest16.

@Ignore
public void rtest16() {
    print("test PC");
    DMSearch result = readAndSearchData("src/edu/cmu/tetradproj/amurrayw/testcase7_fixed.txt", new int[] { 0, 1 }, new int[] { 2, 3 }, false, new int[] { 0, 1 });
    File file = new File("src/edu/cmu/tetradproj/amurrayw/output_test7_fixed.txt");
    try {
        FileOutputStream out = new FileOutputStream(file);
        PrintStream outStream = new PrintStream(out);
        outStream.println(result.getDmStructure().latentStructToEdgeListGraph(result.getDmStructure()));
        outStream.println();
    } catch (java.io.FileNotFoundException e) {
        print("Can't write to file.");
    }
    System.out.println(result.getDmStructure().latentStructToEdgeListGraph(result.getDmStructure()));
    print("DONE");
}
Also used : PrintStream(java.io.PrintStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) DMSearch(edu.cmu.tetrad.search.DMSearch) Ignore(org.junit.Ignore)

Aggregations

DMSearch (edu.cmu.tetrad.search.DMSearch)14 DataSet (edu.cmu.tetrad.data.DataSet)10 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)9 Graph (edu.cmu.tetrad.graph.Graph)9 SemIm (edu.cmu.tetrad.sem.SemIm)9 SemPm (edu.cmu.tetrad.sem.SemPm)9 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)7 Test (org.junit.Test)7 Ignore (org.junit.Ignore)6 File (java.io.File)5 FileOutputStream (java.io.FileOutputStream)4 PrintStream (java.io.PrintStream)4 Node (edu.cmu.tetrad.graph.Node)2 ContinuousTabularDataFileReader (edu.pitt.dbmi.data.reader.tabular.ContinuousTabularDataFileReader)1 TabularDataReader (edu.pitt.dbmi.data.reader.tabular.TabularDataReader)1 IOException (java.io.IOException)1