Search in sources :

Example 1 with DataWrapper

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

the class RegressionParamsPanel 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 2 with DataWrapper

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

the class PurifyParamsEditor method setVarNames.

private boolean setVarNames(Object[] parentModels, Parameters params) {
    DataModel dataModel = null;
    for (Object parentModel : parentModels) {
        if (parentModel instanceof DataWrapper) {
            DataWrapper dataWrapper = (DataWrapper) parentModel;
            dataModel = dataWrapper.getSelectedDataModel();
        }
    }
    boolean discreteModel;
    if (dataModel instanceof ICovarianceMatrix) {
        discreteModel = false;
    } else {
        DataSet dataSet = (DataSet) dataModel;
        assert dataSet != null;
        discreteModel = dataSet.isDiscrete();
    // try {
    // new DataSet((DataSet) dataModel);
    // discreteModel = true;
    // }
    // catch (IllegalArgumentException e) {
    // discreteModel = false;
    // }
    }
    getParams().set("varNames", params.get("varNames", null));
    return discreteModel;
}
Also used : DataWrapper(edu.cmu.tetradapp.model.DataWrapper) DataSet(edu.cmu.tetrad.data.DataSet) DataModel(edu.cmu.tetrad.data.DataModel) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix)

Example 3 with DataWrapper

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

the class PcSearchParamEditor method setup.

public void setup() {
    /*
      The variable names from the object being searched over (usually data).
     */
    List<String> varNames = (List<String>) params.get("varNames", null);
    DataModel dataModel1 = null;
    Graph graph = null;
    for (Object parentModel1 : this.parentModels) {
        if (parentModel1 instanceof DataWrapper) {
            DataWrapper dataWrapper = (DataWrapper) parentModel1;
            dataModel1 = dataWrapper.getSelectedDataModel();
        }
        if (parentModel1 instanceof GraphWrapper) {
            GraphWrapper graphWrapper = (GraphWrapper) parentModel1;
            graph = graphWrapper.getGraph();
        }
        if (parentModel1 instanceof DagWrapper) {
            DagWrapper dagWrapper = (DagWrapper) parentModel1;
            graph = dagWrapper.getDag();
        }
        if (parentModel1 instanceof SemGraphWrapper) {
            SemGraphWrapper semGraphWrapper = (SemGraphWrapper) parentModel1;
            graph = semGraphWrapper.getGraph();
        }
    }
    if (dataModel1 != null) {
        varNames = new ArrayList<>(dataModel1.getVariableNames());
    } else if (graph != null) {
        Iterator<Node> it = graph.getNodes().iterator();
        varNames = new ArrayList();
        Node temp;
        while (it.hasNext()) {
            temp = it.next();
            if (temp.getNodeType() == NodeType.MEASURED) {
                varNames.add(temp.getName());
            }
        }
    } else {
        throw new NullPointerException("Null model (no graph or data model " + "passed to the search).");
    }
    this.params.set("varNames", varNames);
    IntTextField depthField = new IntTextField(this.params.getInt("depth", -1), 4);
    depthField.setFilter(new IntTextField.Filter() {

        public int filter(int value, int oldValue) {
            try {
                PcSearchParamEditor.this.params.set("depth", value);
                Preferences.userRoot().putInt("depth", value);
                return value;
            } catch (Exception e) {
                return oldValue;
            }
        }
    });
    double alpha = params.getDouble("alpha", 0.001);
    if (!Double.isNaN(alpha)) {
        alphaField = new DoubleTextField(alpha, 4, NumberFormatUtil.getInstance().getNumberFormat());
        alphaField.setFilter(new DoubleTextField.Filter() {

            public double filter(double value, double oldValue) {
                try {
                    PcSearchParamEditor.this.params.set("alpha", 0.001);
                    Preferences.userRoot().putDouble("alpha", value);
                    return value;
                } catch (Exception e) {
                    return oldValue;
                }
            }
        });
    }
    setBorder(new MatteBorder(10, 10, 10, 10, super.getBackground()));
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    if (!Double.isNaN(alpha)) {
        Box b2 = Box.createHorizontalBox();
        b2.add(new JLabel("Alpha Value:"));
        b2.add(Box.createGlue());
        b2.add(alphaField);
        add(b2);
        add(Box.createVerticalStrut(10));
    }
    Box b3 = Box.createHorizontalBox();
    b3.add(new JLabel("Search Depth:"));
    b3.add(Box.createGlue());
    b3.add(depthField);
    add(b3);
    add(Box.createVerticalStrut(10));
}
Also used : Node(edu.cmu.tetrad.graph.Node) ArrayList(java.util.ArrayList) DataWrapper(edu.cmu.tetradapp.model.DataWrapper) DagWrapper(edu.cmu.tetradapp.model.DagWrapper) MatteBorder(javax.swing.border.MatteBorder) IntTextField(edu.cmu.tetradapp.util.IntTextField) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) SemGraphWrapper(edu.cmu.tetradapp.model.SemGraphWrapper) DoubleTextField(edu.cmu.tetradapp.util.DoubleTextField) SemGraphWrapper(edu.cmu.tetradapp.model.SemGraphWrapper) GraphWrapper(edu.cmu.tetradapp.model.GraphWrapper) Graph(edu.cmu.tetrad.graph.Graph) DataModel(edu.cmu.tetrad.data.DataModel)

Example 4 with DataWrapper

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

the class BuildPureClustersParamsEditor method setup.

public void setup() {
    DoubleTextField alphaField = new DoubleTextField(params.getDouble("alpha", 0.001), 4, NumberFormatUtil.getInstance().getNumberFormat());
    alphaField.setFilter(new DoubleTextField.Filter() {

        public double filter(double value, double oldValue) {
            try {
                getParams().set("alpha", 0.001);
                return value;
            } catch (Exception e) {
                return oldValue;
            }
        }
    });
    final TestType[] descriptions = TestType.getTestDescriptions();
    JComboBox testSelector = new JComboBox(descriptions);
    testSelector.setSelectedItem(getParams().get("tetradTestType", TestType.TETRAD_WISHART));
    testSelector.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JComboBox combo = (JComboBox) e.getSource();
            TestType testType = (TestType) combo.getSelectedItem();
            getParams().set("tetradTestType", testType);
        }
    });
    final TestType[] purifyDescriptions = TestType.getPurifyTestDescriptions();
    JComboBox purifySelector = new JComboBox(purifyDescriptions);
    purifySelector.setSelectedItem(getParams().get("purifyTestType", TestType.NONE));
    purifySelector.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JComboBox combo = (JComboBox) e.getSource();
            TestType testType = (TestType) combo.getSelectedItem();
            getParams().set("purifyTestType", testType);
        }
    });
    // Where is it setting the appropriate knowledge for the search?
    DataModel dataModel = null;
    for (Object parentModel : this.parentModels) {
        if (parentModel instanceof DataWrapper) {
            DataWrapper dataWrapper = (DataWrapper) parentModel;
            dataModel = dataWrapper.getSelectedDataModel();
        }
    }
    if (dataModel == null) {
        throw new IllegalStateException("Null data model.");
    }
    List<String> varNames = new ArrayList<>(dataModel.getVariableNames());
    boolean isDiscreteModel;
    if (dataModel instanceof ICovarianceMatrix) {
        isDiscreteModel = false;
    } else {
        DataSet dataSet = (DataSet) dataModel;
        isDiscreteModel = dataSet.isDiscrete();
    // try {
    // new DataSet((DataSet) dataModel);
    // isDiscreteModel = true;
    // }
    // catch (IllegalArgumentException e) {
    // isDiscreteModel = false;
    // }
    }
    params.set("varNames", varNames);
    alphaField.setValue(params.getDouble("alpha", 0.001));
    Box b = Box.createVerticalBox();
    Box b1 = Box.createHorizontalBox();
    b1.add(new JLabel("Alpha:"));
    b1.add(Box.createHorizontalGlue());
    b1.add(alphaField);
    b.add(b1);
    if (!isDiscreteModel) {
        Box b2 = Box.createHorizontalBox();
        b2.add(new JLabel("Statistical Test:"));
        b2.add(Box.createHorizontalGlue());
        b2.add(testSelector);
        b.add(b2);
        Box b3 = Box.createHorizontalBox();
        b3.add(new JLabel("Purify Test:"));
        b3.add(Box.createHorizontalGlue());
        b3.add(purifySelector);
        b.add(b3);
    } else {
        this.params.set("purifyTestType", TestType.DISCRETE_LRT);
        this.params.set("tetradTestType", TestType.DISCRETE);
    }
    setLayout(new BorderLayout());
    add(b, BorderLayout.CENTER);
}
Also used : DoubleTextField(edu.cmu.tetradapp.util.DoubleTextField) DataSet(edu.cmu.tetrad.data.DataSet) ActionEvent(java.awt.event.ActionEvent) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix) ArrayList(java.util.ArrayList) TestType(edu.cmu.tetrad.search.TestType) DataWrapper(edu.cmu.tetradapp.model.DataWrapper) ActionListener(java.awt.event.ActionListener) DataModel(edu.cmu.tetrad.data.DataModel)

Example 5 with DataWrapper

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

the class CalculatorEditor method setParentModels.

/**
 * Grabs the data set that the calculator is working on.
 */
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