Search in sources :

Example 6 with SemBicScore

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

the class TestFges method searchMGMFges.

public Graph searchMGMFges(DataSet ds, double penalty) {
    MGM m = new MGM(ds, new double[] { 0.1, 0.1, 0.1 });
    // m.setVerbose(this.verbose);
    Graph gm = m.search();
    DataSet dataSet = MixedUtils.makeContinuousData(ds);
    SemBicScore score = new SemBicScore(new CovarianceMatrixOnTheFly(dataSet));
    score.setPenaltyDiscount(penalty);
    Fges fg = new Fges(score);
    fg.setBoundGraph(gm);
    fg.setVerbose(false);
    return fg.search();
}
Also used : MGM(edu.pitt.csb.mgm.MGM) RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph) Fges(edu.cmu.tetrad.search.Fges) SemBicScore(edu.cmu.tetrad.search.SemBicScore)

Example 7 with SemBicScore

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

the class TestFges method testCites.

@Test
public void testCites() {
    String citesString = "164\n" + "ABILITY\tGPQ\tPREPROD\tQFJ\tSEX\tCITES\tPUBS\n" + "1.0\n" + ".62\t1.0\n" + ".25\t.09\t1.0\n" + ".16\t.28\t.07\t1.0\n" + "-.10\t.00\t.03\t.10\t1.0\n" + ".29\t.25\t.34\t.37\t.13\t1.0\n" + ".18\t.15\t.19\t.41\t.43\t.55\t1.0";
    char[] citesChars = citesString.toCharArray();
    DataReader reader = new DataReader();
    ICovarianceMatrix dataSet = reader.parseCovariance(citesChars);
    IKnowledge knowledge = new Knowledge2();
    knowledge.addToTier(1, "ABILITY");
    knowledge.addToTier(2, "GPQ");
    knowledge.addToTier(3, "QFJ");
    knowledge.addToTier(3, "PREPROD");
    knowledge.addToTier(4, "SEX");
    knowledge.addToTier(5, "PUBS");
    knowledge.addToTier(6, "CITES");
    SemBicScore score = new SemBicScore(dataSet);
    score.setPenaltyDiscount(1);
    Fges fges = new Fges(score);
    fges.setKnowledge(knowledge);
    Graph pattern = fges.search();
    // System.out.println(pattern);
    String trueString = "Graph Nodes:\n" + "ABILITY,GPQ,PREPROD,QFJ,SEX,CITES,PUBS\n" + "\n" + "Graph Edges: \n" + "1. ABILITY --> GPQ \n" + "2. ABILITY --> PREPROD \n" + "3. GPQ --> QFJ \n" + "4. PUBS --> CITES \n" + "5. QFJ --> PUBS \n" + "6. SEX --> PUBS";
    Graph trueGraph = null;
    try {
        trueGraph = GraphUtils.readerToGraphTxt(trueString);
    } catch (IOException e) {
        e.printStackTrace();
    }
    pattern = GraphUtils.replaceNodes(pattern, trueGraph.getNodes());
    assertEquals(trueGraph, pattern);
}
Also used : RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph) Fges(edu.cmu.tetrad.search.Fges) SemBicScore(edu.cmu.tetrad.search.SemBicScore) SemBicDTest(edu.cmu.tetrad.algcomparison.independence.SemBicDTest) SemBicTest(edu.cmu.tetrad.algcomparison.independence.SemBicTest) Test(org.junit.Test)

Example 8 with SemBicScore

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

the class TestFges method test7.

@Test
public void test7() {
    for (int i = 0; i < 10; i++) {
        Graph graph = GraphUtils.randomGraph(10, 0, 10, 10, 10, 10, false);
        SemPm semPm = new SemPm(graph);
        SemIm semIm = new SemIm(semPm);
        DataSet dataSet = semIm.simulateData(1000, false);
        Fges fges = new Fges(new SemBicScore(new CovarianceMatrixOnTheFly(dataSet)));
        Graph pattern = fges.search();
        Graph dag = dagFromPattern(pattern);
        assertFalse(dag.existsDirectedCycle());
    }
}
Also used : RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph) Fges(edu.cmu.tetrad.search.Fges) SemBicScore(edu.cmu.tetrad.search.SemBicScore) SemBicDTest(edu.cmu.tetrad.algcomparison.independence.SemBicDTest) SemBicTest(edu.cmu.tetrad.algcomparison.independence.SemBicTest) Test(org.junit.Test)

Example 9 with SemBicScore

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

the class ExploreAutisticsNeurotypicals method runAlgorithm.

private List<List<Graph>> runAlgorithm(String path, List<List<DataSet>> allDatasets, double penaltyDiscount) {
    List<List<Graph>> allGraphs = new ArrayList<>();
    for (List<DataSet> dataSets : allDatasets) {
        List<Graph> graphs = new ArrayList<>();
        for (DataSet dataSet : dataSets) {
            String name = dataSet.getName() + "." + penaltyDiscount + ".graph.txt";
            File file = new File(path, name);
            SemBicScore score = new SemBicScore(new CovarianceMatrixOnTheFly(dataSet));
            score.setPenaltyDiscount(penaltyDiscount);
            Fges search = new Fges(score);
            search.setVerbose(false);
            Graph graph = search.search();
            GraphUtils.saveGraph(graph, file, false);
            graphs.add(GraphUtils.undirectedGraph(GraphUtils.loadGraphTxt(file)));
        }
        allGraphs.add(graphs);
    }
    return allGraphs;
}
Also used : Graph(edu.cmu.tetrad.graph.Graph) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Fges(edu.cmu.tetrad.search.Fges) SemBicScore(edu.cmu.tetrad.search.SemBicScore)

Aggregations

SemBicScore (edu.cmu.tetrad.search.SemBicScore)9 Fges (edu.cmu.tetrad.search.Fges)8 RandomGraph (edu.cmu.tetrad.algcomparison.graph.RandomGraph)4 Graph (edu.cmu.tetrad.graph.Graph)4 SemBicDTest (edu.cmu.tetrad.algcomparison.independence.SemBicDTest)2 SemBicTest (edu.cmu.tetrad.algcomparison.independence.SemBicTest)2 CovarianceMatrixOnTheFly (edu.cmu.tetrad.data.CovarianceMatrixOnTheFly)2 DataSet (edu.cmu.tetrad.data.DataSet)2 File (java.io.File)2 Test (org.junit.Test)2 ICovarianceMatrix (edu.cmu.tetrad.data.ICovarianceMatrix)1 Dag (edu.cmu.tetrad.graph.Dag)1 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)1 Node (edu.cmu.tetrad.graph.Node)1 Fas (edu.cmu.tetrad.search.Fas)1 IndTestScore (edu.cmu.tetrad.search.IndTestScore)1 PatternToDag (edu.cmu.tetrad.search.PatternToDag)1 SemEstimator (edu.cmu.tetrad.sem.SemEstimator)1 SemIm (edu.cmu.tetrad.sem.SemIm)1 SemPm (edu.cmu.tetrad.sem.SemPm)1