Search in sources :

Example 6 with Fges

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

the class TestFges method explore1.

// private OutputStream out =
// @Test
public void explore1() {
    RandomUtil.getInstance().setSeed(1450184147770L);
    int numVars = 10;
    double edgesPerNode = 1.0;
    int numCases = 1000;
    double penaltyDiscount = 2.0;
    final int numEdges = (int) (numVars * edgesPerNode);
    List<Node> vars = new ArrayList<>();
    for (int i = 0; i < numVars; i++) {
        vars.add(new ContinuousVariable("X" + i));
    }
    Graph dag = GraphUtils.randomGraphRandomForwardEdges(vars, 0, numEdges, 30, 15, 15, false, true);
    // printDegreeDistribution(dag, System.out);
    int[] causalOrdering = new int[vars.size()];
    for (int i = 0; i < vars.size(); i++) {
        causalOrdering[i] = i;
    }
    LargeScaleSimulation simulator = new LargeScaleSimulation(dag, vars, causalOrdering);
    simulator.setOut(out);
    DataSet data = simulator.simulateDataFisher(numCases);
    // ICovarianceMatrix cov = new CovarianceMatrix(data);
    ICovarianceMatrix cov = new CovarianceMatrixOnTheFly(data);
    SemBicScore score = new SemBicScore(cov);
    score.setPenaltyDiscount(penaltyDiscount);
    Fges fges = new Fges(score);
    fges.setVerbose(false);
    fges.setNumPatternsToStore(0);
    fges.setOut(out);
    fges.setFaithfulnessAssumed(true);
    // fges.setMaxIndegree(1);
    fges.setCycleBound(5);
    Graph estPattern = fges.search();
    // printDegreeDistribution(estPattern, out);
    final Graph truePattern = SearchGraphUtils.patternForDag(dag);
    int[][] counts = SearchGraphUtils.graphComparison(estPattern, truePattern, null);
    int[][] expectedCounts = { { 2, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 8, 0, 0 }, { 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 } };
    for (int i = 0; i < counts.length; i++) {
        assertTrue(Arrays.equals(counts[i], expectedCounts[i]));
    }
// 
// System.out.println(MatrixUtils.toString(expectedCounts));
// System.out.println(MatrixUtils.toString(counts));
}
Also used : Fges(edu.cmu.tetrad.search.Fges) RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph) SemBicScore(edu.cmu.tetrad.search.SemBicScore)

Example 7 with Fges

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

the class TestFges method testExplore5.

@Test
public void testExplore5() {
    Graph graph = GraphConverter.convert("A-->B,A-->C,A-->D,A->E,B-->F,C-->F,D-->F,E-->F");
    Fges fges = new Fges(new GraphScore(graph));
    fges.setFaithfulnessAssumed(false);
    Graph pattern = fges.search();
    assertEquals(SearchGraphUtils.patternForDag(graph), pattern);
}
Also used : RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph) Fges(edu.cmu.tetrad.search.Fges) SemBicDTest(edu.cmu.tetrad.algcomparison.independence.SemBicDTest) SemBicTest(edu.cmu.tetrad.algcomparison.independence.SemBicTest) Test(org.junit.Test)

Example 8 with Fges

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

the class TestFges method searchSemFges.

private Graph searchSemFges(DataSet Dk, double penalty) {
    Dk = DataUtils.convertNumericalDiscreteToContinuous(Dk);
    SemBicScore score = new SemBicScore(new CovarianceMatrixOnTheFly(Dk));
    score.setPenaltyDiscount(penalty);
    Fges fges = new Fges(score);
    return fges.search();
}
Also used : Fges(edu.cmu.tetrad.search.Fges) SemBicScore(edu.cmu.tetrad.search.SemBicScore)

Example 9 with Fges

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

the class TestFges method checkWithKnowledge.

/**
 * Presents the input graph to FCI and checks to make sure the output of FCI is equivalent to the given output
 * graph.
 */
private void checkWithKnowledge(String inputGraph, String answerGraph, IKnowledge knowledge) {
    // Set up graph and node objects.
    Graph input = GraphConverter.convert(inputGraph);
    // Set up search.
    Fges fges = new Fges(new GraphScore(input));
    // Set up search.
    fges.setKnowledge(knowledge);
    // Run search
    Graph result = fges.search();
    // Build comparison graph.
    Graph answer = GraphConverter.convert(answerGraph);
    // Graph answer = new PC(new IndTestDSep(input)).search();
    // System.out.println("Input = " + input);
    // System.out.println("Knowledge = " + knowledge);
    // System.out.println("Answer = " + answer);
    // System.out.println("Result graph = " + result);
    // Do test.
    assertEquals(answer, result);
}
Also used : RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph) Fges(edu.cmu.tetrad.search.Fges)

Example 10 with Fges

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

the class TestFges method testFromGraphSimpleFgesMb.

@Test
public void testFromGraphSimpleFgesMb() {
    // This may fail if faithfulness is assumed but should pass if not.
    Node x1 = new GraphNode("X1");
    Node x2 = new GraphNode("X2");
    Node x3 = new GraphNode("X3");
    Node x4 = new GraphNode("X4");
    Graph dag = new EdgeListGraph();
    dag.addNode(x1);
    dag.addNode(x2);
    dag.addNode(x3);
    dag.addNode(x4);
    dag.addDirectedEdge(x1, x2);
    dag.addDirectedEdge(x1, x3);
    dag.addDirectedEdge(x4, x2);
    dag.addDirectedEdge(x4, x3);
    GraphScore fgesScore = new GraphScore(dag);
    Fges fges = new Fges(fgesScore);
    Graph pattern1 = fges.search();
    Set<Node> mb = new HashSet<>();
    mb.add(x1);
    mb.addAll(pattern1.getAdjacentNodes(x1));
    for (Node child : pattern1.getChildren(x1)) {
        mb.addAll(pattern1.getParents(child));
    }
    Graph mb1 = pattern1.subgraph(new ArrayList<>(mb));
    FgesMb fgesMb = new FgesMb(fgesScore);
    Graph mb2 = fgesMb.search(x1);
    assertEquals(mb1, mb2);
}
Also used : RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph) Fges(edu.cmu.tetrad.search.Fges) SemBicDTest(edu.cmu.tetrad.algcomparison.independence.SemBicDTest) SemBicTest(edu.cmu.tetrad.algcomparison.independence.SemBicTest) Test(org.junit.Test)

Aggregations

Fges (edu.cmu.tetrad.search.Fges)25 RandomGraph (edu.cmu.tetrad.algcomparison.graph.RandomGraph)15 SemBicDTest (edu.cmu.tetrad.algcomparison.independence.SemBicDTest)11 SemBicTest (edu.cmu.tetrad.algcomparison.independence.SemBicTest)11 Test (org.junit.Test)11 SemBicScore (edu.cmu.tetrad.search.SemBicScore)9 Graph (edu.cmu.tetrad.graph.Graph)4 PatternToDag (edu.cmu.tetrad.search.PatternToDag)3 BootstrapEdgeEnsemble (edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble)3 GeneralBootstrapTest (edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest)3 DataSet (edu.cmu.tetrad.data.DataSet)2 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)2 BDeuScore (edu.cmu.tetrad.search.BDeuScore)2 Pc (edu.cmu.tetrad.search.Pc)2 ArrayList (java.util.ArrayList)2 Algorithm (edu.cmu.tetrad.algcomparison.algorithm.Algorithm)1 RandomForward (edu.cmu.tetrad.algcomparison.graph.RandomForward)1 FisherZ (edu.cmu.tetrad.algcomparison.independence.FisherZ)1 IndependenceWrapper (edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper)1 ScoreWrapper (edu.cmu.tetrad.algcomparison.score.ScoreWrapper)1