Search in sources :

Example 6 with DagToPag

use of edu.cmu.tetrad.search.DagToPag 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 7 with DagToPag

use of edu.cmu.tetrad.search.DagToPag 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)

Aggregations

DagToPag (edu.cmu.tetrad.search.DagToPag)7 Algorithm (edu.cmu.tetrad.algcomparison.algorithm.Algorithm)5 DataSet (edu.cmu.tetrad.data.DataSet)5 Graph (edu.cmu.tetrad.graph.Graph)5 Parameters (edu.cmu.tetrad.util.Parameters)5 IndependenceWrapper (edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper)4 GeneralBootstrapTest (edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest)4 Test (org.junit.Test)4 ExternalAlgorithm (edu.cmu.tetrad.algcomparison.algorithm.ExternalAlgorithm)2 MultiDataSetAlgorithm (edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm)2 Fci (edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.Fci)2 Gfci (edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.Gfci)2 ChiSquare (edu.cmu.tetrad.algcomparison.independence.ChiSquare)2 FisherZ (edu.cmu.tetrad.algcomparison.independence.FisherZ)2 ScoreWrapper (edu.cmu.tetrad.algcomparison.score.ScoreWrapper)2 Simulation (edu.cmu.tetrad.algcomparison.simulation.Simulation)2 ElapsedTime (edu.cmu.tetrad.algcomparison.statistic.ElapsedTime)2 ParameterColumn (edu.cmu.tetrad.algcomparison.statistic.ParameterColumn)2 Statistic (edu.cmu.tetrad.algcomparison.statistic.Statistic)2 HasKnowledge (edu.cmu.tetrad.algcomparison.utils.HasKnowledge)2