Search in sources :

Example 6 with DataModelList

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

the class MissingDataInjectorAction 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;
        JComponent editor = editor();
        int selection = JOptionPane.showOptionDialog(JOptionUtils.centeringComp(), editor, "Probability", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Done", "Cancel" }, "Done");
        if (selection != 0) {
            return;
        }
        int numVars = dataSet.getNumColumns();
        double prob = getProb();
        double[] probs = new double[numVars];
        for (int i = 0; i < probs.length; i++) {
            probs[i] = prob;
        }
        DataSet newDataSet = DataUtils.addMissingData(dataSet, probs);
        DataModelList list = new DataModelList();
        list.add(newDataSet);
        getDataEditor().reset(list);
        getDataEditor().selectFirstTab();
    } 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)

Example 7 with DataModelList

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

the class MergeDatasetsWrapper method construct.

private void construct(DataWrapper... dataWrappers) {
    for (DataWrapper wrapper : dataWrappers) {
        if (wrapper == null) {
            throw new NullPointerException("The given data must not be null");
        }
    }
    DataModelList merged = new DataModelList();
    for (DataWrapper wrapper : dataWrappers) {
        merged.addAll(wrapper.getDataModelList());
    }
    this.setDataModel(merged);
    LogDataUtils.logDataModelList("Parent data in which constant columns have been removed.", getDataModelList());
}
Also used : DataModelList(edu.cmu.tetrad.data.DataModelList)

Example 8 with DataModelList

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

the class TestDataWrapper method testDataModelList.

@Test
public void testDataModelList() {
    DataModelList modelList = new DataModelList();
    List<Node> variables1 = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        variables1.add(new ContinuousVariable("X" + i));
    }
    List<Node> variables2 = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        variables2.add(new ContinuousVariable("X" + i));
    }
    DataSet first = new ColtDataSet(10, variables1);
    first.setName("first");
    DataSet second = new ColtDataSet(10, variables2);
    second.setName("second");
    modelList.add(first);
    modelList.add(second);
    assertTrue(modelList.contains(first));
    assertTrue(modelList.contains(second));
    modelList.setSelectedModel(second);
    try {
        DataModelList modelList2 = new MarshalledObject<>(modelList).get();
        assertEquals("second", modelList2.getSelectedModel().getName());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ContinuousVariable(edu.cmu.tetrad.data.ContinuousVariable) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) DataModelList(edu.cmu.tetrad.data.DataModelList) ColtDataSet(edu.cmu.tetrad.data.ColtDataSet) DataSet(edu.cmu.tetrad.data.DataSet) Node(edu.cmu.tetrad.graph.Node) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 9 with DataModelList

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

the class SubsetDiscreteVariablesAction method actionPerformed.

/**
 * Performs the action of loading a session from a file.
 */
public void actionPerformed(ActionEvent e) {
    DataModel selectedDataModel = getDataEditor().getSelectedDataModel();
    if (selectedDataModel instanceof DataSet) {
        DataSet dataSet = (DataSet) selectedDataModel;
        for (int i = dataSet.getNumColumns(); i >= 0; i--) {
            if (dataSet.getVariable(i) instanceof DiscreteVariable) {
                dataSet.removeColumn(i);
            }
        }
        DataModelList list = new DataModelList();
        list.add(dataSet);
        getDataEditor().reset(list);
        getDataEditor().selectFirstTab();
    } else {
        JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Requires a tabular data set.");
    }
}
Also used : DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable) DataSet(edu.cmu.tetrad.data.DataSet) DataModelList(edu.cmu.tetrad.data.DataModelList) DataModel(edu.cmu.tetrad.data.DataModel)

Example 10 with DataModelList

use of edu.cmu.tetrad.data.DataModelList 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)

Aggregations

DataModelList (edu.cmu.tetrad.data.DataModelList)11 DataSet (edu.cmu.tetrad.data.DataSet)7 DataModel (edu.cmu.tetrad.data.DataModel)6 DataWrapper (edu.cmu.tetradapp.model.DataWrapper)3 ArrayList (java.util.ArrayList)3 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 File (java.io.File)2 List (java.util.List)2 Comparison (edu.cmu.tetrad.algcomparison.Comparison)1 RandomGraph (edu.cmu.tetrad.algcomparison.graph.RandomGraph)1 SingleGraph (edu.cmu.tetrad.algcomparison.graph.SingleGraph)1 BayesNetSimulation (edu.cmu.tetrad.algcomparison.simulation.BayesNetSimulation)1 BooleanGlassSimulation (edu.cmu.tetrad.algcomparison.simulation.BooleanGlassSimulation)1 ConditionalGaussianSimulation (edu.cmu.tetrad.algcomparison.simulation.ConditionalGaussianSimulation)1 GeneralSemSimulation (edu.cmu.tetrad.algcomparison.simulation.GeneralSemSimulation)1 LeeHastieSimulation (edu.cmu.tetrad.algcomparison.simulation.LeeHastieSimulation)1 LoadContinuousDataAndGraphs (edu.cmu.tetrad.algcomparison.simulation.LoadContinuousDataAndGraphs)1 SemSimulation (edu.cmu.tetrad.algcomparison.simulation.SemSimulation)1