Search in sources :

Example 6 with DoubleTextField

use of edu.cmu.tetradapp.util.DoubleTextField in project tetrad by cmu-phil.

the class PurifyParamsEditor 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(params.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);
        }
    });
    boolean discreteModel = setVarNames(parentModels, params);
    editClusters = new JButton("Edit");
    editClusters.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            openClusterEditor();
        }
    });
    Box b = Box.createVerticalBox();
    Box b1 = Box.createHorizontalBox();
    b1.add(new JLabel("Alpha:"));
    b1.add(Box.createHorizontalGlue());
    b1.add(alphaField);
    b.add(b1);
    Box b2 = Box.createHorizontalBox();
    b2.add(new JLabel("search_for_structure_over_latents Assignments:"));
    b2.add(Box.createHorizontalGlue());
    b2.add(editClusters);
    b.add(b2);
    if (!discreteModel) {
        Box b3 = Box.createHorizontalBox();
        b3.add(new JLabel("Statistical Test:"));
        b3.add(Box.createHorizontalGlue());
        b3.add(testSelector);
        b.add(b3);
    } else {
        this.params.set("tetradTestType", TestType.DISCRETE_LRT);
    }
    setLayout(new BorderLayout());
    add(b, BorderLayout.CENTER);
}
Also used : DoubleTextField(edu.cmu.tetradapp.util.DoubleTextField) ActionEvent(java.awt.event.ActionEvent) TestType(edu.cmu.tetrad.search.TestType) ActionListener(java.awt.event.ActionListener)

Example 7 with DoubleTextField

use of edu.cmu.tetradapp.util.DoubleTextField in project tetrad by cmu-phil.

the class MissingDataInjectorParamsEditor method buildGui.

// ======================== Private Methods ====================================//
/**
 * Constructs the Gui used to edit properties; called from each constructor.
 * Constructs labels and text fields for editing each property and adds
 * appropriate listeners.
 */
private void buildGui() {
    setLayout(new BorderLayout());
    final DoubleTextField probField = new DoubleTextField(params.getDouble("prob", 0.02), 6, NumberFormatUtil.getInstance().getNumberFormat());
    probField.setFilter(new DoubleTextField.Filter() {

        public double filter(double value, double oldValue) {
            try {
                params.set("prob", value);
                return value;
            } catch (IllegalArgumentException e) {
                return oldValue;
            }
        }
    });
    // continue workbench construction.
    Box b1 = Box.createVerticalBox();
    Box b2 = Box.createHorizontalBox();
    b2.add(new JLabel("<html>" + "The input dataset will have missing data values inserted " + "<br>independently for each variable in each case with the" + "<br>probability specified." + "</html>"));
    Box b7 = Box.createHorizontalBox();
    b7.add(Box.createHorizontalGlue());
    b7.add(new JLabel("<html>" + "<i>Probability:  </i>" + "</html>"));
    b7.add(probField);
    b1.add(b2);
    b1.add(Box.createVerticalStrut(5));
    b1.add(b7);
    b1.add(Box.createHorizontalGlue());
    add(b1, BorderLayout.CENTER);
}
Also used : DoubleTextField(edu.cmu.tetradapp.util.DoubleTextField)

Example 8 with DoubleTextField

use of edu.cmu.tetradapp.util.DoubleTextField in project tetrad by cmu-phil.

the class MarkovBlanketSearchEditor method getParamEditor.

/**
 * Creates the param editor.
 */
private JComponent getParamEditor() {
    Box box = Box.createVerticalBox();
    JComboBox comboBox = new JComboBox(this.algorithmRunner.getSource().getVariableNames().toArray());
    comboBox.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            String s = (String) e.getItem();
            if (s != null) {
                algorithmRunner.getParams().set("targetName", s);
            }
        }
    });
    DoubleTextField alphaField = new DoubleTextField(getParams().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);
                Preferences.userRoot().putDouble("alpha", getParams().getDouble("alpha", 0.001));
                return value;
            } catch (Exception e) {
                return oldValue;
            }
        }
    });
    box.add(comboBox);
    box.add(Box.createVerticalStrut(4));
    box.add(createLabeledComponent("Alpha", alphaField));
    box.setBorder(new TitledBorder("Parameters"));
    return box;
}
Also used : DoubleTextField(edu.cmu.tetradapp.util.DoubleTextField) TitledBorder(javax.swing.border.TitledBorder)

Example 9 with DoubleTextField

use of edu.cmu.tetradapp.util.DoubleTextField 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 10 with DoubleTextField

use of edu.cmu.tetradapp.util.DoubleTextField 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)

Aggregations

DoubleTextField (edu.cmu.tetradapp.util.DoubleTextField)26 ActionEvent (java.awt.event.ActionEvent)10 ActionListener (java.awt.event.ActionListener)10 DecimalFormat (java.text.DecimalFormat)7 IntTextField (edu.cmu.tetradapp.util.IntTextField)6 ArrayList (java.util.ArrayList)6 Parameters (edu.cmu.tetrad.util.Parameters)5 DataModel (edu.cmu.tetrad.data.DataModel)4 Node (edu.cmu.tetrad.graph.Node)4 DataWrapper (edu.cmu.tetradapp.model.DataWrapper)4 List (java.util.List)4 EmptyBorder (javax.swing.border.EmptyBorder)4 MatteBorder (javax.swing.border.MatteBorder)4 TitledBorder (javax.swing.border.TitledBorder)4 DataSet (edu.cmu.tetrad.data.DataSet)3 Graph (edu.cmu.tetrad.graph.Graph)3 DagWrapper (edu.cmu.tetradapp.model.DagWrapper)3 GraphWrapper (edu.cmu.tetradapp.model.GraphWrapper)3 SemGraphWrapper (edu.cmu.tetradapp.model.SemGraphWrapper)3 Iterator (java.util.Iterator)3