Search in sources :

Example 21 with DoubleTextField

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

the class StructEMBayesSearchParamsEditor method setup.

/**
 * Constructs the Gui used to edit properties; called from each constructor.
 * Constructs labels and text fields for editing each property and adds
 * appropriate listeners.
 */
public void setup() {
    setLayout(new BorderLayout());
    final DoubleTextField toleranceField = new DoubleTextField(params.getDouble("tolerance", 0.0001), 8, NumberFormatUtil.getInstance().getNumberFormat());
    toleranceField.setFilter(new DoubleTextField.Filter() {

        public double filter(double value, double oldValue) {
            try {
                params.set("tolerance", 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 dataset will be used to iteratively estmate models (Bayes nets) " + "<br>using the BDe metric until the model does not change from one " + "<br>iteration to the next.  " + "</html>"));
    Box b7 = Box.createHorizontalBox();
    b7.add(Box.createHorizontalGlue());
    b7.add(new JLabel("<html>" + "<i>The default value is 0.0001</i>" + "</html>"));
    b7.add(toleranceField);
    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 22 with DoubleTextField

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

the class SearchParamEditor method setup.

public void setup() {
    /*
      The variable names from the object being searched over (usually data).
     */
    List varNames = (List<String>) params.get("varNames", null);
    DataModel dataModel1 = null;
    Graph graph = null;
    for (Object parentModel1 : 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 it = graph.getNodes().iterator();
        varNames = new ArrayList();
        Node temp;
        while (it.hasNext()) {
            temp = (Node) 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).");
    }
    params.set("varNames", varNames);
    IntTextField depthField = new IntTextField(params.getInt("depth", -1), 4);
    depthField.setFilter(new IntTextField.Filter() {

        public int filter(int value, int oldValue) {
            try {
                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 {
                    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 b0 = Box.createHorizontalBox();
        b0.add(new JLabel("Alpha Value:"));
        b0.add(Box.createGlue());
        b0.add(alphaField);
        add(b0);
        add(Box.createVerticalStrut(10));
    }
    Box b1 = Box.createHorizontalBox();
    b1.add(new JLabel("Search Depth:"));
    b1.add(Box.createGlue());
    b1.add(depthField);
    add(b1);
    add(Box.createVerticalStrut(10));
}
Also used : DoubleTextField(edu.cmu.tetradapp.util.DoubleTextField) Node(edu.cmu.tetrad.graph.Node) SemGraphWrapper(edu.cmu.tetradapp.model.SemGraphWrapper) GraphWrapper(edu.cmu.tetradapp.model.GraphWrapper) ArrayList(java.util.ArrayList) DataWrapper(edu.cmu.tetradapp.model.DataWrapper) DagWrapper(edu.cmu.tetradapp.model.DagWrapper) MatteBorder(javax.swing.border.MatteBorder) Graph(edu.cmu.tetrad.graph.Graph) DataModel(edu.cmu.tetrad.data.DataModel) IntTextField(edu.cmu.tetradapp.util.IntTextField) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) SemGraphWrapper(edu.cmu.tetradapp.model.SemGraphWrapper)

Example 23 with DoubleTextField

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

the class GlassoSearchEditor method getIndTestParamBox.

private JComponent getIndTestParamBox() {
    final Parameters params = getAlgorithmRunner().getParams();
    IntTextField maxItField = new IntTextField((int) params.get("maxit", 10000), 6);
    maxItField.setFilter(new IntTextField.Filter() {

        public int filter(int value, int oldValue) {
            try {
                params.set("maxit", value);
                return value;
            } catch (Exception e) {
                return oldValue;
            }
        }
    });
    DoubleTextField thrField = new DoubleTextField(params.getDouble("thr", 1e-4), 8, new DecimalFormat("0.0########"), new DecimalFormat("0.00E00"), 1e-4);
    thrField.setFilter(new DoubleTextField.Filter() {

        public double filter(double value, double oldValue) {
            try {
                params.set("thr", value);
                return value;
            } catch (Exception e) {
                return oldValue;
            }
        }
    });
    JCheckBox iaCheckBox = new JCheckBox("Meinhausen-Buhlman");
    iaCheckBox.setSelected(params.getBoolean("ia", false));
    iaCheckBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            JCheckBox checkBox = (JCheckBox) actionEvent.getSource();
            params.set("is", checkBox.isSelected());
        }
    });
    JCheckBox isCheckBox = new JCheckBox("Warm start");
    isCheckBox.setSelected(params.getBoolean("ia", false));
    isCheckBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            JCheckBox checkBox = (JCheckBox) actionEvent.getSource();
            params.set("is", checkBox.isSelected());
        }
    });
    JCheckBox itrCheckBox = new JCheckBox("Log trace");
    itrCheckBox.setSelected(params.getBoolean("ia", false));
    itrCheckBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            JCheckBox checkBox = (JCheckBox) actionEvent.getSource();
            params.set("itr", checkBox.isSelected());
        }
    });
    JCheckBox ipenCheckBox = new JCheckBox("Penalize diagonal");
    ipenCheckBox.setSelected(params.getBoolean("ipen", false));
    ipenCheckBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            JCheckBox checkBox = (JCheckBox) actionEvent.getSource();
            params.set("ipen", checkBox.isSelected());
        }
    });
    Box b = Box.createVerticalBox();
    Box b1 = Box.createHorizontalBox();
    b1.add(new JLabel("Max iterations"));
    b1.add(Box.createHorizontalGlue());
    b1.add(maxItField);
    b.add(b1);
    Box b2 = Box.createHorizontalBox();
    b2.add(new JLabel("Threshold"));
    b2.add(Box.createHorizontalGlue());
    b2.add(thrField);
    b.add(b2);
    Box b3 = Box.createHorizontalBox();
    b3.add(iaCheckBox);
    b3.add(Box.createHorizontalGlue());
    b.add(b3);
    Box b4 = Box.createHorizontalBox();
    b4.add(isCheckBox);
    b4.add(Box.createHorizontalGlue());
    b.add(b4);
    Box b5 = Box.createHorizontalBox();
    b5.add(itrCheckBox);
    b5.add(Box.createHorizontalGlue());
    b.add(b5);
    Box b6 = Box.createHorizontalBox();
    b6.add(ipenCheckBox);
    b6.add(Box.createHorizontalGlue());
    b.add(b6);
    return b;
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) DoubleTextField(edu.cmu.tetradapp.util.DoubleTextField) ActionEvent(java.awt.event.ActionEvent) DecimalFormat(java.text.DecimalFormat) ActionListener(java.awt.event.ActionListener) IntTextField(edu.cmu.tetradapp.util.IntTextField)

Example 24 with DoubleTextField

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

the class GeneralizedSemImParamsEditor method initialValuesPane.

private JComponent initialValuesPane() {
    Box b = Box.createVerticalBox();
    java.util.List<String> parameters = new ArrayList<>(semPm().getParameters());
    Collections.sort(parameters);
    // Need to keep these in a particular order.
    class MyTextField extends DoubleTextField {

        private String parameter;

        public MyTextField(String parameter, double value, int width, NumberFormat format) {
            super(value, width, format);
            this.parameter = parameter;
        }

        public String getParameter() {
            return this.parameter;
        }
    }
    List<String> _parameters = new ArrayList(semPm.getParameters());
    Collections.sort(_parameters);
    for (String parameter : _parameters) {
        final String _parameter = parameter;
        Box c = Box.createHorizontalBox();
        c.add(new JLabel(parameter + " = "));
        final MyTextField field = new MyTextField(parameter, semIm.getParameterValue(parameter), 8, NumberFormatUtil.getInstance().getNumberFormat());
        field.setFilter(new DoubleTextField.Filter() {

            public double filter(double value, double oldValue) {
                semIm.setParameterValue(_parameter, value);
                return value;
            }
        });
        c.add(field);
        c.add(Box.createHorizontalGlue());
        b.add(c);
        b.add(Box.createVerticalStrut(5));
    }
    b.setBorder(new EmptyBorder(5, 5, 5, 5));
    return b;
}
Also used : DoubleTextField(edu.cmu.tetradapp.util.DoubleTextField) ArrayList(java.util.ArrayList) EmptyBorder(javax.swing.border.EmptyBorder) NumberFormat(java.text.NumberFormat)

Example 25 with DoubleTextField

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

the class EMBayesEstimatorParamsEditor method setup.

/**
 * Constructs the Gui used to edit properties; called from each constructor.
 * Constructs labels and text fields for editing each property and adds
 * appropriate listeners.
 */
public void setup() {
    setLayout(new BorderLayout());
    final DoubleTextField toleranceField = new DoubleTextField(params.getDouble("tolerance", 0.0001), 8, NumberFormatUtil.getInstance().getNumberFormat());
    toleranceField.setFilter(new DoubleTextField.Filter() {

        public double filter(double value, double oldValue) {
            try {
                params.set("tolerance", 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 dataset will be used to iteratively estmate the parameters " + "<br>of a Bayes IM until the distance between the vectors of parameters" + "<br>of successive iterates is less than a tolerance set by the user" + "</html>"));
    Box b7 = Box.createHorizontalBox();
    b7.add(Box.createHorizontalGlue());
    b7.add(new JLabel("<html>" + "<i>The default value is 0.0001</i>" + "</html>"));
    b7.add(toleranceField);
    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)

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