Search in sources :

Example 1 with DataSet

use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.

the class MimbuildEditor method getIndTestParamBox.

/**
 * Factory to return the correct param editor for independence test params.
 * This will go in a little box in the search editor.
 */
private JComponent getIndTestParamBox(Parameters params) {
    if (params == null) {
        throw new NullPointerException();
    }
    if (params instanceof Parameters) {
        MimRunner runner = getMimRunner();
        params.set("varNames", runner.getParams().get("varNames", null));
        DataModel dataModel = runner.getData();
        if (dataModel instanceof DataSet) {
            DataSet data = (DataSet) runner.getData();
            boolean discrete = data.isDiscrete();
            return new BuildPureClustersIndTestParamsEditor2(params, discrete);
        } else if (dataModel instanceof ICovarianceMatrix) {
            return new BuildPureClustersIndTestParamsEditor2(params, false);
        }
    }
    if (params instanceof Parameters) {
        MimRunner runner = getMimRunner();
        params.set("varNames", runner.getParams().get("varNames", null));
        boolean discreteData = false;
        if (runner.getData() instanceof DataSet) {
            discreteData = ((DataSet) runner.getData()).isDiscrete();
        }
        return new PurifyIndTestParamsEditor(params, discreteData);
    }
    if (params instanceof Parameters) {
        MimRunner runner = getMimRunner();
        params.set("varNames", runner.getParams().get("varNames", null));
        return new MimBuildIndTestParamsEditor(params);
    }
    throw new IllegalArgumentException("Unrecognized Parameters: " + params.getClass());
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) DataSet(edu.cmu.tetrad.data.DataSet) DataModel(edu.cmu.tetrad.data.DataModel) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix) MimRunner(edu.cmu.tetradapp.model.MimRunner)

Example 2 with DataSet

use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.

the class PValueImproverEditor method setGraphWorkbench.

private void setGraphWorkbench(final GraphWorkbench graphWorkbench) {
    JTabbedPane tabbedPane = new JTabbedPane();
    this.graphWorkbench = graphWorkbench;
    if (getOriginalSemIm() != null) {
        setOriginalSemIm(new SemIm(getWrapper().getOriginalSemIm()));
    }
    this.newSemIm = getWrapper().getNewSemIm();
    if (getNewSemIm() != null) {
        SemImEditor newEditor = new SemImEditor(new SemImWrapper(getNewSemIm()));
        final GraphWorkbench workbench = newEditor.getWorkbench();
        workbench.addPropertyChangeListener(new PropertyChangeListener() {

            public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
                if ("modelChanged".equals(propertyChangeEvent.getPropertyName())) {
                    System.out.println(propertyChangeEvent);
                    Graph graph = workbench.getGraph();
                    System.out.println(graph);
                    try {
                        new Dag(graph);
                    } catch (IllegalArgumentException e) {
                        return;
                    }
                    Scorer scorer = new DagScorer((DataSet) getWrapper().getDataModel());
                    scorer.score(graph);
                    getWrapper().setNewSemIm(scorer.getEstSem());
                    setGraphWorkbench(graphWorkbench);
                }
            }
        });
        tabbedPane.addTab("New Model", newEditor);
    }
    if (getOriginalSemIm() != null) {
        SemImEditor originalEditor = new SemImEditor(new SemImWrapper(getOriginalSemIm()));
        tabbedPane.addTab("Original Model", originalEditor);
    }
    if (graphWorkbench != null) {
        tabbedPane.addTab("forbid_latent_common_causes", graphWorkbench);
    }
    panel.removeAll();
    panel.add(tabbedPane, BorderLayout.CENTER);
    panel.revalidate();
    panel.repaint();
    firePropertyChange("modelChanged", null, null);
}
Also used : DagScorer(edu.cmu.tetrad.sem.DagScorer) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) DataSet(edu.cmu.tetrad.data.DataSet) Scorer(edu.cmu.tetrad.sem.Scorer) DagScorer(edu.cmu.tetrad.sem.DagScorer) Dag(edu.cmu.tetrad.graph.Dag) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) GraphWorkbench(edu.cmu.tetradapp.workbench.GraphWorkbench) SemImWrapper(edu.cmu.tetradapp.model.SemImWrapper) SemIm(edu.cmu.tetrad.sem.SemIm)

Example 3 with DataSet

use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.

the class LoadTimeSeriesDataAction method loadTimeSeriesDataSet.

/**
 * Method loadDataSet_TabDelim
 */
private void loadTimeSeriesDataSet() {
    // select a file to load using the file chooser
    JFileChooser chooser = getJFileChooser();
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    chooser.showOpenDialog(this.editor);
    // get the file
    File file = chooser.getSelectedFile();
    Preferences.userRoot().put("fileSaveLocation", file.getParent());
    try {
        BufferedReader in = new BufferedReader(new FileReader(file));
        String line;
        StringTokenizer st;
        // read in variable name and set up DataSet.
        List<Node> variables = new LinkedList<>();
        st = new StringTokenizer(in.readLine());
        while (st.hasMoreTokens()) {
            String name = st.nextToken();
            ContinuousVariable var = new ContinuousVariable(name);
            variables.add(var);
        }
        DataSet dataSet = new ColtDataSet(0, variables);
        int row = -1;
        while ((line = in.readLine()) != null) {
            int col = -1;
            st = new StringTokenizer(line);
            while (st.hasMoreTokens()) {
                String literal = st.nextToken();
                if (literal.length() == 0) {
                    continue;
                }
                dataSet.setObject(row, ++col, literal);
            }
        }
        TimeSeriesData dataSet3 = new TimeSeriesData(dataSet.getDoubleData(), dataSet.getVariableNames());
        editor.getDataWrapper().setDataModel(dataSet3);
        firePropertyChange("modelChanged", null, null);
        editor.reset();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) DataSet(edu.cmu.tetrad.data.DataSet) Node(edu.cmu.tetrad.graph.Node) LinkedList(java.util.LinkedList) ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) StringTokenizer(java.util.StringTokenizer) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) TimeSeriesData(edu.cmu.tetrad.data.TimeSeriesData)

Example 4 with DataSet

use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.

the class SemEstimatorEditor method reestimate.

private void reestimate() {
    SemOptimizer optimizer;
    String type = wrapper.getSemOptimizerType();
    switch(type) {
        case "Regression":
            optimizer = new SemOptimizerRegression();
            break;
        case "EM":
            optimizer = new SemOptimizerEm();
            break;
        case "Powell":
            optimizer = new SemOptimizerPowell();
            break;
        case "Random Search":
            optimizer = new SemOptimizerScattershot();
            break;
        case "RICF":
            optimizer = new SemOptimizerRicf();
            break;
        default:
            throw new IllegalArgumentException("Unexpected optimizer type: " + type);
    }
    int numRestarts = wrapper.getNumRestarts();
    optimizer.setNumRestarts(numRestarts);
    java.util.List<SemEstimator> estimators = wrapper.getMultipleResultList();
    java.util.List<SemEstimator> newEstimators = new ArrayList<>();
    estimators.forEach(estimator -> {
        SemPm semPm = estimator.getSemPm();
        DataSet dataSet = estimator.getDataSet();
        ICovarianceMatrix covMatrix = estimator.getCovMatrix();
        SemEstimator newEstimator;
        if (dataSet != null) {
            newEstimator = new SemEstimator(dataSet, semPm, optimizer);
            newEstimator.setNumRestarts(numRestarts);
            newEstimator.setScoreType(wrapper.getScoreType());
        } else if (covMatrix != null) {
            newEstimator = new SemEstimator(covMatrix, semPm, optimizer);
            newEstimator.setNumRestarts(numRestarts);
            newEstimator.setScoreType(wrapper.getScoreType());
        } else {
            throw new IllegalStateException("Only continuous rectangular" + " data sets and covariance matrices can be processed.");
        }
        newEstimator.estimate();
        newEstimators.add(newEstimator);
    });
    wrapper.setSemEstimator(newEstimators.get(0));
    wrapper.setMultipleResultList(newEstimators);
    resetSemImEditor();
}
Also used : SemOptimizerScattershot(edu.cmu.tetrad.sem.SemOptimizerScattershot) SemOptimizerRicf(edu.cmu.tetrad.sem.SemOptimizerRicf) DataSet(edu.cmu.tetrad.data.DataSet) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix) SemOptimizerRegression(edu.cmu.tetrad.sem.SemOptimizerRegression) SemOptimizerEm(edu.cmu.tetrad.sem.SemOptimizerEm) ArrayList(java.util.ArrayList) SemOptimizerPowell(edu.cmu.tetrad.sem.SemOptimizerPowell) SemOptimizer(edu.cmu.tetrad.sem.SemOptimizer) SemPm(edu.cmu.tetrad.sem.SemPm) SemEstimator(edu.cmu.tetrad.sem.SemEstimator)

Example 5 with DataSet

use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.

the class RandomSamplerAction method actionPerformed.

/**
 * Performs the action of loading a session from a file.
 */
public void actionPerformed(ActionEvent e) {
    DataModel dataModel = getDataEditor().getSelectedDataModel();
    if (dataModel instanceof DataSet) {
        DataSet dataSet = (DataSet) dataModel;
        if (dataSet.getNumRows() == 0) {
            JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Data set is empty.");
            return;
        }
        JComponent editor = editor();
        int selection = JOptionPane.showOptionDialog(JOptionUtils.centeringComp(), editor, "Sample Size", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Done", "Cancel" }, "Done");
        if (selection != 0) {
            return;
        }
        try {
            DataSet newDataSet = RandomSampler.sample(dataSet, getSampleSize());
            DataModelList list = new DataModelList();
            list.add(newDataSet);
            getDataEditor().reset(list);
            getDataEditor().selectFirstTab();
        } catch (Exception e1) {
            String s = e1.getMessage();
            if (s == null || "".equals(s)) {
                s = "Could not construct random sample.";
            }
            JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), s);
        }
    } else {
        JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Must be a tabular data set.");
    }
}
Also used : DataSet(edu.cmu.tetrad.data.DataSet) DataModelList(edu.cmu.tetrad.data.DataModelList) DataModel(edu.cmu.tetrad.data.DataModel)

Aggregations

DataSet (edu.cmu.tetrad.data.DataSet)216 Test (org.junit.Test)65 Graph (edu.cmu.tetrad.graph.Graph)64 Node (edu.cmu.tetrad.graph.Node)60 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)48 ArrayList (java.util.ArrayList)45 ColtDataSet (edu.cmu.tetrad.data.ColtDataSet)36 GeneralBootstrapTest (edu.pitt.dbmi.algo.bootstrap.GeneralBootstrapTest)32 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)29 SemIm (edu.cmu.tetrad.sem.SemIm)28 SemPm (edu.cmu.tetrad.sem.SemPm)28 BootstrapEdgeEnsemble (edu.pitt.dbmi.algo.bootstrap.BootstrapEdgeEnsemble)26 DataModel (edu.cmu.tetrad.data.DataModel)22 Parameters (edu.cmu.tetrad.util.Parameters)22 DiscreteVariable (edu.cmu.tetrad.data.DiscreteVariable)20 File (java.io.File)16 ParseException (java.text.ParseException)16 LinkedList (java.util.LinkedList)14 ICovarianceMatrix (edu.cmu.tetrad.data.ICovarianceMatrix)13 DMSearch (edu.cmu.tetrad.search.DMSearch)10