Search in sources :

Example 66 with GeneralBootstrapTest

use of edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest in project tetrad by cmu-phil.

the class Fci method search.

@Override
public Graph search(DataModel dataSet, Parameters parameters) {
    if (parameters.getInt("bootstrapSampleSize") < 1) {
        if (algorithm != null) {
            initialGraph = algorithm.search(dataSet, parameters);
        }
        edu.cmu.tetrad.search.Fci search = new edu.cmu.tetrad.search.Fci(test.getTest(dataSet, parameters));
        search.setDepth(parameters.getInt("depth"));
        search.setKnowledge(knowledge);
        search.setMaxPathLength(parameters.getInt("maxPathLength"));
        search.setCompleteRuleSetUsed(parameters.getBoolean("completeRuleSetUsed"));
        // }
        return search.search();
    } else {
        Fci algorithm = new Fci(test);
        // algorithm.setKnowledge(knowledge);
        // if (initialGraph != null) {
        // algorithm.setInitialGraph(initialGraph);
        // }
        DataSet data = (DataSet) dataSet;
        GeneralBootstrapTest search = new GeneralBootstrapTest(data, algorithm, parameters.getInt("bootstrapSampleSize"));
        search.setKnowledge(knowledge);
        BootstrapEdgeEnsemble edgeEnsemble = BootstrapEdgeEnsemble.Highest;
        switch(parameters.getInt("bootstrapEnsemble", 1)) {
            case 0:
                edgeEnsemble = BootstrapEdgeEnsemble.Preserved;
                break;
            case 1:
                edgeEnsemble = BootstrapEdgeEnsemble.Highest;
                break;
            case 2:
                edgeEnsemble = BootstrapEdgeEnsemble.Majority;
        }
        search.setEdgeEnsemble(edgeEnsemble);
        search.setParameters(parameters);
        search.setVerbose(parameters.getBoolean("verbose"));
        return search.search();
    }
}
Also used : GeneralBootstrapTest(edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest) BootstrapEdgeEnsemble(edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble) DataSet(edu.cmu.tetrad.data.DataSet)

Example 67 with GeneralBootstrapTest

use of edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest in project tetrad by cmu-phil.

the class TestGeneralBootstrapTest method testFCId.

@Test
public void testFCId() {
    double structurePrior = 1, samplePrior = 1;
    int depth = -1;
    int maxPathLength = -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("depth", depth);
    parameters.set("maxPathLength", maxPathLength);
    parameters.set("numPatternsToStore", 0);
    parameters.set("verbose", verbose);
    IndependenceWrapper test = new ChiSquare();
    Algorithm algorithm = new Fci(test);
    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);
}
Also used : MlBayesIm(edu.cmu.tetrad.bayes.MlBayesIm) Parameters(edu.cmu.tetrad.util.Parameters) ChiSquare(edu.cmu.tetrad.algcomparison.independence.ChiSquare) GeneralBootstrapTest(edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest) DataSet(edu.cmu.tetrad.data.DataSet) Algorithm(edu.cmu.tetrad.algcomparison.algorithm.Algorithm) 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) BayesIm(edu.cmu.tetrad.bayes.BayesIm) MlBayesIm(edu.cmu.tetrad.bayes.MlBayesIm) BayesPm(edu.cmu.tetrad.bayes.BayesPm) Test(org.junit.Test) GeneralBootstrapTest(edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest)

Example 68 with GeneralBootstrapTest

use of edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest 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);
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) GeneralBootstrapTest(edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest) DataSet(edu.cmu.tetrad.data.DataSet) ScoreWrapper(edu.cmu.tetrad.algcomparison.score.ScoreWrapper) Algorithm(edu.cmu.tetrad.algcomparison.algorithm.Algorithm) Fges(edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.Fges) Graph(edu.cmu.tetrad.graph.Graph) 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 69 with GeneralBootstrapTest

use of edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest 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);
}
Also used : MlBayesIm(edu.cmu.tetrad.bayes.MlBayesIm) Parameters(edu.cmu.tetrad.util.Parameters) GeneralBootstrapTest(edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest) DataSet(edu.cmu.tetrad.data.DataSet) ScoreWrapper(edu.cmu.tetrad.algcomparison.score.ScoreWrapper) Algorithm(edu.cmu.tetrad.algcomparison.algorithm.Algorithm) Fges(edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.Fges) Graph(edu.cmu.tetrad.graph.Graph) BayesIm(edu.cmu.tetrad.bayes.BayesIm) MlBayesIm(edu.cmu.tetrad.bayes.MlBayesIm) BdeuScore(edu.cmu.tetrad.algcomparison.score.BdeuScore) BayesPm(edu.cmu.tetrad.bayes.BayesPm) Test(org.junit.Test) GeneralBootstrapTest(edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest)

Example 70 with GeneralBootstrapTest

use of edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest 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);
}
Also used : MlBayesIm(edu.cmu.tetrad.bayes.MlBayesIm) Parameters(edu.cmu.tetrad.util.Parameters) ChiSquare(edu.cmu.tetrad.algcomparison.independence.ChiSquare) 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) BayesIm(edu.cmu.tetrad.bayes.BayesIm) MlBayesIm(edu.cmu.tetrad.bayes.MlBayesIm) BdeuScore(edu.cmu.tetrad.algcomparison.score.BdeuScore) BayesPm(edu.cmu.tetrad.bayes.BayesPm) Test(org.junit.Test) GeneralBootstrapTest(edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest)

Aggregations

GeneralBootstrapTest (edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest)72 BootstrapEdgeEnsemble (edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble)66 DataSet (edu.cmu.tetrad.data.DataSet)32 Graph (edu.cmu.tetrad.graph.Graph)21 ArrayList (java.util.ArrayList)21 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)15 TakesInitialGraph (edu.cmu.tetrad.algcomparison.utils.TakesInitialGraph)10 Lofs2 (edu.cmu.tetrad.search.Lofs2)10 Node (edu.cmu.tetrad.graph.Node)6 Parameters (edu.cmu.tetrad.util.Parameters)6 PrintStream (java.io.PrintStream)6 Test (org.junit.Test)6 Algorithm (edu.cmu.tetrad.algcomparison.algorithm.Algorithm)5 PcAll (edu.cmu.tetrad.search.PcAll)5 Fges (edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.Fges)4 IndependenceWrapper (edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper)4 ScoreWrapper (edu.cmu.tetrad.algcomparison.score.ScoreWrapper)4 edu.cmu.tetrad.search (edu.cmu.tetrad.search)4 DagToPag (edu.cmu.tetrad.search.DagToPag)4 IndTestScore (edu.cmu.tetrad.search.IndTestScore)4