Search in sources :

Example 16 with RandomForward

use of edu.cmu.tetrad.algcomparison.graph.RandomForward 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 17 with RandomForward

use of edu.cmu.tetrad.algcomparison.graph.RandomForward in project tetrad by cmu-phil.

the class TestFges method test9.

public void test9() {
    Parameters parameters = new Parameters();
    parameters.set("numMeasures", 50);
    parameters.set("numLatents", 0);
    parameters.set("avgDegree", 2);
    parameters.set("maxDegree", 20);
    parameters.set("maxIndegree", 20);
    parameters.set("maxOutdegree", 20);
    parameters.set("connected", false);
    parameters.set("coefLow", 0.2);
    parameters.set("coefHigh", 0.9);
    parameters.set("varLow", 1);
    parameters.set("varHigh", 3);
    parameters.set("verbose", false);
    parameters.set("coefSymmetric", true);
    parameters.set("numRuns", 1);
    parameters.set("percentDiscrete", 0);
    parameters.set("numCategories", 3);
    parameters.set("differentGraphs", true);
    parameters.set("sampleSize", 500);
    parameters.set("intervalBetweenShocks", 10);
    parameters.set("intervalBetweenRecordings", 10);
    parameters.set("fisherEpsilon", 0.001);
    parameters.set("randomizeColumns", true);
    RandomGraph graph = new RandomForward();
    LinearFisherModel sim = new LinearFisherModel(graph);
    sim.createData(parameters);
    Graph previous = null;
    int prevDiff = Integer.MAX_VALUE;
    // for (int l = 7; l >= 1; l--) {
    for (int i = 2; i <= 20; i++) {
        parameters.set("penaltyDiscount", i / (double) 10);
        // parameters.set("alpha", Double.parseDouble("1E-" + l));
        // ScoreWrapper score = new edu.cmu.tetrad.algcomparison.score.SemBicScore();
        // Algorithm alg = new edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.Fges(score);
        IndependenceWrapper test = new SemBicTest();
        // IndependenceWrapper test = new FisherZ();
        Algorithm alg = new edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.Cpc(test);
        Graph out = alg.search(sim.getDataModel(0), parameters);
        // Graph out = GraphUtils.undirectedGraph(alg.search(sim.getDataModel(0), parameters));
        Set<Edge> edges1 = out.getEdges();
        int numEdges = edges1.size();
        if (previous != null) {
            Set<Edge> edges2 = previous.getEdges();
            edges2.removeAll(edges1);
            int diff = edges2.size();
            // 
            System.out.println("Penalty discount =" + parameters.getDouble("penaltyDiscount") + " # edges = " + numEdges + " # additional = " + diff);
            previous = out;
            if (diff > prevDiff)
                break;
            prevDiff = diff;
        } else {
            previous = out;
        }
    }
    Graph estGraph = previous;
    Graph trueGraph = sim.getTrueGraph(0);
    estGraph = GraphUtils.replaceNodes(estGraph, trueGraph.getNodes());
    Statistic ap = new AdjacencyPrecision();
    Statistic ar = new AdjacencyRecall();
    Statistic ahp = new ArrowheadPrecision();
    Statistic ahr = new ArrowheadRecall();
    System.out.println("AP = " + ap.getValue(trueGraph, estGraph));
    System.out.println("AR = " + ar.getValue(trueGraph, estGraph));
    System.out.println("AHP = " + ahp.getValue(trueGraph, estGraph));
    System.out.println("AHR = " + ahr.getValue(trueGraph, estGraph));
}
Also used : SemBicTest(edu.cmu.tetrad.algcomparison.independence.SemBicTest) LinearFisherModel(edu.cmu.tetrad.algcomparison.simulation.LinearFisherModel) RandomForward(edu.cmu.tetrad.algcomparison.graph.RandomForward) Algorithm(edu.cmu.tetrad.algcomparison.algorithm.Algorithm) RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph) IndependenceWrapper(edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper) RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph)

Example 18 with RandomForward

use of edu.cmu.tetrad.algcomparison.graph.RandomForward in project tetrad by cmu-phil.

the class TestFges method testFromData.

@Test
public void testFromData() {
    Parameters parameters = new Parameters();
    parameters.set("standardize", false);
    parameters.set("measurementVariance", 0);
    parameters.set("numRuns", 1);
    parameters.set("differentGraphs", true);
    parameters.set("sampleSize", 1000);
    parameters.set("numMeasures", 100);
    parameters.set("numLatents", 0);
    parameters.set("avgDegree", 6);
    // parameters.set("maxDegree", 100);
    // parameters.set("maxIndegree", 100);
    // parameters.set("maxOutdegree", 100);
    parameters.set("symmetricFirstStep", true);
    parameters.set("faithfulnessAssumed", false);
    parameters.set("penaltyDisount", 2);
    parameters.set("alpha", 0.001);
    parameters.set("coefLow", 0.2);
    parameters.set("coefHigh", 0.9);
    parameters.set("varLow", 1);
    parameters.set("varHigh", 3);
    parameters.set("coefSymmetric", true);
    parameters.set("covSymmetric", true);
    parameters.set("randomizeColumns", true);
    SemSimulation simulation = new SemSimulation(new RandomForward());
    simulation.createData(parameters);
    Graph dag = simulation.getTrueGraph(0);
    DataModel dataSet = simulation.getDataModel(0);
    edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.PcFges pcFges = new edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.PcFges(new edu.cmu.tetrad.algcomparison.score.SemBicScore(), false);
    long start = System.currentTimeMillis();
    Graph graph = pcFges.search(dataSet, parameters);
    long stop = System.currentTimeMillis();
    System.out.println("Elapsed " + (stop - start) + " ms");
    graph = GraphUtils.replaceNodes(graph, dag.getNodes());
    System.out.println(MisclassificationUtils.edgeMisclassifications(graph, dag));
}
Also used : SemSimulation(edu.cmu.tetrad.algcomparison.simulation.SemSimulation) RandomForward(edu.cmu.tetrad.algcomparison.graph.RandomForward) RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph) SemBicDTest(edu.cmu.tetrad.algcomparison.independence.SemBicDTest) SemBicTest(edu.cmu.tetrad.algcomparison.independence.SemBicTest) Test(org.junit.Test)

Example 19 with RandomForward

use of edu.cmu.tetrad.algcomparison.graph.RandomForward in project tetrad by cmu-phil.

the class TestImagesSimulation method test1.

public void test1() {
    Parameters parameters = new Parameters();
    parameters.set("numRuns", 1);
    parameters.set("numMeasures", 100);
    parameters.set("avgDegree", 8);
    // parameters.set("maxDegree", 8);
    // parameters.set("maxIndegree",  3);
    // parameters.set("maxOutdegree", 3);
    parameters.set("sampleSize", 500);
    parameters.set("penaltyDiscount", 4);
    // parameters.set("alpha", 0.001);
    // parameters.set("maxDegree", 5);
    // parameters.set("numCategoriesToDiscretize", 3);
    parameters.set("intervalBetweenRecordings", 20);
    parameters.set("varLow", 1.);
    parameters.set("varHigh", 3.);
    parameters.set("coefLow", .1);
    parameters.set("coefHigh", 1);
    parameters.set("coefSymmetric", true);
    parameters.set("meanLow", -1);
    parameters.set("meanHigh", 1);
    // parameters.set("scaleFreeAlpha", .9);
    // parameters.set("scaleFreeBeta", .05);
    // parameters.set("scaleFreeDeltaIn", 3);
    // parameters.set("scaleFreeDeltaOut", .1);
    parameters.set("numRuns", 1);
    parameters.set("randomSelectionSize", 3);
    Statistics statistics = new Statistics();
    // statistics.add(new ParameterColumn("numCategories"));
    statistics.add(new AdjacencyPrecision());
    statistics.add(new AdjacencyRecall());
    statistics.add(new ArrowheadPrecision());
    statistics.add(new ArrowheadRecall());
    statistics.add(new ElapsedTime());
    statistics.setWeight("AP", 1.0);
    statistics.setWeight("AR", 0.5);
    Algorithms algorithms = new Algorithms();
    algorithms.add(new ImagesSemBic());
    algorithms.add(new ImagesPcStableMax());
    Simulations simulations = new Simulations();
    simulations.add(new LinearFisherModel(new RandomForward()));
    Comparison comparison = new Comparison();
    comparison.setShowAlgorithmIndices(true);
    comparison.setShowSimulationIndices(false);
    comparison.setSortByUtility(false);
    comparison.setShowUtilities(false);
    comparison.setParallelized(true);
    // comparison.setSaveGraphs(true);
    comparison.setTabDelimitedTables(false);
    comparison.compareFromSimulations("comparison", simulations, algorithms, statistics, parameters);
}
Also used : Simulations(edu.cmu.tetrad.algcomparison.simulation.Simulations) Parameters(edu.cmu.tetrad.util.Parameters) LinearFisherModel(edu.cmu.tetrad.algcomparison.simulation.LinearFisherModel) ImagesPcStableMax(edu.cmu.tetrad.algcomparison.algorithm.multi.ImagesPcStableMax) RandomForward(edu.cmu.tetrad.algcomparison.graph.RandomForward) Algorithms(edu.cmu.tetrad.algcomparison.algorithm.Algorithms) ImagesSemBic(edu.cmu.tetrad.algcomparison.algorithm.multi.ImagesSemBic) Comparison(edu.cmu.tetrad.algcomparison.Comparison)

Example 20 with RandomForward

use of edu.cmu.tetrad.algcomparison.graph.RandomForward 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

RandomForward (edu.cmu.tetrad.algcomparison.graph.RandomForward)20 Comparison (edu.cmu.tetrad.algcomparison.Comparison)14 Parameters (edu.cmu.tetrad.util.Parameters)14 Simulations (edu.cmu.tetrad.algcomparison.simulation.Simulations)10 Algorithms (edu.cmu.tetrad.algcomparison.algorithm.Algorithms)9 SemSimulation (edu.cmu.tetrad.algcomparison.simulation.SemSimulation)9 LinearFisherModel (edu.cmu.tetrad.algcomparison.simulation.LinearFisherModel)8 RandomGraph (edu.cmu.tetrad.algcomparison.graph.RandomGraph)5 Algorithm (edu.cmu.tetrad.algcomparison.algorithm.Algorithm)4 FisherZ (edu.cmu.tetrad.algcomparison.independence.FisherZ)4 SemBicScore (edu.cmu.tetrad.algcomparison.score.SemBicScore)4 Simulation (edu.cmu.tetrad.algcomparison.simulation.Simulation)4 Fges (edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.Fges)3 SemBicTest (edu.cmu.tetrad.algcomparison.independence.SemBicTest)3 LeeHastieSimulation (edu.cmu.tetrad.algcomparison.simulation.LeeHastieSimulation)3 FirstInflection (edu.cmu.tetrad.algcomparison.algorithm.FirstInflection)2 IndependenceWrapper (edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper)2 SemBicDTest (edu.cmu.tetrad.algcomparison.independence.SemBicDTest)2 FisherZScore (edu.cmu.tetrad.algcomparison.score.FisherZScore)2 ScoreWrapper (edu.cmu.tetrad.algcomparison.score.ScoreWrapper)2