/** * Adds a new double parameter to be altered for the model being tuned. * * @param param the model parameter * @param initialSearchValues the values to try for the specified parameter */ public void addParameter(DoubleParameter param, double... initialSearchValues) { if (param == null) throw new IllegalArgumentException("null not allowed for parameter"); searchParams.add(param); DoubleList dl = new DoubleList(initialSearchValues.length); for (double d : initialSearchValues) dl.add(d); Arrays.sort(dl.getBackingArray()); // convience, only really needed if param is warm if (param.isWarmParameter() && !param.preferredLowToHigh()) Collections.reverse(dl); // put it in the prefered order if (param.isWarmParameter()) // put it at the front! searchValues.add(0, dl); else searchValues.add(dl); }
/** * Sets the parameters according to the given array * * @param setTo the index corresponds to the parameters, and the value which parameter value to * use. */ private void setParameters(int[] setTo) { for (int i = 0; i < setTo.length; i++) { Parameter param = searchParams.get(i); if (param instanceof DoubleParameter) ((DoubleParameter) param).setValue(searchValues.get(i).get(setTo[i])); else if (param instanceof IntParameter) ((IntParameter) param).setValue(searchValues.get(i).get(setTo[i]).intValue()); } }
// Construct GUI for a set of parameters public static void makeControls( Container controls, GridBagLayout controlLayout, GridBagConstraints controlCon, Vector dpList, Vector optList, String title) { Container spec = new Container(); controlLayout.setConstraints(spec, controlCon); controls.add(spec); GridBagLayout layout = new GridBagLayout(); GridBagConstraints con = new GridBagConstraints(); spec.setLayout(layout); Iterator i = dpList.iterator(); while (i.hasNext()) { DoubleParameter dp = (DoubleParameter) (i.next()); // Make slider and text field JSlider val = new JSlider(JSlider.HORIZONTAL); JTextField tval = new JTextField(5); dp.register(val); dp.register(tval); // Lay out label, slider, text field con.fill = GridBagConstraints.NONE; con.weightx = 0.0; con.weighty = 0.0; con.gridwidth = 1; JLabel name = new JLabel(dp.name); layout.setConstraints(name, con); spec.add(name); con.fill = GridBagConstraints.HORIZONTAL; con.weightx = 0.8; layout.setConstraints(val, con); spec.add(val); con.weightx = 0.2; con.gridwidth = GridBagConstraints.REMAINDER; layout.setConstraints(tval, con); spec.add(tval); } // Label column on bottom con.fill = GridBagConstraints.VERTICAL; con.anchor = GridBagConstraints.SOUTH; con.weightx = 0.0; con.weighty = 1.0; con.gridwidth = GridBagConstraints.REMAINDER; JLabel ltitle = new JLabel(title); layout.setConstraints(ltitle, con); spec.add(ltitle); // Display options con.anchor = GridBagConstraints.WEST; i = optList.iterator(); while (i.hasNext()) { BooleanParameter bp = (BooleanParameter) (i.next()); JCheckBox ck = new JCheckBox(bp.name); bp.register(ck); layout.setConstraints(ck, con); spec.add(ck); } }