Search in sources :

Example 16 with Comparison

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

the class TestGenerateMixedData method test1.

public void test1() {
    Parameters parameters = new Parameters();
    parameters.set("numRuns", 100);
    parameters.set("numMeasures", 100);
    parameters.set("avgDegree", 4);
    parameters.set("sampleSize", 5000);
    parameters.set("maxDegree", 8);
    parameters.set("minCategories", 2);
    parameters.set("maxCategories", 5);
    parameters.set("percentDiscrete", 50);
    parameters.set("intervalBetweenRecordings", 20);
    parameters.set("varLow", 1.);
    parameters.set("varHigh", 3.);
    parameters.set("coefLow", .1);
    parameters.set("coefHigh", 1.5);
    parameters.set("coefSymmetric", true);
    parameters.set("meanLow", -1);
    parameters.set("meanHigh", 1);
    final LeeHastieSimulation simulation = new LeeHastieSimulation(new RandomForward());
    Comparison comparison = new Comparison();
    comparison.setShowAlgorithmIndices(true);
    comparison.setShowSimulationIndices(false);
    comparison.setSortByUtility(false);
    comparison.setShowUtilities(false);
    comparison.setParallelized(false);
    comparison.setSaveGraphs(true);
    comparison.setTabDelimitedTables(true);
    comparison.saveToFiles("mixed.lee.hastie.avg.degree.4", simulation, parameters);
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) LeeHastieSimulation(edu.cmu.tetrad.algcomparison.simulation.LeeHastieSimulation) Comparison(edu.cmu.tetrad.algcomparison.Comparison) RandomForward(edu.cmu.tetrad.algcomparison.graph.RandomForward)

Example 17 with Comparison

use of edu.cmu.tetrad.algcomparison.Comparison 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 18 with Comparison

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

the class SimulationEditor method getFileMenu.

private void getFileMenu(final JMenu fileMenu, final Simulation simulation, final GraphSelectionEditor graphEditor, final DataEditor dataEditor, final JTabbedPane tabbedPane, final String[] simulationItems) {
    JMenuItem loadSimulation = new JMenuItem("Load Simulation");
    JMenuItem saveSimulation = new JMenuItem("Save Simulation");
    loadSimulation.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser();
            String sessionSaveLocation = Preferences.userRoot().get("fileSaveLocation", "");
            chooser.setCurrentDirectory(new File(sessionSaveLocation));
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int ret1 = chooser.showOpenDialog(JOptionUtils.centeringComp());
            if (!(ret1 == JFileChooser.APPROVE_OPTION)) {
                return;
            }
            File file = chooser.getSelectedFile();
            if (file == null) {
                return;
            }
            // Check to make sure the directory has the right structure.
            File[] files = file.listFiles();
            if (files == null) {
                JOptionPane.showMessageDialog((SimulationEditor.this), "That wasn't a directory");
                return;
            }
            boolean correctStructure = isCorrectStructure(files);
            if (!correctStructure) {
                int count = 0;
                File thisOne = null;
                for (File _file : files) {
                    File[] _files = _file.listFiles();
                    if (_files == null) {
                        continue;
                    }
                    if (isCorrectStructure(_files)) {
                        count++;
                        thisOne = _file;
                    }
                }
                if (thisOne == null) {
                    JOptionPane.showMessageDialog((SimulationEditor.this), "That file was not a simulation, and none of its subdirectories was either. " + "\nNeed a directory with a 'data' subdirectory, a 'graph' subdirectory, " + "\nand a 'parameters.txt' file.");
                    return;
                }
                if (count > 1) {
                    JOptionPane.showMessageDialog((SimulationEditor.this), "More than one subdirectory of that directory was a simulation; please select " + "\none of the subdirectories.");
                    return;
                }
                file = thisOne;
            }
            edu.cmu.tetrad.algcomparison.simulation.Simulation _simulation = new LoadContinuousDataAndGraphs(file.getPath());
            _simulation.createData(simulation.getParams());
            if (_simulation.getNumDataModels() > 0) {
                Graph trueGraph = _simulation.getTrueGraph(0);
                edu.cmu.tetrad.graph.GraphUtils.circleLayout(trueGraph, 225, 200, 150);
                List<Graph> graphs = new ArrayList<>();
                for (int i = 0; i < _simulation.getNumDataModels(); i++) {
                    graphs.add(_simulation.getTrueGraph(i));
                }
                graphEditor.replace(graphs);
                DataWrapper wrapper = new DataWrapper(new Parameters());
                DataModelList list = new DataModelList();
                for (int i = 0; i < _simulation.getNumDataModels(); i++) {
                    list.add(_simulation.getDataModel(i));
                }
                wrapper.setDataModelList(list);
                tabbedPane.setComponentAt(2, new DataEditor(wrapper, false, JTabbedPane.LEFT));
            }
            String graphPref = null;
            String simPref = null;
            if (_simulation.getParameters().contains("graphsDropdownPreference")) {
                graphPref = (String) simulation.getParams().get("graphsDropdownPreference");
            }
            if (_simulation.getParameters().contains("simulationsDropdownPreference")) {
                simPref = (String) simulation.getParams().get("simulationsDropdownPreference");
            }
            if (graphPref != null) {
                graphsDropdown.setSelectedItem(graphPref);
                System.out.println("Set pre-loaded Graph: " + graphPref);
            }
            if (simPref != null) {
                simulationsDropdown.setSelectedItem(simPref);
                System.out.println("Set pre-loaded sim: " + simPref);
            }
            simulation.setSimulation(_simulation, simulation.getParams());
            resetPanel(simulation, graphItems, simulationItems, tabbedPane);
        }

        private boolean isCorrectStructure(File[] files) {
            boolean hasDataDir = false;
            boolean hasGraphDir = false;
            boolean hasParametersFile = false;
            for (File _file : files) {
                if (_file.isDirectory() && _file.getName().equals("data")) {
                    hasDataDir = true;
                }
                if (_file.isDirectory() && _file.getName().equals("graph")) {
                    hasGraphDir = true;
                }
                if (_file.isFile() && _file.getName().equals("parameters.txt")) {
                    hasParametersFile = true;
                }
            }
            return hasDataDir && hasGraphDir && hasParametersFile;
        }
    });
    saveSimulation.addActionListener((e) -> {
        JFileChooser chooser = new JFileChooser();
        String sessionSaveLocation = Preferences.userRoot().get("fileSaveLocation", "");
        chooser.setCurrentDirectory(new File(sessionSaveLocation));
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        int ret1 = chooser.showSaveDialog(JOptionUtils.centeringComp());
        if (!(ret1 == JFileChooser.APPROVE_OPTION)) {
            return;
        }
        final File selectedFile = chooser.getSelectedFile();
        if (selectedFile == null) {
            return;
        }
        // if (file.listFiles().length != 0) {
        // JOptionPane.showMessageDialog((SimulationEditor.this),
        // "That wasn't a a new or empty directory; try typing a name for the directory\n" +
        // "or creating an empty directory.");
        // return;
        // }
        new Comparison().saveToFiles(selectedFile.getAbsolutePath(), simulation.getSimulation(), simulation.getParams());
        Preferences.userRoot().put("fileSaveLocation", selectedFile.getParent());
    });
    fileMenu.addSeparator();
    fileMenu.add(loadSimulation);
    fileMenu.add(saveSimulation);
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) ActionEvent(java.awt.event.ActionEvent) LoadContinuousDataAndGraphs(edu.cmu.tetrad.algcomparison.simulation.LoadContinuousDataAndGraphs) DataWrapper(edu.cmu.tetradapp.model.DataWrapper) RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph) SingleGraph(edu.cmu.tetrad.algcomparison.graph.SingleGraph) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) TimeSeriesSemSimulation(edu.cmu.tetrad.algcomparison.simulation.TimeSeriesSemSimulation) GeneralSemSimulation(edu.cmu.tetrad.algcomparison.simulation.GeneralSemSimulation) SemSimulation(edu.cmu.tetrad.algcomparison.simulation.SemSimulation) ConditionalGaussianSimulation(edu.cmu.tetrad.algcomparison.simulation.ConditionalGaussianSimulation) StandardizedSemSimulation(edu.cmu.tetrad.algcomparison.simulation.StandardizedSemSimulation) BooleanGlassSimulation(edu.cmu.tetrad.algcomparison.simulation.BooleanGlassSimulation) Simulation(edu.cmu.tetradapp.model.Simulation) LeeHastieSimulation(edu.cmu.tetrad.algcomparison.simulation.LeeHastieSimulation) BayesNetSimulation(edu.cmu.tetrad.algcomparison.simulation.BayesNetSimulation) DataModelList(edu.cmu.tetrad.data.DataModelList) Comparison(edu.cmu.tetrad.algcomparison.Comparison) List(java.util.List) ArrayList(java.util.ArrayList) DataModelList(edu.cmu.tetrad.data.DataModelList) JMenuItem(javax.swing.JMenuItem) File(java.io.File)

Example 19 with Comparison

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

the class ExampleNonlinearSave method main.

public static void main(String... args) {
    Parameters parameters = new Parameters();
    parameters.set("numRuns", 100);
    parameters.set("numMeasures", 20);
    parameters.set("avgDegree", 3);
    parameters.set("sampleSize", 500);
    parameters.set("percentDiscrete", 0);
    parameters.set("minCategories", 2);
    parameters.set("maxCategories", 5);
    parameters.set("differentGraphs", true);
    parameters.set("interceptLow", 0);
    parameters.set("interceptHigh", 1);
    parameters.set("contiuousInfluence", 0.5);
    parameters.set("linearLow", 0.5);
    parameters.set("linearHigh", 1.0);
    parameters.set("quadraticLow", 0.5);
    parameters.set("quadraticHigh", 1.0);
    parameters.set("cubicLow", 0.2);
    parameters.set("cubicHigh", 0.3);
    parameters.set("varLow", 1);
    parameters.set("varHigh", 1);
    parameters.set("betaLow", 5);
    parameters.set("betaHigh", 8);
    parameters.set("gammaLow", 1.0);
    parameters.set("gammaHigh", 1.5);
    Simulation simulation = new LinearSineSimulation(new RandomForward());
    Comparison comparison = new Comparison();
    comparison.setShowAlgorithmIndices(true);
    comparison.saveToFiles("comparison", simulation, parameters);
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) Comparison(edu.cmu.tetrad.algcomparison.Comparison) RandomForward(edu.cmu.tetrad.algcomparison.graph.RandomForward)

Example 20 with Comparison

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

the class CompareExternalAlgorithms method main.

public static void main(String... args) {
    Parameters parameters = new Parameters();
    parameters.set("numRuns", 10);
    Statistics statistics = new Statistics();
    statistics.add(new ParameterColumn("numMeasures"));
    statistics.add(new ParameterColumn("avgDegree"));
    statistics.add(new ParameterColumn("sampleSize"));
    statistics.add(new AdjacencyPrecision());
    statistics.add(new AdjacencyRecall());
    statistics.add(new ArrowheadPrecision());
    statistics.add(new ArrowheadRecall());
    statistics.add(new F1Adj());
    statistics.add(new F1Arrow());
    statistics.add(new F1All());
    statistics.add(new ElapsedTime());
    statistics.setWeight("AP", 1.0);
    statistics.setWeight("AR", 0.5);
    statistics.setWeight("AHP", 1.0);
    statistics.setWeight("AHR", 0.5);
    Algorithms algorithms = new Algorithms();
    algorithms.add(new ExternalAlgorithmTetrad("PC_(\"Peter_and_Clark\"),_Priority_Rule,_using_Fisher_Z_test,_alpha_=_0.001"));
    algorithms.add(new ExternalAlgorithmPcalgPc("PC_pcalg_defaults_alpha_=_0.001"));
    algorithms.add(new ExternalAlgorithmBNTPc("learn_struct_pdag_pc_alpha_=_0.001"));
    Comparison comparison = new Comparison();
    comparison.setShowAlgorithmIndices(true);
    comparison.setShowSimulationIndices(true);
    comparison.setSortByUtility(false);
    comparison.setShowUtilities(false);
    comparison.setParallelized(false);
    comparison.generateReportFromExternalAlgorithms("/Users/user/comparison-data/condition_1", "/Users/user/causal-comparisons/condition_1", algorithms, statistics, parameters);
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) Algorithms(edu.cmu.tetrad.algcomparison.algorithm.Algorithms) Comparison(edu.cmu.tetrad.algcomparison.Comparison) ExternalAlgorithmBNTPc(edu.cmu.tetrad.algcomparison.algorithm.external.ExternalAlgorithmBNTPc) ExternalAlgorithmPcalgPc(edu.cmu.tetrad.algcomparison.algorithm.external.ExternalAlgorithmPcalgPc) ExternalAlgorithmTetrad(edu.cmu.tetrad.algcomparison.algorithm.external.ExternalAlgorithmTetrad)

Aggregations

Comparison (edu.cmu.tetrad.algcomparison.Comparison)30 Parameters (edu.cmu.tetrad.util.Parameters)30 Algorithms (edu.cmu.tetrad.algcomparison.algorithm.Algorithms)24 Simulations (edu.cmu.tetrad.algcomparison.simulation.Simulations)16 RandomForward (edu.cmu.tetrad.algcomparison.graph.RandomForward)14 SemBicScore (edu.cmu.tetrad.algcomparison.score.SemBicScore)11 SemSimulation (edu.cmu.tetrad.algcomparison.simulation.SemSimulation)6 Fges (edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.Fges)5 FisherZ (edu.cmu.tetrad.algcomparison.independence.FisherZ)5 LinearFisherModel (edu.cmu.tetrad.algcomparison.simulation.LinearFisherModel)4 LeeHastieSimulation (edu.cmu.tetrad.algcomparison.simulation.LeeHastieSimulation)3 Simulation (edu.cmu.tetrad.algcomparison.simulation.Simulation)3 FirstInflection (edu.cmu.tetrad.algcomparison.algorithm.FirstInflection)2 ConditionalGaussianSimulation (edu.cmu.tetrad.algcomparison.simulation.ConditionalGaussianSimulation)2 TimeSeriesSemSimulation (edu.cmu.tetrad.algcomparison.simulation.TimeSeriesSemSimulation)2 Algorithm (edu.cmu.tetrad.algcomparison.algorithm.Algorithm)1 StARS (edu.cmu.tetrad.algcomparison.algorithm.StARS)1 StabilitySelection (edu.cmu.tetrad.algcomparison.algorithm.StabilitySelection)1 ExternalAlgorithmBNTPc (edu.cmu.tetrad.algcomparison.algorithm.external.ExternalAlgorithmBNTPc)1 ExternalAlgorithmPcalgPc (edu.cmu.tetrad.algcomparison.algorithm.external.ExternalAlgorithmPcalgPc)1