Search in sources :

Example 21 with DataModel

use of edu.cmu.tetrad.data.DataModel 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 22 with DataModel

use of edu.cmu.tetrad.data.DataModel 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 23 with DataModel

use of edu.cmu.tetrad.data.DataModel 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 24 with DataModel

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

the class MimSearchEditor 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 BuildPureClustersIndTestParamsEditor(params, discrete);
        } else if (dataModel instanceof ICovarianceMatrix) {
            return new BuildPureClustersIndTestParamsEditor(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 IndTestParams: " + 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 25 with DataModel

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

Aggregations

DataModel (edu.cmu.tetrad.data.DataModel)39 DataSet (edu.cmu.tetrad.data.DataSet)22 ArrayList (java.util.ArrayList)15 DataWrapper (edu.cmu.tetradapp.model.DataWrapper)13 Graph (edu.cmu.tetrad.graph.Graph)9 ICovarianceMatrix (edu.cmu.tetrad.data.ICovarianceMatrix)8 Parameters (edu.cmu.tetrad.util.Parameters)8 DataModelList (edu.cmu.tetrad.data.DataModelList)7 Node (edu.cmu.tetrad.graph.Node)7 ActionEvent (java.awt.event.ActionEvent)7 ActionListener (java.awt.event.ActionListener)7 List (java.util.List)5 LayoutMenu (edu.cmu.tetradapp.workbench.LayoutMenu)4 DoubleTextField (edu.cmu.tetradapp.util.DoubleTextField)3 WatchedProcess (edu.cmu.tetradapp.util.WatchedProcess)3 GraphWorkbench (edu.cmu.tetradapp.workbench.GraphWorkbench)3 IOException (java.io.IOException)3 Algorithm (edu.cmu.tetrad.algcomparison.algorithm.Algorithm)2 MultiDataSetAlgorithm (edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm)2 BdeuScore (edu.cmu.tetrad.algcomparison.score.BdeuScore)2