use of edu.cmu.tetrad.algcomparison.score.BdeuScore in project tetrad by cmu-phil.
the class TsImages method search.
@Override
public Graph search(List<DataModel> dataSets, Parameters parameters) {
List<DataModel> dataModels = new ArrayList<>();
for (DataModel dataSet : dataSets) {
dataModels.add(dataSet);
}
TsGFci search;
if (score instanceof SemBicScore) {
SemBicScoreImages gesScore = new SemBicScoreImages(dataModels);
gesScore.setPenaltyDiscount(parameters.getDouble("penaltyDiscount"));
IndependenceTest test = new IndTestScore(gesScore);
search = new TsGFci(test, gesScore);
} else if (score instanceof BdeuScore) {
double samplePrior = parameters.getDouble("samplePrior", 1);
double structurePrior = parameters.getDouble("structurePrior", 1);
BdeuScoreImages score = new BdeuScoreImages(dataModels);
score.setSamplePrior(samplePrior);
score.setStructurePrior(structurePrior);
IndependenceTest test = new IndTestScore(score);
search = new TsGFci(test, score);
} else {
throw new IllegalStateException("Sorry, data must either be all continuous or all discrete.");
}
IKnowledge knowledge = dataModels.get(0).getKnowledge();
search.setKnowledge(knowledge);
return search.search();
}
use of edu.cmu.tetrad.algcomparison.score.BdeuScore in project tetrad by cmu-phil.
the class ImagesBDeu method getParameters.
@Override
public List<String> getParameters() {
List<String> parameters = new Fges(new BdeuScore(), false).getParameters();
parameters.add("numRuns");
parameters.add("randomSelectionSize");
// Bootstrapping
parameters.add("bootstrapSampleSize");
parameters.add("bootstrapEnsemble");
parameters.add("verbose");
return parameters;
}
use of edu.cmu.tetrad.algcomparison.score.BdeuScore 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.cmu.tetrad.algcomparison.score.BdeuScore 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