Search in sources :

Example 11 with DoubleTextField

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

the class FciSearchParamEditor 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<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).");
    }
    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);
                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));
    Box b1 = Box.createHorizontalBox();
    b1.add(new JLabel("Knowledge:"));
    b1.add(Box.createGlue());
    add(b1);
    add(Box.createVerticalStrut(10));
    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 : 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 12 with DoubleTextField

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

the class DirichletBayesImParamsEditor 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());
    JRadioButton manualRetain = new JRadioButton();
    JRadioButton randomRetain = new JRadioButton();
    manualRetain.setText("Manually, retaining previous values where possible.");
    randomRetain.setText("Using a symmetric prior for each row of each conditional" + " probability table.");
    ButtonGroup group = new ButtonGroup();
    group.add(manualRetain);
    group.add(randomRetain);
    final DoubleTextField symmetricAlphaField = new DoubleTextField(params.getDouble("symmetricAlpha", 1.0), 5, NumberFormatUtil.getInstance().getNumberFormat());
    symmetricAlphaField.setFilter(new DoubleTextField.Filter() {

        public double filter(double value, double oldValue) {
            try {
                params.set("symmetricAlpha", value);
                return value;
            } catch (IllegalArgumentException e) {
                return oldValue;
            }
        }
    });
    if (getParams().getString("initializationMode", "manualRetain").equals("manualRetain")) {
        manualRetain.setSelected(true);
        symmetricAlphaField.setEnabled(false);
    } else if (getParams().getString("initializationMode", "manualRetain").equals("symmetricPrior")) {
        randomRetain.setSelected(true);
        symmetricAlphaField.setEnabled(true);
    } else {
        throw new IllegalStateException();
    }
    manualRetain.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            getParams().set("initializationMode", "manualRetain");
            symmetricAlphaField.setEnabled(false);
        }
    });
    randomRetain.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            getParams().set("initializationMode", "symmetricPrior");
            symmetricAlphaField.setEnabled(true);
        }
    });
    // continue workbench construction.
    Box b1 = Box.createVerticalBox();
    Box b2 = Box.createHorizontalBox();
    b2.add(new JLabel("Pseudocounts for this Dirichlet Bayes IM should be initialized:"));
    b2.add(Box.createHorizontalGlue());
    Box b3 = Box.createHorizontalBox();
    b3.add(manualRetain);
    b3.add(Box.createHorizontalGlue());
    Box b4 = Box.createHorizontalBox();
    b4.add(randomRetain);
    b4.add(Box.createHorizontalGlue());
    Box b5 = Box.createHorizontalBox();
    b5.add(Box.createRigidArea(new Dimension(30, 0)));
    b5.add(new JLabel("All pseudocounts = "));
    b5.add(symmetricAlphaField);
    b5.add(Box.createHorizontalGlue());
    b1.add(b2);
    b1.add(Box.createVerticalStrut(5));
    b1.add(b3);
    b1.add(b4);
    b1.add(b5);
    b1.add(Box.createHorizontalGlue());
    add(b1, BorderLayout.CENTER);
}
Also used : DoubleTextField(edu.cmu.tetradapp.util.DoubleTextField) ActionEvent(java.awt.event.ActionEvent) ActionListener(java.awt.event.ActionListener)

Example 13 with DoubleTextField

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

the class DirichletEstimatorParamsEditor 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 symmetricAlphaField = new DoubleTextField(params.getDouble("symmetricAlpha", 1.0), 5, NumberFormatUtil.getInstance().getNumberFormat());
    symmetricAlphaField.setFilter(new DoubleTextField.Filter() {

        public double filter(double value, double oldValue) {
            try {
                params.set("symmetricAlpha", value);
                return value;
            } catch (IllegalArgumentException e) {
                return oldValue;
            }
        }
    });
    // continue workbench construction.
    Box b1 = Box.createVerticalBox();
    Box b2 = Box.createHorizontalBox();
    b2.add(new JLabel("<html>" + "If you make a Dirichlet estimator using a Bayes PM and a " + "<br>discrete data set as parents, a Dirichlet Bayes IM will" + "<br>be created behind the scenes for you using the number you" + "<br>provide below as pseudocount for every cell. This Dirichlet" + "<br>Bayes IM will be used as the prior for the estimation. If" + "<br>you would like to have more control over how this prior is" + "<br>created, please remove the PM-->Estimator edge, add a new" + "<br>IM box, connect it as PM-->IM-->Estimator, and create the" + "<br>prior you want as a Dirichlet Bayes IM in the IM box." + "</html>"));
    Box b7 = Box.createHorizontalBox();
    b7.add(Box.createHorizontalGlue());
    b7.add(new JLabel("<html>" + "<i>Estimate using a prior with all pseudocounts =</i>" + "</html>"));
    b7.add(symmetricAlphaField);
    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 14 with DoubleTextField

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

the class RangeEditor method createRangeFields.

/**
 * Creates the range fields, if the editor is not editable then all these fields should
 * be not editable.
 */
private void createRangeFields() {
    this.leftRangeFields = new DoubleTextField[getNumCategories()];
    this.rightRangeFields = new DoubleTextField[getNumCategories()];
    int maxCategory = getNumCategories() - 1;
    this.leftRangeFields[0] = new DoubleTextField(Double.NEGATIVE_INFINITY, 6, NumberFormatUtil.getInstance().getNumberFormat());
    this.leftRangeFields[0].setFilter(new DoubleTextField.Filter() {

        public double filter(double value, double oldValue) {
            return oldValue;
        }
    });
    this.rightRangeFields[maxCategory] = new DoubleTextField(Double.POSITIVE_INFINITY, 6, NumberFormatUtil.getInstance().getNumberFormat());
    this.rightRangeFields[maxCategory].setFilter(new DoubleTextField.Filter() {

        public double filter(double value, double oldValue) {
            return oldValue;
        }
    });
    this.leftRangeFields[0].setEditable(false);
    this.rightRangeFields[maxCategory].setEditable(false);
    this.leftRangeFields[0].setHorizontalAlignment(JTextField.CENTER);
    this.rightRangeFields[maxCategory].setHorizontalAlignment(JTextField.CENTER);
    for (int i = 0; i < getNumCategories() - 1; i++) {
        this.rightRangeFields[i] = new DoubleTextField(breakpoints[i], 6, NumberFormatUtil.getInstance().getNumberFormat());
        this.rightRangeFields[i].setEditable(false);
        labels.put(this.rightRangeFields[i], i);
        this.leftRangeFields[i + 1] = new DoubleTextField(breakpoints[i], 6, NumberFormatUtil.getInstance().getNumberFormat());
        this.leftRangeFields[i + 1].setEditable(this.editableRange);
        this.labels.put(this.leftRangeFields[i + 1], i + 1);
        final Object label = labels.get(this.leftRangeFields[i + 1]);
        this.leftRangeFields[i + 1].setFilter(new DoubleTextField.Filter() {

            public double filter(double value, double oldValue) {
                if (label == null) {
                    return oldValue;
                }
                int index = (Integer) label;
                if (index - 1 > 0 && !(breakpoints[index - 2] < value)) {
                    value = breakpoints[index - 1];
                }
                if (index - 1 < breakpoints.length - 1 && !(value < breakpoints[index])) {
                    value = breakpoints[index - 1];
                }
                breakpoints[index - 1] = value;
                getRightRangeFields()[index - 1].setValue(value);
                return value;
            }
        });
        labels.put(this.leftRangeFields[i + 1], i + 1);
        this.focusTraveralOrder.add(this.leftRangeFields[i + 1]);
    }
}
Also used : DoubleTextField(edu.cmu.tetradapp.util.DoubleTextField)

Example 15 with DoubleTextField

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

the class SemImParamsEditor 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 JCheckBox randomEveryTime = new JCheckBox();
    randomEveryTime.setSelected(!params.getBoolean("retainPreviousValues", false));
    DecimalFormat decimalFormat = new DecimalFormat("0.0######");
    final DoubleTextField coefLowField = new DoubleTextField(params.getDouble("coefLow", 0.5), 6, decimalFormat);
    coefLowField.setFilter(new DoubleTextField.Filter() {

        public double filter(double value, double oldValue) {
            try {
                getParams().set("coefLow", value);
                getParams().set("coefHigh", params.getDouble("coefHigh", 1.5));
                return value;
            } catch (IllegalArgumentException e) {
                return oldValue;
            }
        }
    });
    final DoubleTextField coefHighField = new DoubleTextField(params.getDouble("coefHigh", 1.5), 6, decimalFormat);
    coefHighField.setFilter(new DoubleTextField.Filter() {

        public double filter(double value, double oldValue) {
            try {
                getParams().set("coefLow", params.getDouble("coefLow", 0.5));
                getParams().set("coefHigh", value);
                return value;
            } catch (IllegalArgumentException e) {
                return oldValue;
            }
        }
    });
    final DoubleTextField covLowField = new DoubleTextField(params.getDouble("covLow", 0.1), 6, decimalFormat);
    covLowField.setFilter(new DoubleTextField.Filter() {

        public double filter(double value, double oldValue) {
            try {
                params.set("covLow", value);
                params.set("covHigh", params.getDouble("covHigh", 0.2));
                return value;
            } catch (IllegalArgumentException e) {
                return oldValue;
            }
        }
    });
    final DoubleTextField covHighField = new DoubleTextField(params.getDouble("covHigh", 0.2), 6, decimalFormat);
    covHighField.setFilter(new DoubleTextField.Filter() {

        public double filter(double value, double oldValue) {
            try {
                params.set("covLow", params.getDouble("covLow", 0.1));
                params.set("covHigh", value);
                return value;
            } catch (IllegalArgumentException e) {
                return oldValue;
            }
        }
    });
    final DoubleTextField varLowField = new DoubleTextField(params.getDouble("varLow", 1), 6, decimalFormat);
    varLowField.setFilter(new DoubleTextField.Filter() {

        public double filter(double value, double oldValue) {
            try {
                params.set("varLow", value);
                params.set("varHigh", params.getDouble("varHigh", 3));
                return value;
            } catch (IllegalArgumentException e) {
                return oldValue;
            }
        }
    });
    final DoubleTextField varHighField = new DoubleTextField(params.getDouble("varHigh", 3), 6, decimalFormat);
    varHighField.setFilter(new DoubleTextField.Filter() {

        public double filter(double value, double oldValue) {
            try {
                params.set("varLow", params.getDouble("varLow", 1));
                params.set("varHigh", value);
                return value;
            } catch (IllegalArgumentException e) {
                return oldValue;
            }
        }
    });
    final JCheckBox coefSymmetric = new JCheckBox("Symmetric about zero.");
    final JCheckBox covSymmetric = new JCheckBox("Symmetric about zero.");
    coefSymmetric.setSelected(params.getBoolean("coefSymmetric", true));
    covSymmetric.setSelected(params.getBoolean("covSymmetric", true));
    coefSymmetric.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JCheckBox checkBox = (JCheckBox) e.getSource();
            params.set("coefSymmetric", checkBox.isSelected());
        }
    });
    covSymmetric.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JCheckBox checkBox = (JCheckBox) e.getSource();
            params.set("covSymmetric", checkBox.isSelected());
        }
    });
    randomEveryTime.setText("Pick new random values each time this SEM IM is reinitialized.");
    randomEveryTime.setVerticalTextPosition(SwingConstants.TOP);
    randomEveryTime.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JCheckBox checkBox = (JCheckBox) e.getSource();
            boolean retainPreviousValues = !checkBox.isSelected();
            getParams().set("retainPreviousValues", retainPreviousValues);
        }
    });
    // continue workbench construction.
    Box b1 = Box.createVerticalBox();
    Box b2 = Box.createHorizontalBox();
    b2.add(new JLabel("Unfixed parameter values for this SEM IM are drawn as follows:"));
    b2.add(Box.createHorizontalGlue());
    b1.add(b2);
    b1.add(Box.createVerticalStrut(5));
    Box b4a = Box.createHorizontalBox();
    // b4a.add(Box.createHorizontalStrut(10));
    b4a.add(new JLabel("Coefficient values are drawn from "));
    b4a.add(new BigLabel("("));
    b4a.add(coefLowField);
    b4a.add(new BigLabel(", "));
    b4a.add(coefHighField);
    b4a.add(new BigLabel(") "));
    b4a.add(coefSymmetric);
    b4a.add(Box.createHorizontalGlue());
    b1.add(b4a);
    Box b4b = Box.createHorizontalBox();
    // b4b.add(Box.createHorizontalStrut(10));
    b4b.add(new JLabel("Error covariance values are drawn from "));
    b4b.add(new BigLabel("("));
    b4b.add(covLowField);
    b4b.add(new BigLabel(", "));
    b4b.add(covHighField);
    b4b.add(new BigLabel(") "));
    b4b.add(covSymmetric);
    b4b.add(Box.createHorizontalGlue());
    b1.add(b4b);
    Box b4c = Box.createHorizontalBox();
    // b4c.add(Box.createHorizontalStrut(10));
    b4c.add(new JLabel("Error standard deviation values are drawn from "));
    b4c.add(new BigLabel("("));
    b4c.add(varLowField);
    b4c.add(new BigLabel(", "));
    b4c.add(varHighField);
    b4c.add(new BigLabel(")"));
    b4c.add(new JLabel("."));
    b4c.add(Box.createHorizontalGlue());
    b1.add(b4c);
    Box b5 = Box.createHorizontalBox();
    // b5.add(Box.createHorizontalStrut(10));
    b5.add(randomEveryTime);
    b5.add(Box.createHorizontalGlue());
    b1.add(b5);
    b1.add(Box.createHorizontalGlue());
    add(b1, BorderLayout.CENTER);
    setBorder(new EmptyBorder(5, 5, 5, 5));
}
Also used : DoubleTextField(edu.cmu.tetradapp.util.DoubleTextField) ActionEvent(java.awt.event.ActionEvent) DecimalFormat(java.text.DecimalFormat) ActionListener(java.awt.event.ActionListener) EmptyBorder(javax.swing.border.EmptyBorder)

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