use of edu.cmu.tetrad.algcomparison.independence.FisherZ 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.independence.FisherZ in project tetrad by cmu-phil.
the class TestGeneralBootstrapTest method testFCIc.
@Test
public void testFCIc() {
int penaltyDiscount = 2;
int depth = 3;
int maxPathLength = -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("depth", depth);
parameters.set("maxPathLength", maxPathLength);
parameters.set("numPatternsToStore", 0);
parameters.set("verbose", verbose);
IndependenceWrapper test = new FisherZ();
Fci algorithm = new Fci(test);
GeneralBootstrapTest bootstrapTest = new GeneralBootstrapTest(data, algorithm, numBootstrapSamples);
bootstrapTest.setVerbose(verbose);
bootstrapTest.setParameters(parameters);
bootstrapTest.setEdgeEnsemble(BootstrapEdgeEnsemble.Preserved);
// bootstrapTest.setParallelMode(false);
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);
}
use of edu.cmu.tetrad.algcomparison.independence.FisherZ 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);
}
use of edu.cmu.tetrad.algcomparison.independence.FisherZ in project tetrad by cmu-phil.
the class TestCopy method main.
/**
* An example script to simulate data and run a comparison analysis on it.
*
* @author jdramsey
*/
public static void main(String... args) {
Parameters parameters = new Parameters();
parameters.set("numRuns", 10);
parameters.set("numMeasures", 100);
parameters.set("avgDegree", 2, 4, 6);
parameters.set("sampleSize", 200);
parameters.set("alpha", 1e-4, 1e-3, 1e-2);
parameters.set("penaltyDiscount", 1);
Statistics statistics = new Statistics();
statistics.add(new ParameterColumn("sampleSize"));
statistics.add(new ParameterColumn("avgDegree"));
statistics.add(new ParameterColumn("alpha"));
statistics.add(new AdjacencyPrecision());
statistics.add(new AdjacencyRecall());
statistics.add(new ArrowheadPrecision());
statistics.add(new ArrowheadRecall());
statistics.add(new MathewsCorrAdj());
statistics.add(new MathewsCorrArrow());
statistics.add(new F1Adj());
statistics.add(new F1Arrow());
statistics.add(new SHD());
statistics.add(new ElapsedTime());
statistics.setWeight("AP", 1.0);
statistics.setWeight("AHP", 1.0);
Algorithms algorithms = new Algorithms();
algorithms.add(new Pc(new FisherZ()));
algorithms.add(new PcStableMax(new FisherZ(), false));
Simulations simulations = new Simulations();
simulations.add(new SemSimulation(new RandomForward()));
Comparison comparison = new Comparison();
comparison.setShowAlgorithmIndices(true);
comparison.setShowSimulationIndices(true);
comparison.setSortByUtility(true);
comparison.setShowUtilities(true);
comparison.setParallelized(true);
comparison.compareFromSimulations("comparison", simulations, algorithms, statistics, parameters);
}
Aggregations