Search in sources :

Example 6 with LinearFisherModel

use of edu.cmu.tetrad.algcomparison.simulation.LinearFisherModel 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 LinearFisherModel

use of edu.cmu.tetrad.algcomparison.simulation.LinearFisherModel 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 8 with LinearFisherModel

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

Aggregations

RandomForward (edu.cmu.tetrad.algcomparison.graph.RandomForward)8 LinearFisherModel (edu.cmu.tetrad.algcomparison.simulation.LinearFisherModel)8 Comparison (edu.cmu.tetrad.algcomparison.Comparison)4 Algorithm (edu.cmu.tetrad.algcomparison.algorithm.Algorithm)4 Algorithms (edu.cmu.tetrad.algcomparison.algorithm.Algorithms)4 RandomGraph (edu.cmu.tetrad.algcomparison.graph.RandomGraph)4 Simulations (edu.cmu.tetrad.algcomparison.simulation.Simulations)4 Parameters (edu.cmu.tetrad.util.Parameters)4 FirstInflection (edu.cmu.tetrad.algcomparison.algorithm.FirstInflection)2 Fges (edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.Fges)2 IndependenceWrapper (edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper)2 SemBicTest (edu.cmu.tetrad.algcomparison.independence.SemBicTest)2 FisherZScore (edu.cmu.tetrad.algcomparison.score.FisherZScore)2 ScoreWrapper (edu.cmu.tetrad.algcomparison.score.ScoreWrapper)2 SemBicScore (edu.cmu.tetrad.algcomparison.score.SemBicScore)2 SemSimulation (edu.cmu.tetrad.algcomparison.simulation.SemSimulation)2 Fges (edu.cmu.tetrad.search.Fges)2 StARS (edu.cmu.tetrad.algcomparison.algorithm.StARS)1 StabilitySelection (edu.cmu.tetrad.algcomparison.algorithm.StabilitySelection)1 ImagesPcStableMax (edu.cmu.tetrad.algcomparison.algorithm.multi.ImagesPcStableMax)1