Search in sources :

Example 1 with IndependenceWrapper

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

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

the class TimeoutComparison method configuration.

/**
 */
public void configuration(String path) {
    try {
        new File(path).mkdirs();
        PrintStream out = new PrintStream(new FileOutputStream(new File(path, "Configuration.txt")));
        Parameters allParams = new Parameters();
        List<Class> algorithms = new ArrayList<>();
        List<Class> statistics = new ArrayList<>();
        List<Class> independenceWrappers = new ArrayList<>();
        List<Class> scoreWrappers = new ArrayList<>();
        List<Class> simulations = new ArrayList<>();
        algorithms.addAll(getClasses(Algorithm.class));
        statistics.addAll(getClasses(Statistic.class));
        independenceWrappers.addAll(getClasses(IndependenceWrapper.class));
        scoreWrappers.addAll(getClasses(ScoreWrapper.class));
        simulations.addAll(getClasses(Simulation.class));
        out.println("Available Algorithms:");
        out.println();
        out.println("Algorithms that take an independence test (using an example independence test):");
        out.println();
        for (Class clazz : new ArrayList<>(algorithms)) {
            if (Experimental.class.isAssignableFrom(clazz)) {
                continue;
            }
            Constructor[] constructors = clazz.getConstructors();
            for (Constructor constructor : constructors) {
                if (constructor.getParameterTypes().length == 1 && constructor.getParameterTypes()[0] == IndependenceWrapper.class) {
                    Algorithm algorithm = (Algorithm) constructor.newInstance(FisherZ.class.newInstance());
                    out.println(clazz.getSimpleName() + ": " + algorithm.getDescription());
                    if (HasParameters.class.isAssignableFrom(clazz)) {
                        printParameters(algorithm.getParameters(), allParams, out);
                    }
                    if (TakesInitialGraph.class.isAssignableFrom(clazz)) {
                        out.println("\t" + clazz.getSimpleName() + " can take an initial graph from some other algorithm as input");
                    }
                }
            }
        }
        out.println();
        out.println("Algorithms that take a score (using an example score):");
        out.println();
        for (Class clazz : new ArrayList<>(algorithms)) {
            if (Experimental.class.isAssignableFrom(clazz)) {
                continue;
            }
            Constructor[] constructors = clazz.getConstructors();
            for (Constructor constructor : constructors) {
                if (constructor.getParameterTypes().length == 1 && constructor.getParameterTypes()[0] == ScoreWrapper.class) {
                    Algorithm algorithm = (Algorithm) constructor.newInstance(BdeuScore.class.newInstance());
                    out.println(clazz.getSimpleName() + ": " + algorithm.getDescription());
                    if (HasParameters.class.isAssignableFrom(clazz)) {
                        printParameters(algorithm.getParameters(), allParams, out);
                    }
                }
            }
        }
        out.println();
        out.println("Algorithms with blank constructor:");
        out.println();
        for (Class clazz : new ArrayList<>(algorithms)) {
            if (Experimental.class.isAssignableFrom(clazz)) {
                continue;
            }
            Constructor[] constructors = clazz.getConstructors();
            for (Constructor constructor : constructors) {
                if (constructor.getParameterTypes().length == 0) {
                    Algorithm algorithm = (Algorithm) constructor.newInstance();
                    out.println(clazz.getSimpleName() + ": " + algorithm.getDescription());
                    if (HasParameters.class.isAssignableFrom(clazz)) {
                        printParameters(algorithm.getParameters(), allParams, out);
                    }
                }
            }
        }
        out.println();
        out.println("Available Statistics:");
        out.println();
        for (Class clazz : statistics) {
            if (Experimental.class.isAssignableFrom(clazz)) {
                continue;
            }
            Constructor[] constructors = clazz.getConstructors();
            for (Constructor constructor : constructors) {
                if (constructor.getParameterTypes().length == 0) {
                    Statistic statistic = (Statistic) constructor.newInstance();
                    out.println(clazz.getSimpleName() + ": " + statistic.getDescription());
                }
            }
        }
        out.println();
        out.println("Available Independence Tests:");
        out.println();
        for (Class clazz : independenceWrappers) {
            if (Experimental.class.isAssignableFrom(clazz)) {
                continue;
            }
            Constructor[] constructors = clazz.getConstructors();
            for (Constructor constructor : constructors) {
                if (constructor.getParameterTypes().length == 0) {
                    IndependenceWrapper independence = (IndependenceWrapper) constructor.newInstance();
                    out.println(clazz.getSimpleName() + ": " + independence.getDescription());
                    if (HasParameters.class.isAssignableFrom(clazz)) {
                        printParameters(independence.getParameters(), allParams, out);
                    }
                }
            }
        }
        out.println();
        out.println("Available Scores:");
        out.println();
        for (Class clazz : scoreWrappers) {
            if (Experimental.class.isAssignableFrom(clazz)) {
                continue;
            }
            Constructor[] constructors = clazz.getConstructors();
            for (Constructor constructor : constructors) {
                if (constructor.getParameterTypes().length == 0) {
                    ScoreWrapper score = (ScoreWrapper) constructor.newInstance();
                    out.println(clazz.getSimpleName() + ": " + score.getDescription());
                    if (HasParameters.class.isAssignableFrom(clazz)) {
                        printParameters(score.getParameters(), allParams, out);
                    }
                }
            }
        }
        out.println();
        out.println("Available Simulations:");
        out.println();
        for (Class clazz : simulations) {
            if (Experimental.class.isAssignableFrom(clazz)) {
                continue;
            }
            Constructor[] constructors = clazz.getConstructors();
            for (Constructor constructor : constructors) {
                if (constructor.getParameterTypes().length == 0) {
                    Simulation simulation = (Simulation) constructor.newInstance();
                    out.println(clazz.getSimpleName() + ": " + simulation.getDescription());
                    if (HasParameters.class.isAssignableFrom(clazz)) {
                        printParameters(simulation.getParameters(), allParams, out);
                    }
                }
            }
        }
        out.println();
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : PrintStream(java.io.PrintStream) Parameters(edu.cmu.tetrad.util.Parameters) HasParameters(edu.cmu.tetrad.algcomparison.utils.HasParameters) ScoreWrapper(edu.cmu.tetrad.algcomparison.score.ScoreWrapper) Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList) ExternalAlgorithm(edu.cmu.tetrad.algcomparison.algorithm.ExternalAlgorithm) Algorithm(edu.cmu.tetrad.algcomparison.algorithm.Algorithm) MultiDataSetAlgorithm(edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm) TimeoutException(java.util.concurrent.TimeoutException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) IndependenceWrapper(edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper) Statistic(edu.cmu.tetrad.algcomparison.statistic.Statistic) Simulation(edu.cmu.tetrad.algcomparison.simulation.Simulation) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 3 with IndependenceWrapper

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

the class AlgorithmFactory method create.

public static Algorithm create(Class<? extends Algorithm> algoClass, Class<? extends IndependenceWrapper> indTestClass, Class<? extends ScoreWrapper> scoreClass) throws IllegalAccessException, InstantiationException {
    if (algoClass == null) {
        throw new IllegalArgumentException("Algorithm class cannot be null.");
    }
    IndependenceWrapper test = (indTestClass == null) ? null : indTestClass.newInstance();
    ScoreWrapper score = (scoreClass == null) ? null : scoreClass.newInstance();
    return create(algoClass, test, score);
}
Also used : TakesIndependenceWrapper(edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper) IndependenceWrapper(edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper) ScoreWrapper(edu.cmu.tetrad.algcomparison.score.ScoreWrapper) UsesScoreWrapper(edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper)

Example 4 with IndependenceWrapper

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

the class Comparison method configuration.

/**
 */
public void configuration(String path) {
    try {
        new File(path).mkdirs();
        PrintStream out = new PrintStream(new FileOutputStream(new File(path, "Configuration.txt")));
        Parameters allParams = new Parameters();
        List<Class> algorithms = new ArrayList<>();
        List<Class> statistics = new ArrayList<>();
        List<Class> independenceWrappers = new ArrayList<>();
        List<Class> scoreWrappers = new ArrayList<>();
        List<Class> simulations = new ArrayList<>();
        algorithms.addAll(getClasses(Algorithm.class));
        statistics.addAll(getClasses(Statistic.class));
        independenceWrappers.addAll(getClasses(IndependenceWrapper.class));
        scoreWrappers.addAll(getClasses(ScoreWrapper.class));
        simulations.addAll(getClasses(Simulation.class));
        out.println("Available Algorithms:");
        out.println();
        out.println("Algorithms that take an independence test (using an example independence test):");
        out.println();
        for (Class clazz : new ArrayList<>(algorithms)) {
            if (Experimental.class.isAssignableFrom(clazz)) {
                continue;
            }
            Constructor[] constructors = clazz.getConstructors();
            for (Constructor constructor : constructors) {
                if (constructor.getParameterTypes().length == 1 && constructor.getParameterTypes()[0] == IndependenceWrapper.class) {
                    Algorithm algorithm = (Algorithm) constructor.newInstance(FisherZ.class.newInstance());
                    out.println(clazz.getSimpleName() + ": " + algorithm.getDescription());
                    if (HasParameters.class.isAssignableFrom(clazz)) {
                        printParameters(algorithm.getParameters(), allParams, out);
                    }
                    if (TakesInitialGraph.class.isAssignableFrom(clazz)) {
                        out.println("\t" + clazz.getSimpleName() + " can take an initial graph from some other algorithm as input");
                    }
                }
            }
        }
        out.println();
        out.println("Algorithms that take a score (using an example score):");
        out.println();
        for (Class clazz : new ArrayList<>(algorithms)) {
            if (Experimental.class.isAssignableFrom(clazz)) {
                continue;
            }
            Constructor[] constructors = clazz.getConstructors();
            for (Constructor constructor : constructors) {
                if (constructor.getParameterTypes().length == 1 && constructor.getParameterTypes()[0] == ScoreWrapper.class) {
                    Algorithm algorithm = (Algorithm) constructor.newInstance(BdeuScore.class.newInstance());
                    out.println(clazz.getSimpleName() + ": " + algorithm.getDescription());
                    if (HasParameters.class.isAssignableFrom(clazz)) {
                        printParameters(algorithm.getParameters(), allParams, out);
                    }
                }
            }
        }
        out.println();
        out.println("Algorithms with blank constructor:");
        out.println();
        for (Class clazz : new ArrayList<>(algorithms)) {
            if (Experimental.class.isAssignableFrom(clazz)) {
                continue;
            }
            Constructor[] constructors = clazz.getConstructors();
            for (Constructor constructor : constructors) {
                if (constructor.getParameterTypes().length == 0) {
                    Algorithm algorithm = (Algorithm) constructor.newInstance();
                    out.println(clazz.getSimpleName() + ": " + algorithm.getDescription());
                    if (HasParameters.class.isAssignableFrom(clazz)) {
                        printParameters(algorithm.getParameters(), allParams, out);
                    }
                }
            }
        }
        out.println();
        out.println("Available Statistics:");
        out.println();
        for (Class clazz : statistics) {
            if (Experimental.class.isAssignableFrom(clazz)) {
                continue;
            }
            Constructor[] constructors = clazz.getConstructors();
            for (Constructor constructor : constructors) {
                if (constructor.getParameterTypes().length == 0) {
                    Statistic statistic = (Statistic) constructor.newInstance();
                    out.println(clazz.getSimpleName() + ": " + statistic.getDescription());
                }
            }
        }
        out.println();
        out.println("Available Independence Tests:");
        out.println();
        for (Class clazz : independenceWrappers) {
            if (Experimental.class.isAssignableFrom(clazz)) {
                continue;
            }
            Constructor[] constructors = clazz.getConstructors();
            for (Constructor constructor : constructors) {
                if (constructor.getParameterTypes().length == 0) {
                    IndependenceWrapper independence = (IndependenceWrapper) constructor.newInstance();
                    out.println(clazz.getSimpleName() + ": " + independence.getDescription());
                    if (HasParameters.class.isAssignableFrom(clazz)) {
                        printParameters(independence.getParameters(), allParams, out);
                    }
                }
            }
        }
        out.println();
        out.println("Available Scores:");
        out.println();
        for (Class clazz : scoreWrappers) {
            if (Experimental.class.isAssignableFrom(clazz)) {
                continue;
            }
            Constructor[] constructors = clazz.getConstructors();
            for (Constructor constructor : constructors) {
                if (constructor.getParameterTypes().length == 0) {
                    ScoreWrapper score = (ScoreWrapper) constructor.newInstance();
                    out.println(clazz.getSimpleName() + ": " + score.getDescription());
                    if (HasParameters.class.isAssignableFrom(clazz)) {
                        printParameters(score.getParameters(), allParams, out);
                    }
                }
            }
        }
        out.println();
        out.println("Available Simulations:");
        out.println();
        for (Class clazz : simulations) {
            if (Experimental.class.isAssignableFrom(clazz)) {
                continue;
            }
            Constructor[] constructors = clazz.getConstructors();
            for (Constructor constructor : constructors) {
                if (constructor.getParameterTypes().length == 0) {
                    Simulation simulation = (Simulation) constructor.newInstance();
                    out.println(clazz.getSimpleName() + ": " + simulation.getDescription());
                    if (HasParameters.class.isAssignableFrom(clazz)) {
                        printParameters(simulation.getParameters(), allParams, out);
                    }
                }
            }
        }
        out.println();
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : HasParameters(edu.cmu.tetrad.algcomparison.utils.HasParameters) ScoreWrapper(edu.cmu.tetrad.algcomparison.score.ScoreWrapper) Constructor(java.lang.reflect.Constructor) ExternalAlgorithm(edu.cmu.tetrad.algcomparison.algorithm.ExternalAlgorithm) Algorithm(edu.cmu.tetrad.algcomparison.algorithm.Algorithm) MultiDataSetAlgorithm(edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm) IndependenceWrapper(edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper) Statistic(edu.cmu.tetrad.algcomparison.statistic.Statistic) Simulation(edu.cmu.tetrad.algcomparison.simulation.Simulation)

Example 5 with IndependenceWrapper

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

Aggregations

IndependenceWrapper (edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper)10 Algorithm (edu.cmu.tetrad.algcomparison.algorithm.Algorithm)7 ScoreWrapper (edu.cmu.tetrad.algcomparison.score.ScoreWrapper)7 Parameters (edu.cmu.tetrad.util.Parameters)6 Test (org.junit.Test)5 DataSet (edu.cmu.tetrad.data.DataSet)4 Graph (edu.cmu.tetrad.graph.Graph)4 DagToPag (edu.cmu.tetrad.search.DagToPag)4 GeneralBootstrapTest (edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest)4 FisherZ (edu.cmu.tetrad.algcomparison.independence.FisherZ)3 SemBicTest (edu.cmu.tetrad.algcomparison.independence.SemBicTest)3 Simulation (edu.cmu.tetrad.algcomparison.simulation.Simulation)3 ExternalAlgorithm (edu.cmu.tetrad.algcomparison.algorithm.ExternalAlgorithm)2 MultiDataSetAlgorithm (edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm)2 Fci (edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.Fci)2 Gfci (edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.Gfci)2 RandomForward (edu.cmu.tetrad.algcomparison.graph.RandomForward)2 RandomGraph (edu.cmu.tetrad.algcomparison.graph.RandomGraph)2 ChiSquare (edu.cmu.tetrad.algcomparison.independence.ChiSquare)2 SemBicScore (edu.cmu.tetrad.algcomparison.score.SemBicScore)2