Search in sources :

Example 1 with SemBicTest

use of edu.cmu.tetrad.algcomparison.independence.SemBicTest in project tetrad by cmu-phil.

the class TestKunMeasurementError method TestCycles_Data_fMRI_FASK.

public void TestCycles_Data_fMRI_FASK() {
    Parameters parameters = new Parameters();
    parameters.set("numRuns", 20);
    parameters.set("penaltyDiscount", 1);
    parameters.set("depth", -1);
    parameters.set("determinismThreshold", .1);
    parameters.set("verbose", true);
    parameters.set("symmetricFirstStep", false);
    parameters.set("faithfulnessAssumed", false);
    parameters.set("maxDegree", 100);
    Statistics statistics = new Statistics();
    // statistics.add(new ParameterColumn("determinismThreshold"));
    statistics.add(new AdjacencyPrecision());
    statistics.add(new AdjacencyRecall());
    statistics.add(new ArrowheadPrecision());
    statistics.add(new ArrowheadRecall());
    Simulations simulations = new Simulations();
    // String dir = "/Users/user/Downloads/Simul1_T500";
    String dir = "/Users/user/Downloads/Simul1_T2000";
    // String dir = "/Users/user/Downloads/Simul2_T500";
    // String dir = "/Users/user/Downloads/Simul2_T2000";
    simulations.add(new LoadContinuousDataAndSingleGraphKun(dir, "Cov_X"));
    simulations.add(new LoadContinuousDataAndSingleGraphKun(dir, "Cov_tilde"));
    simulations.add(new LoadContinuousDataAndSingleGraphKun(dir, "Cov_tilde_hat"));
    // 
    Algorithms algorithms = new Algorithms();
    IndependenceWrapper test = new SemBicTest();
    ScoreWrapper score = new SemBicScore();
    algorithms.add(new Pc(test));
    algorithms.add(new Fges(score));
    algorithms.add(new Pcd());
    algorithms.add(new FgesD());
    Comparison comparison = new Comparison();
    comparison.setShowAlgorithmIndices(true);
    comparison.setShowSimulationIndices(true);
    comparison.setSortByUtility(false);
    comparison.setShowUtilities(false);
    comparison.setParallelized(false);
    comparison.setSaveGraphs(false);
    comparison.setTabDelimitedTables(false);
    comparison.compareFromSimulations("comparison", simulations, algorithms, statistics, parameters);
}
Also used : Simulations(edu.cmu.tetrad.algcomparison.simulation.Simulations) SemBicTest(edu.cmu.tetrad.algcomparison.independence.SemBicTest) Parameters(edu.cmu.tetrad.util.Parameters) ScoreWrapper(edu.cmu.tetrad.algcomparison.score.ScoreWrapper) Fges(edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.Fges) Pcd(edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.Pcd) IndependenceWrapper(edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper) Algorithms(edu.cmu.tetrad.algcomparison.algorithm.Algorithms) Pc(edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.Pc) Comparison(edu.cmu.tetrad.algcomparison.Comparison) SemBicScore(edu.cmu.tetrad.algcomparison.score.SemBicScore) FgesD(edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.FgesD)

Example 2 with SemBicTest

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

Aggregations

IndependenceWrapper (edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper)2 SemBicTest (edu.cmu.tetrad.algcomparison.independence.SemBicTest)2 Comparison (edu.cmu.tetrad.algcomparison.Comparison)1 Algorithm (edu.cmu.tetrad.algcomparison.algorithm.Algorithm)1 Algorithms (edu.cmu.tetrad.algcomparison.algorithm.Algorithms)1 Fges (edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.Fges)1 FgesD (edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.FgesD)1 Pc (edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.Pc)1 Pcd (edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.Pcd)1 RandomForward (edu.cmu.tetrad.algcomparison.graph.RandomForward)1 RandomGraph (edu.cmu.tetrad.algcomparison.graph.RandomGraph)1 ScoreWrapper (edu.cmu.tetrad.algcomparison.score.ScoreWrapper)1 SemBicScore (edu.cmu.tetrad.algcomparison.score.SemBicScore)1 LinearFisherModel (edu.cmu.tetrad.algcomparison.simulation.LinearFisherModel)1 Simulations (edu.cmu.tetrad.algcomparison.simulation.Simulations)1 Parameters (edu.cmu.tetrad.util.Parameters)1