Search in sources :

Example 16 with Fges

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

the class TestFges method testExplore3.

@Test
public void testExplore3() {
    Graph graph = GraphConverter.convert("A-->B,A-->C,B-->D,C-->D");
    Fges fges = new Fges(new GraphScore(graph));
    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 17 with Fges

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

the class TestFges method testExplore4.

@Test
public void testExplore4() {
    Graph graph = GraphConverter.convert("A-->B,A-->C,A-->D,B-->E,C-->E,D-->E");
    Fges fges = new Fges(new GraphScore(graph));
    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 18 with Fges

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

the class TestFges method explore2.

@Test
public void explore2() {
    RandomUtil.getInstance().setSeed(1457220623122L);
    int numVars = 20;
    double edgeFactor = 1.0;
    int numCases = 1000;
    double structurePrior = 1;
    double samplePrior = 1;
    List<Node> vars = new ArrayList<>();
    for (int i = 0; i < numVars; i++) {
        vars.add(new ContinuousVariable("X" + i));
    }
    Graph dag = GraphUtils.randomGraphRandomForwardEdges(vars, 0, (int) (numVars * edgeFactor), 30, 15, 15, false, true);
    // printDegreeDistribution(dag, out);
    BayesPm pm = new BayesPm(dag, 2, 3);
    BayesIm im = new MlBayesIm(pm, MlBayesIm.RANDOM);
    DataSet data = im.simulateData(numCases, false);
    // out.println("Finishing simulation");
    BDeScore score = new BDeScore(data);
    score.setSamplePrior(samplePrior);
    score.setStructurePrior(structurePrior);
    Fges ges = new Fges(score);
    ges.setVerbose(false);
    ges.setNumPatternsToStore(0);
    ges.setFaithfulnessAssumed(false);
    Graph estPattern = ges.search();
    final Graph truePattern = SearchGraphUtils.patternForDag(dag);
    int[][] counts = SearchGraphUtils.graphComparison(estPattern, truePattern, null);
    int[][] expectedCounts = { { 2, 0, 0, 0, 0, 1 }, { 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0 }, { 2, 0, 0, 13, 0, 3 }, { 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));
// System.out.println(RandomUtil.getInstance().getSeed());
}
Also used : MlBayesIm(edu.cmu.tetrad.bayes.MlBayesIm) Fges(edu.cmu.tetrad.search.Fges) RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph) BayesIm(edu.cmu.tetrad.bayes.BayesIm) MlBayesIm(edu.cmu.tetrad.bayes.MlBayesIm) BayesPm(edu.cmu.tetrad.bayes.BayesPm) SemBicDTest(edu.cmu.tetrad.algcomparison.independence.SemBicDTest) SemBicTest(edu.cmu.tetrad.algcomparison.independence.SemBicTest) Test(org.junit.Test)

Example 19 with Fges

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

the class TestFges method testFromGraphSimpleFges.

@Test
public void testFromGraphSimpleFges() {
    // 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 g = new EdgeListGraph();
    g.addNode(x1);
    g.addNode(x2);
    g.addNode(x3);
    g.addNode(x4);
    g.addDirectedEdge(x1, x2);
    g.addDirectedEdge(x1, x3);
    g.addDirectedEdge(x4, x2);
    g.addDirectedEdge(x4, x3);
    Graph pattern1 = new Pc(new IndTestDSep(g)).search();
    Fges fges = new Fges(new GraphScore(g));
    fges.setFaithfulnessAssumed(true);
    Graph pattern2 = fges.search();
    // System.out.println(pattern1);
    // System.out.println(pattern2);
    assertEquals(pattern1, pattern2);
}
Also used : RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph) Pc(edu.cmu.tetrad.search.Pc) 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 20 with Fges

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

the class TestFges method searchBdeuFges.

private Graph searchBdeuFges(DataSet Dk, int k) {
    Discretizer discretizer = new Discretizer(Dk);
    List<Node> nodes = Dk.getVariables();
    for (Node node : nodes) {
        if (node instanceof ContinuousVariable) {
            discretizer.equalIntervals(node, k);
        }
    }
    Dk = discretizer.discretize();
    BDeuScore score = new BDeuScore(Dk);
    score.setSamplePrior(1.0);
    score.setStructurePrior(1.0);
    Fges fges = new Fges(score);
    return fges.search();
}
Also used : Fges(edu.cmu.tetrad.search.Fges)

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