use of edu.cmu.tetrad.search.Fges in project tetrad by cmu-phil.
the class MixedFgesTreatingDiscreteAsContinuous method search.
public Graph search(DataModel Dk, Parameters parameters) {
if (parameters.getInt("bootstrapSampleSize") < 1) {
DataSet mixedDataSet = DataUtils.getMixedDataSet(Dk);
mixedDataSet = DataUtils.convertNumericalDiscreteToContinuous(mixedDataSet);
SemBicScore score = new SemBicScore(new CovarianceMatrixOnTheFly(mixedDataSet));
score.setPenaltyDiscount(parameters.getDouble("penaltyDiscount"));
Fges fges = new Fges(score);
Graph p = fges.search();
return convertBack(mixedDataSet, p);
} else {
MixedFgesTreatingDiscreteAsContinuous algorithm = new MixedFgesTreatingDiscreteAsContinuous();
DataSet data = (DataSet) Dk;
GeneralBootstrapTest search = new GeneralBootstrapTest(data, algorithm, parameters.getInt("bootstrapSampleSize"));
BootstrapEdgeEnsemble edgeEnsemble = BootstrapEdgeEnsemble.Highest;
switch(parameters.getInt("bootstrapEnsemble", 1)) {
case 0:
edgeEnsemble = BootstrapEdgeEnsemble.Preserved;
break;
case 1:
edgeEnsemble = BootstrapEdgeEnsemble.Highest;
break;
case 2:
edgeEnsemble = BootstrapEdgeEnsemble.Majority;
}
search.setEdgeEnsemble(edgeEnsemble);
search.setParameters(parameters);
search.setVerbose(parameters.getBoolean("verbose"));
return search.search();
}
}
use of edu.cmu.tetrad.search.Fges in project tetrad by cmu-phil.
the class TestFges method checkSearch.
/**
* Presents the input graph to FCI and checks to make sure the output of FCI is equivalent to the given output
* graph.
*/
private void checkSearch(String inputGraph, String outputGraph) {
// Set up graph and node objects.
Graph graph = GraphConverter.convert(inputGraph);
// Set up search.
Fges fges = new Fges(new GraphScore(graph));
// Run search
Graph resultGraph = fges.search();
// Build comparison graph.
Graph trueGraph = GraphConverter.convert(outputGraph);
// PrintUtil out problem and graphs.
// System.out.println("\nInput graph:");
// System.out.println(graph);
// System.out.println("\nResult graph:");
// System.out.println(resultGraph);
// System.out.println("\nTrue graph:");
// System.out.println(trueGraph);
resultGraph = GraphUtils.replaceNodes(resultGraph, trueGraph.getNodes());
// Do test.
assertTrue(resultGraph.equals(trueGraph));
}
use of edu.cmu.tetrad.search.Fges in project tetrad by cmu-phil.
the class TestFges method clarkTest.
@Test
public void clarkTest() {
RandomGraph randomGraph = new RandomForward();
Simulation simulation = new LinearFisherModel(randomGraph);
Parameters parameters = new Parameters();
parameters.set("numMeasures", 100);
parameters.set("numLatents", 0);
parameters.set("coefLow", 0.2);
parameters.set("coefHigh", 0.8);
parameters.set("avgDegree", 2);
parameters.set("maxDegree", 100);
parameters.set("maxIndegree", 100);
parameters.set("maxOutdegree", 100);
parameters.set("connected", false);
parameters.set("numRuns", 1);
parameters.set("differentGraphs", false);
parameters.set("sampleSize", 1000);
parameters.set("faithfulnessAssumed", false);
parameters.set("maxDegree", -1);
parameters.set("verbose", false);
parameters.set("alpha", 0.01);
simulation.createData(parameters);
DataSet dataSet = (DataSet) simulation.getDataModel(0);
Graph trueGraph = simulation.getTrueGraph(0);
// trueGraph = SearchGraphUtils.patternForDag(trueGraph);
ScoreWrapper score = new edu.cmu.tetrad.algcomparison.score.SemBicScore();
IndependenceWrapper test = new FisherZ();
Algorithm fges = new edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.Fges(score, false);
Graph fgesGraph = fges.search(dataSet, parameters);
clarkTestForAlpha(0.05, parameters, dataSet, trueGraph, fgesGraph, test);
clarkTestForAlpha(0.01, parameters, dataSet, trueGraph, fgesGraph, test);
}
use of edu.cmu.tetrad.search.Fges 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();
}
use of edu.cmu.tetrad.search.Fges in project tetrad by cmu-phil.
the class TestFges method testFromGraph.
@Test
public void testFromGraph() {
int numNodes = 20;
int numIterations = 20;
for (int i = 0; i < numIterations; i++) {
// System.out.println("Iteration " + (i + 1));
Graph dag = GraphUtils.randomDag(numNodes, 0, numNodes, 10, 10, 10, false);
Fges fges = new Fges(new GraphScore(dag));
fges.setFaithfulnessAssumed(true);
Graph pattern1 = fges.search();
Graph pattern2 = new Pc(new IndTestDSep(dag)).search();
// System.out.println(pattern2);
assertEquals(pattern2, pattern1);
}
}
Aggregations