Search in sources :

Example 11 with DataWrapper

use of edu.cmu.tetradapp.model.DataWrapper in project tetrad by cmu-phil.

the class LoadDataAction method isDataEmpty.

// ======================= private methods =========================//
/**
 * States whether the data is empty.
 */
private boolean isDataEmpty() {
    DataWrapper wrapper = this.dataEditor.getDataWrapper();
    DataModelList dataModels = wrapper.getDataModelList();
    for (DataModel model : dataModels) {
        if (model instanceof DataSet) {
            return ((DataSet) model).getNumRows() == 0;
        } else {
            // how do you know in this case? Just say false
            return false;
        }
    }
    return true;
}
Also used : DataWrapper(edu.cmu.tetradapp.model.DataWrapper) DataModelList(edu.cmu.tetrad.data.DataModelList) DataSet(edu.cmu.tetrad.data.DataSet) DataModel(edu.cmu.tetrad.data.DataModel)

Example 12 with DataWrapper

use of edu.cmu.tetradapp.model.DataWrapper in project tetrad by cmu-phil.

the class LogisticRegressionParamsPanel method getVarsFromData.

private List<String> getVarsFromData(Object[] parentModels) {
    DataModel dataModel = null;
    for (Object parentModel : parentModels) {
        if (parentModel instanceof DataWrapper) {
            DataWrapper dataWrapper = (DataWrapper) parentModel;
            dataModel = dataWrapper.getSelectedDataModel();
        }
    }
    if (dataModel == null) {
        return null;
    } else {
        return new ArrayList<>(dataModel.getVariableNames());
    }
}
Also used : DataWrapper(edu.cmu.tetradapp.model.DataWrapper) DataModel(edu.cmu.tetrad.data.DataModel) ArrayList(java.util.ArrayList)

Example 13 with DataWrapper

use of edu.cmu.tetradapp.model.DataWrapper in project tetrad by cmu-phil.

the class MbSearchParamEditor method getVarsFromData.

private List<String> getVarsFromData(Object[] parentModels) {
    DataModel dataModel = null;
    for (Object parentModel : parentModels) {
        if (parentModel instanceof DataWrapper) {
            DataWrapper dataWrapper = (DataWrapper) parentModel;
            dataModel = dataWrapper.getSelectedDataModel();
        } else if (parentModel instanceof IndependenceFactsModel) {
            dataModel = ((IndependenceFactsModel) parentModel).getFacts();
        }
    }
    if (dataModel == null) {
        return null;
    } else {
        return new ArrayList<>(dataModel.getVariableNames());
    }
}
Also used : DataWrapper(edu.cmu.tetradapp.model.DataWrapper) DataModel(edu.cmu.tetrad.data.DataModel) IndependenceFactsModel(edu.cmu.tetradapp.model.IndependenceFactsModel) ArrayList(java.util.ArrayList)

Example 14 with DataWrapper

use of edu.cmu.tetradapp.model.DataWrapper in project tetrad by cmu-phil.

the class ShiftDataParamsEditor method setup.

/**
 * Builds the panel.
 */
public void setup() {
    DataModelList dataModelList = null;
    for (Object parentModel : parentModels) {
        if (parentModel instanceof DataWrapper) {
            DataWrapper dataWrapper = (DataWrapper) parentModel;
            dataModelList = dataWrapper.getDataModelList();
        }
    }
    if (dataModelList == null) {
        throw new NullPointerException("Null data model list.");
    }
    for (DataModel model : dataModelList) {
        if (!(model instanceof DataSet)) {
            JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "For the shift search, all of the data in the data box must be in the form of data sets.");
            return;
        }
    }
    final List<DataModel> dataSets = new ArrayList<>();
    for (Object aDataModelList : dataModelList) {
        dataSets.add((DataSet) aDataModelList);
    }
    SpinnerModel maxVarsModel = new SpinnerNumberModel(Preferences.userRoot().getInt("shiftSearchMaxNumShifts", 3), 1, 50, 1);
    JSpinner maxVarsSpinner = new JSpinner(maxVarsModel);
    maxVarsSpinner.setMaximumSize(maxVarsSpinner.getPreferredSize());
    maxVarsSpinner.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            JSpinner spinner = (JSpinner) e.getSource();
            SpinnerNumberModel model = (SpinnerNumberModel) spinner.getModel();
            int value = (Integer) model.getValue();
            Preferences.userRoot().putInt("shiftSearchMaxNumShifts", value);
        }
    });
    SpinnerModel maxShiftModel = new SpinnerNumberModel(Preferences.userRoot().getInt("shiftSearchMaxShift", 2), 1, 50, 1);
    JSpinner maxShiftSpinner = new JSpinner(maxShiftModel);
    maxShiftSpinner.setMaximumSize(maxShiftSpinner.getPreferredSize());
    maxShiftSpinner.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            JSpinner spinner = (JSpinner) e.getSource();
            SpinnerNumberModel model = (SpinnerNumberModel) spinner.getModel();
            int value = (Integer) model.getValue();
            Preferences.userRoot().putInt("shiftSearchMaxShift", value);
        }
    });
    JButton searchButton = new JButton("Search");
    final JButton stopButton = new JButton("Stop");
    final JTextArea textArea = new JTextArea();
    JScrollPane textScroll = new JScrollPane(textArea);
    textScroll.setPreferredSize(new Dimension(500, 200));
    searchButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent actionEvent) {
            final Thread thread = new Thread() {

                public void run() {
                    textArea.setText("");
                    doShiftSearch(dataSets, textArea);
                }
            };
            thread.start();
        }
    });
    stopButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent actionEvent) {
            if (search != null) {
                search.stop();
                TaskManager.getInstance().setCanceled(true);
            }
        }
    });
    JComboBox directionBox = new JComboBox(new String[] { "forward", "backward" });
    directionBox.setSelectedItem(params.getBoolean("forwardSearch", true) ? "forward" : "backward");
    directionBox.setMaximumSize(directionBox.getPreferredSize());
    directionBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent actionEvent) {
            JComboBox source = (JComboBox) actionEvent.getSource();
            String selected = (String) source.getSelectedItem();
            params.set("forwardSearch", "forward".equals(selected));
        }
    });
    Box b1 = Box.createVerticalBox();
    Box b2 = Box.createHorizontalBox();
    b2.add(new JLabel("Maximum number of variables in shift set is: "));
    b2.add(maxVarsSpinner);
    b2.add(Box.createHorizontalGlue());
    b1.add(b2);
    Box b3 = Box.createHorizontalBox();
    b3.add(new JLabel("Maximum "));
    b3.add(directionBox);
    b3.add(new JLabel(" shift: "));
    b3.add(maxShiftSpinner);
    b3.add(Box.createHorizontalGlue());
    b1.add(b3);
    Box b4 = Box.createHorizontalBox();
    b4.add(new JLabel("Output:"));
    b4.add(Box.createHorizontalGlue());
    b1.add(b4);
    Box b5 = Box.createHorizontalBox();
    b5.add(textScroll);
    b1.add(b5);
    Box b6 = Box.createHorizontalBox();
    b6.add(searchButton);
    b6.add(stopButton);
    b1.add(b6);
    final Box a1 = Box.createVerticalBox();
    Box a2 = Box.createHorizontalBox();
    a2.add(new JLabel("Specify the shift (positive or negative) for each variable:"));
    a2.add(Box.createHorizontalGlue());
    a1.add(a2);
    a1.add(Box.createVerticalStrut(20));
    setUpA1(dataSets, a1);
    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab("Shift", new JScrollPane(a1));
    tabbedPane.addTab("Search", new JScrollPane(b1));
    add(tabbedPane, BorderLayout.CENTER);
    tabbedPane.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent changeEvent) {
            System.out.println("a1 shown");
            a1.removeAll();
            setUpA1(dataSets, a1);
        }
    });
}
Also used : DataSet(edu.cmu.tetrad.data.DataSet) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) DataWrapper(edu.cmu.tetradapp.model.DataWrapper) DataModelList(edu.cmu.tetrad.data.DataModelList) ChangeListener(javax.swing.event.ChangeListener) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener) DataModel(edu.cmu.tetrad.data.DataModel)

Example 15 with DataWrapper

use of edu.cmu.tetradapp.model.DataWrapper in project tetrad by cmu-phil.

the class SplitCasesParamsEditor method setParentModels.

public void setParentModels(Object[] parentModels) {
    if (parentModels == null || parentModels.length == 0) {
        throw new IllegalArgumentException("There must be parent model");
    }
    DataWrapper data = null;
    for (Object parent : parentModels) {
        if (parent instanceof DataWrapper) {
            data = (DataWrapper) parent;
        }
    }
    if (data == null) {
        throw new IllegalArgumentException("Should have have a data wrapper as a parent");
    }
    DataModel model = data.getSelectedDataModel();
    if (!(model instanceof DataSet)) {
        throw new IllegalArgumentException("The data must be tabular");
    }
    this.dataSet = (DataSet) model;
}
Also used : DataWrapper(edu.cmu.tetradapp.model.DataWrapper) DataSet(edu.cmu.tetrad.data.DataSet) DataModel(edu.cmu.tetrad.data.DataModel)

Aggregations

DataWrapper (edu.cmu.tetradapp.model.DataWrapper)16 DataModel (edu.cmu.tetrad.data.DataModel)13 ArrayList (java.util.ArrayList)10 DataSet (edu.cmu.tetrad.data.DataSet)7 Graph (edu.cmu.tetrad.graph.Graph)4 DoubleTextField (edu.cmu.tetradapp.util.DoubleTextField)4 List (java.util.List)4 DataModelList (edu.cmu.tetrad.data.DataModelList)3 Node (edu.cmu.tetrad.graph.Node)3 DagWrapper (edu.cmu.tetradapp.model.DagWrapper)3 GraphWrapper (edu.cmu.tetradapp.model.GraphWrapper)3 SemGraphWrapper (edu.cmu.tetradapp.model.SemGraphWrapper)3 IntTextField (edu.cmu.tetradapp.util.IntTextField)3 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 Iterator (java.util.Iterator)3 MatteBorder (javax.swing.border.MatteBorder)3 ICovarianceMatrix (edu.cmu.tetrad.data.ICovarianceMatrix)2 Parameters (edu.cmu.tetrad.util.Parameters)2 Comparison (edu.cmu.tetrad.algcomparison.Comparison)1