use of edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest in project tetrad by cmu-phil.
the class Fci method search.
@Override
public Graph search(DataModel dataSet, Parameters parameters) {
if (parameters.getInt("bootstrapSampleSize") < 1) {
if (algorithm != null) {
initialGraph = algorithm.search(dataSet, parameters);
}
edu.cmu.tetrad.search.Fci search = new edu.cmu.tetrad.search.Fci(test.getTest(dataSet, parameters));
search.setDepth(parameters.getInt("depth"));
search.setKnowledge(knowledge);
search.setMaxPathLength(parameters.getInt("maxPathLength"));
search.setCompleteRuleSetUsed(parameters.getBoolean("completeRuleSetUsed"));
// }
return search.search();
} else {
Fci algorithm = new Fci(test);
// algorithm.setKnowledge(knowledge);
// if (initialGraph != null) {
// algorithm.setInitialGraph(initialGraph);
// }
DataSet data = (DataSet) dataSet;
GeneralBootstrapTest search = new GeneralBootstrapTest(data, algorithm, parameters.getInt("bootstrapSampleSize"));
search.setKnowledge(knowledge);
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.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest in project tetrad by cmu-phil.
the class TestGeneralBootstrapTest method testFCId.
@Test
public void testFCId() {
double structurePrior = 1, samplePrior = 1;
int depth = -1;
int maxPathLength = -1;
int numVars = 20;
int edgesPerNode = 2;
int numLatentConfounders = 4;
int numCases = 50;
int numBootstrapSamples = 5;
boolean verbose = true;
long seed = 123;
Graph dag = makeDiscreteDAG(numVars, numLatentConfounders, edgesPerNode);
DagToPag dagToPag = new DagToPag(dag);
Graph truePag = dagToPag.convert();
System.out.println("Truth PAG_of_the_true_DAG Graph:");
System.out.println(truePag.toString());
BayesPm pm = new BayesPm(dag, 2, 3);
BayesIm im = new MlBayesIm(pm, MlBayesIm.RANDOM);
DataSet data = im.simulateData(numCases, seed, false);
Parameters parameters = new Parameters();
parameters.set("structurePrior", structurePrior);
parameters.set("samplePrior", samplePrior);
parameters.set("depth", depth);
parameters.set("maxPathLength", maxPathLength);
parameters.set("numPatternsToStore", 0);
parameters.set("verbose", verbose);
IndependenceWrapper test = new ChiSquare();
Algorithm algorithm = new Fci(test);
GeneralBootstrapTest bootstrapTest = new GeneralBootstrapTest(data, algorithm, numBootstrapSamples);
bootstrapTest.setVerbose(verbose);
bootstrapTest.setParameters(parameters);
bootstrapTest.setEdgeEnsemble(BootstrapEdgeEnsemble.Highest);
Graph resultGraph = bootstrapTest.search();
System.out.println("Estimated Bootstrapped PAG_of_the_true_DAG Graph:");
System.out.println(resultGraph.toString());
// Adjacency Confusion Matrix
int[][] adjAr = GeneralBootstrapTest.getAdjConfusionMatrix(truePag, resultGraph);
printAdjConfusionMatrix(adjAr);
// Edge Type Confusion Matrix
int[][] edgeAr = GeneralBootstrapTest.getEdgeTypeConfusionMatrix(truePag, resultGraph);
printEdgeTypeConfusionMatrix(edgeAr);
}
use of edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest in project tetrad by cmu-phil.
the class TestGeneralBootstrapTest method testFGESc.
@Test
public void testFGESc() {
int penaltyDiscount = 2;
boolean faithfulnessAssumed = false;
int maxDegree = -1;
int numVars = 20;
int edgesPerNode = 2;
int numLatentConfounders = 0;
int numCases = 50;
int numBootstrapSamples = 5;
boolean verbose = true;
Graph dag = makeContinuousDAG(numVars, numLatentConfounders, edgesPerNode);
System.out.println("Truth Graph:");
System.out.println(dag.toString());
int[] causalOrdering = new int[numVars];
for (int i = 0; i < numVars; i++) {
causalOrdering[i] = i;
}
LargeScaleSimulation simulator = new LargeScaleSimulation(dag, dag.getNodes(), causalOrdering);
DataSet data = simulator.simulateDataFisher(numCases);
Parameters parameters = new Parameters();
parameters.set("penaltyDiscount", penaltyDiscount);
parameters.set("faithfulnessAssumed", faithfulnessAssumed);
parameters.set("maxDegree", maxDegree);
parameters.set("numPatternsToStore", 0);
parameters.set("verbose", verbose);
ScoreWrapper score = new SemBicScore();
Algorithm algorithm = new Fges(score);
GeneralBootstrapTest bootstrapTest = new GeneralBootstrapTest(data, algorithm, numBootstrapSamples);
bootstrapTest.setVerbose(verbose);
bootstrapTest.setParameters(parameters);
bootstrapTest.setEdgeEnsemble(BootstrapEdgeEnsemble.Highest);
Graph resultGraph = bootstrapTest.search();
System.out.println("Estimated Graph:");
System.out.println(resultGraph.toString());
// Adjacency Confusion Matrix
int[][] adjAr = GeneralBootstrapTest.getAdjConfusionMatrix(dag, resultGraph);
printAdjConfusionMatrix(adjAr);
// Edge Type Confusion Matrix
int[][] edgeAr = GeneralBootstrapTest.getEdgeTypeConfusionMatrix(dag, resultGraph);
printEdgeTypeConfusionMatrix(edgeAr);
}
use of edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest in project tetrad by cmu-phil.
the class TestGeneralBootstrapTest method testFGESd.
@Test
public void testFGESd() {
double structurePrior = 1, samplePrior = 1;
boolean faithfulnessAssumed = false;
int maxDegree = -1;
int numVars = 20;
int edgesPerNode = 2;
int numLatentConfounders = 0;
int numCases = 50;
int numBootstrapSamples = 5;
boolean verbose = true;
long seed = 123;
Graph dag = makeDiscreteDAG(numVars, numLatentConfounders, edgesPerNode);
System.out.println("Truth Graph:");
System.out.println(dag.toString());
BayesPm pm = new BayesPm(dag, 2, 3);
BayesIm im = new MlBayesIm(pm, MlBayesIm.RANDOM);
DataSet data = im.simulateData(numCases, seed, false);
Parameters parameters = new Parameters();
parameters.set("structurePrior", structurePrior);
parameters.set("samplePrior", samplePrior);
parameters.set("faithfulnessAssumed", faithfulnessAssumed);
parameters.set("maxDegree", maxDegree);
parameters.set("numPatternsToStore", 0);
parameters.set("verbose", verbose);
ScoreWrapper score = new BdeuScore();
Algorithm algorithm = new Fges(score);
GeneralBootstrapTest bootstrapTest = new GeneralBootstrapTest(data, algorithm, numBootstrapSamples);
bootstrapTest.setVerbose(verbose);
bootstrapTest.setParameters(parameters);
bootstrapTest.setEdgeEnsemble(BootstrapEdgeEnsemble.Highest);
Graph resultGraph = bootstrapTest.search();
System.out.println("Estimated Graph:");
System.out.println(resultGraph.toString());
// Adjacency Confusion Matrix
int[][] adjAr = GeneralBootstrapTest.getAdjConfusionMatrix(dag, resultGraph);
printAdjConfusionMatrix(adjAr);
// Edge Type Confusion Matrix
int[][] edgeAr = GeneralBootstrapTest.getEdgeTypeConfusionMatrix(dag, resultGraph);
printEdgeTypeConfusionMatrix(edgeAr);
}
use of edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest in project tetrad by cmu-phil.
the class TestGeneralBootstrapTest method testGFCId.
@Test
public void testGFCId() {
double structurePrior = 1, samplePrior = 1;
boolean faithfulnessAssumed = false;
int maxDegree = -1;
int numVars = 20;
int edgesPerNode = 2;
int numLatentConfounders = 4;
int numCases = 50;
int numBootstrapSamples = 5;
boolean verbose = true;
long seed = 123;
Graph dag = makeDiscreteDAG(numVars, numLatentConfounders, edgesPerNode);
DagToPag dagToPag = new DagToPag(dag);
Graph truePag = dagToPag.convert();
System.out.println("Truth PAG_of_the_true_DAG Graph:");
System.out.println(truePag.toString());
BayesPm pm = new BayesPm(dag, 2, 3);
BayesIm im = new MlBayesIm(pm, MlBayesIm.RANDOM);
DataSet data = im.simulateData(numCases, seed, false);
Parameters parameters = new Parameters();
parameters.set("structurePrior", structurePrior);
parameters.set("samplePrior", samplePrior);
parameters.set("faithfulnessAssumed", faithfulnessAssumed);
parameters.set("maxDegree", maxDegree);
parameters.set("numPatternsToStore", 0);
parameters.set("verbose", verbose);
ScoreWrapper score = new BdeuScore();
IndependenceWrapper test = new ChiSquare();
Algorithm algorithm = new Gfci(test, score);
GeneralBootstrapTest bootstrapTest = new GeneralBootstrapTest(data, algorithm, numBootstrapSamples);
bootstrapTest.setVerbose(verbose);
bootstrapTest.setParameters(parameters);
bootstrapTest.setEdgeEnsemble(BootstrapEdgeEnsemble.Highest);
Graph resultGraph = bootstrapTest.search();
System.out.println("Estimated Bootstrapped PAG_of_the_true_DAG Graph:");
System.out.println(resultGraph.toString());
// Adjacency Confusion Matrix
int[][] adjAr = GeneralBootstrapTest.getAdjConfusionMatrix(truePag, resultGraph);
printAdjConfusionMatrix(adjAr);
// Edge Type Confusion Matrix
int[][] edgeAr = GeneralBootstrapTest.getEdgeTypeConfusionMatrix(truePag, resultGraph);
printEdgeTypeConfusionMatrix(edgeAr);
}
Aggregations