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);
}
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);
}
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());
}
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);
}
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();
}
Aggregations