Search in sources :

Example 6 with FisherZ

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);
}
Also used : LinearFisherModel(edu.cmu.tetrad.algcomparison.simulation.LinearFisherModel) ScoreWrapper(edu.cmu.tetrad.algcomparison.score.ScoreWrapper) RandomForward(edu.cmu.tetrad.algcomparison.graph.RandomForward) Algorithm(edu.cmu.tetrad.algcomparison.algorithm.Algorithm) Fges(edu.cmu.tetrad.search.Fges) RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph) IndependenceWrapper(edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper) RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph) FisherZ(edu.cmu.tetrad.algcomparison.independence.FisherZ) SemSimulation(edu.cmu.tetrad.algcomparison.simulation.SemSimulation) Simulation(edu.cmu.tetrad.algcomparison.simulation.Simulation) SemBicScore(edu.cmu.tetrad.search.SemBicScore) SemBicDTest(edu.cmu.tetrad.algcomparison.independence.SemBicDTest) SemBicTest(edu.cmu.tetrad.algcomparison.independence.SemBicTest) Test(org.junit.Test)

Example 7 with FisherZ

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);
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) GeneralBootstrapTest(edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest) DataSet(edu.cmu.tetrad.data.DataSet) Fci(edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.Fci) IndependenceWrapper(edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper) Graph(edu.cmu.tetrad.graph.Graph) DagToPag(edu.cmu.tetrad.search.DagToPag) FisherZ(edu.cmu.tetrad.algcomparison.independence.FisherZ) LargeScaleSimulation(edu.cmu.tetrad.sem.LargeScaleSimulation) Test(org.junit.Test) GeneralBootstrapTest(edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest)

Example 8 with FisherZ

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);
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) GeneralBootstrapTest(edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest) Gfci(edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.Gfci) DataSet(edu.cmu.tetrad.data.DataSet) ScoreWrapper(edu.cmu.tetrad.algcomparison.score.ScoreWrapper) Algorithm(edu.cmu.tetrad.algcomparison.algorithm.Algorithm) IndependenceWrapper(edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper) Graph(edu.cmu.tetrad.graph.Graph) DagToPag(edu.cmu.tetrad.search.DagToPag) FisherZ(edu.cmu.tetrad.algcomparison.independence.FisherZ) LargeScaleSimulation(edu.cmu.tetrad.sem.LargeScaleSimulation) SemBicScore(edu.cmu.tetrad.algcomparison.score.SemBicScore) Test(org.junit.Test) GeneralBootstrapTest(edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest)

Example 9 with FisherZ

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);
}
Also used : Simulations(edu.cmu.tetrad.algcomparison.simulation.Simulations) Parameters(edu.cmu.tetrad.util.Parameters) SemSimulation(edu.cmu.tetrad.algcomparison.simulation.SemSimulation) RandomForward(edu.cmu.tetrad.algcomparison.graph.RandomForward) Algorithms(edu.cmu.tetrad.algcomparison.algorithm.Algorithms) FisherZ(edu.cmu.tetrad.algcomparison.independence.FisherZ) Comparison(edu.cmu.tetrad.algcomparison.Comparison)

Aggregations

FisherZ (edu.cmu.tetrad.algcomparison.independence.FisherZ)9 Parameters (edu.cmu.tetrad.util.Parameters)7 Algorithms (edu.cmu.tetrad.algcomparison.algorithm.Algorithms)6 Comparison (edu.cmu.tetrad.algcomparison.Comparison)5 SemBicScore (edu.cmu.tetrad.algcomparison.score.SemBicScore)5 RandomForward (edu.cmu.tetrad.algcomparison.graph.RandomForward)4 Gfci (edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.Gfci)3 IndependenceWrapper (edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper)3 SemSimulation (edu.cmu.tetrad.algcomparison.simulation.SemSimulation)3 Simulations (edu.cmu.tetrad.algcomparison.simulation.Simulations)3 Test (org.junit.Test)3 Algorithm (edu.cmu.tetrad.algcomparison.algorithm.Algorithm)2 ScoreWrapper (edu.cmu.tetrad.algcomparison.score.ScoreWrapper)2 DataSet (edu.cmu.tetrad.data.DataSet)2 Graph (edu.cmu.tetrad.graph.Graph)2 DagToPag (edu.cmu.tetrad.search.DagToPag)2 LargeScaleSimulation (edu.cmu.tetrad.sem.LargeScaleSimulation)2 GeneralBootstrapTest (edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest)2 Fci (edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.Fci)1 TsFci (edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.TsFci)1