use of edu.cmu.tetrad.algcomparison.score.ScoreWrapper 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.algcomparison.score.ScoreWrapper 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.cmu.tetrad.algcomparison.score.ScoreWrapper 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.ScoreWrapper 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);
}
use of edu.cmu.tetrad.algcomparison.score.ScoreWrapper in project tetrad by cmu-phil.
the class TestGeneralBootstrapTest method testGFCIc.
@Test
public void testGFCIc() {
int penaltyDiscount = 2;
boolean faithfulnessAssumed = false;
int maxDegree = -1;
int numVars = 20;
int edgesPerNode = 2;
int numLatentConfounders = 2;
int numCases = 50;
int numBootstrapSamples = 5;
boolean verbose = true;
Graph dag = makeContinuousDAG(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());
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();
IndependenceWrapper test = new FisherZ();
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 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