Search in sources :

Example 1 with ScoreWrapper

use of edu.cmu.tetrad.algcomparison.score.ScoreWrapper in project tetrad by cmu-phil.

the class TestFges method main.

public static void main(String... args) {
    if (args.length > 0) {
        int numMeasures = Integer.parseInt(args[0]);
        int avgDegree = Integer.parseInt(args[1]);
        Parameters parameters = new Parameters();
        parameters.set("numMeasures", numMeasures);
        parameters.set("numLatents", 0);
        parameters.set("avgDegree", avgDegree);
        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", 1000);
        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);
        ScoreWrapper score = new FisherZScore();
        Algorithm alg = new edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.Fges(score);
        parameters.set("alpha", 1e-8);
        for (int i = 0; i < 5; i++) {
            Graph out1 = alg.search(sim.getDataModel(0), parameters);
            System.out.println(out1);
        }
    } else {
        new TestFges().test9();
    }
}
Also used : FisherZScore(edu.cmu.tetrad.algcomparison.score.FisherZScore) 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) RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph)

Example 2 with ScoreWrapper

use of edu.cmu.tetrad.algcomparison.score.ScoreWrapper 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 3 with ScoreWrapper

use of edu.cmu.tetrad.algcomparison.score.ScoreWrapper 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 4 with ScoreWrapper

use of edu.cmu.tetrad.algcomparison.score.ScoreWrapper 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 5 with ScoreWrapper

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

Aggregations

ScoreWrapper (edu.cmu.tetrad.algcomparison.score.ScoreWrapper)10 Algorithm (edu.cmu.tetrad.algcomparison.algorithm.Algorithm)8 IndependenceWrapper (edu.cmu.tetrad.algcomparison.independence.IndependenceWrapper)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 GeneralBootstrapTest (edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest)4 Fges (edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.Fges)3 SemBicScore (edu.cmu.tetrad.algcomparison.score.SemBicScore)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 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 FisherZ (edu.cmu.tetrad.algcomparison.independence.FisherZ)2 SemBicTest (edu.cmu.tetrad.algcomparison.independence.SemBicTest)2 BdeuScore (edu.cmu.tetrad.algcomparison.score.BdeuScore)2 LinearFisherModel (edu.cmu.tetrad.algcomparison.simulation.LinearFisherModel)2