Search in sources :

Example 21 with Algorithm

use of edu.cmu.tetrad.algcomparison.algorithm.Algorithm 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 22 with Algorithm

use of edu.cmu.tetrad.algcomparison.algorithm.Algorithm 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 23 with Algorithm

use of edu.cmu.tetrad.algcomparison.algorithm.Algorithm 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 24 with Algorithm

use of edu.cmu.tetrad.algcomparison.algorithm.Algorithm 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)

Example 25 with Algorithm

use of edu.cmu.tetrad.algcomparison.algorithm.Algorithm 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

Algorithm (edu.cmu.tetrad.algcomparison.algorithm.Algorithm)25 MultiDataSetAlgorithm (edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm)13 ExternalAlgorithm (edu.cmu.tetrad.algcomparison.algorithm.ExternalAlgorithm)12 Parameters (edu.cmu.tetrad.util.Parameters)10 Simulation (edu.cmu.tetrad.algcomparison.simulation.Simulation)9 ScoreWrapper (edu.cmu.tetrad.algcomparison.score.ScoreWrapper)8 Statistic (edu.cmu.tetrad.algcomparison.statistic.Statistic)8 Graph (edu.cmu.tetrad.graph.Graph)8 IndependenceWrapper (edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper)7 DataSet (edu.cmu.tetrad.data.DataSet)7 Test (org.junit.Test)6 Simulations (edu.cmu.tetrad.algcomparison.simulation.Simulations)5 DagToPag (edu.cmu.tetrad.search.DagToPag)5 GeneralBootstrapTest (edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest)5 Fges (edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.Fges)4 RandomForward (edu.cmu.tetrad.algcomparison.graph.RandomForward)4 BdeuScore (edu.cmu.tetrad.algcomparison.score.BdeuScore)4 SemBicScore (edu.cmu.tetrad.algcomparison.score.SemBicScore)4 LinearFisherModel (edu.cmu.tetrad.algcomparison.simulation.LinearFisherModel)4 LoadDataAndGraphs (edu.cmu.tetrad.algcomparison.simulation.LoadDataAndGraphs)4