use of edu.cmu.tetradapp.util.DoubleTextField in project tetrad by cmu-phil.
the class MissingDataInjectorAction method editor.
private JComponent editor() {
JPanel editor = new JPanel();
editor.setLayout(new BorderLayout());
final DoubleTextField probField = new DoubleTextField(getProb(), 6, NumberFormatUtil.getInstance().getNumberFormat());
probField.setFilter(new DoubleTextField.Filter() {
public double filter(double value, double oldValue) {
try {
setProb(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());
editor.add(b1, BorderLayout.CENTER);
return editor;
}
use of edu.cmu.tetradapp.util.DoubleTextField in project tetrad by cmu-phil.
the class ParameterPanel method getDoubleField.
private DoubleTextField getDoubleField(final String parameter, final Parameters parameters, double defaultValue, final double lowerBound, final double upperBound) {
final DoubleTextField field = new DoubleTextField(parameters.getDouble(parameter, defaultValue), 8, new DecimalFormat("0.####"), new DecimalFormat("0.0#E0"), 0.001);
field.setFilter(new DoubleTextField.Filter() {
public double filter(double value, double oldValue) {
if (value == field.getValue()) {
return oldValue;
}
if (value < lowerBound) {
return oldValue;
}
if (value > upperBound) {
return oldValue;
}
try {
parameters.set(parameter, value);
} catch (Exception e) {
// Ignore.
}
return value;
}
});
return field;
}
use of edu.cmu.tetradapp.util.DoubleTextField in project tetrad by cmu-phil.
the class LofsSearchEditorNew method getToolbar.
/**
* Construct the toolbar panel.
*/
protected JPanel getToolbar() {
final Parameters searchParams = getAlgorithmRunner().getParams();
strongerDirection = new JCheckBox("Stronger Direction");
strongerDirection.setSelected(searchParams.getBoolean("orientStrongerDirection", true));
strongerDirection.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
JCheckBox button = (JCheckBox) actionEvent.getSource();
searchParams.set("orientStrongerDirection", button.isSelected());
}
});
selfLoopStrength = new DoubleTextField(searchParams.getDouble("selfLoopStrength", 0.0), 5, new DecimalFormat("0.0#####"));
selfLoopStrength.setFilter(new DoubleTextField.Filter() {
public double filter(double value, double oldValue) {
searchParams.set("selfLoopStrength", value);
return value;
}
});
// selfLoopStrength.setSelected(searchParams.isMeanCenterResiduals());
selfLoopStrength.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
JCheckBox checkBox = (JCheckBox) actionEvent.getSource();
searchParams.set("meanCenterResiduals", checkBox.isSelected());
}
});
JCheckBox orient2cycles = new JCheckBox("D");
orient2cycles.setSelected(searchParams.getBoolean("r2Orient2Cycles", false));
orient2cycles.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
JCheckBox checkBox = (JCheckBox) actionEvent.getSource();
searchParams.set("r2Orient2Cycles", checkBox.isSelected());
}
});
epsilon = new DoubleTextField(searchParams.getDouble("epsilon", .1), 5, new DecimalFormat("0.0#####"));
epsilon.setFilter(new DoubleTextField.Filter() {
public double filter(double value, double oldValue) {
searchParams.set("epsilon", value);
return value;
}
});
zeta = new DoubleTextField(searchParams.getDouble("zeta", 1), 5, new DecimalFormat("0.0#####"));
zeta.setFilter(new DoubleTextField.Filter() {
public double filter(double value, double oldValue) {
searchParams.set("dataSet", value);
return value;
}
});
label1 = new JLabel("Cutoff = ");
label2 = new JLabel("Range = ");
JPanel toolbar = new JPanel();
getExecuteButton().setText("Execute*");
getExecuteButton().addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
execute();
}
});
JComboBox rulebox = new JComboBox();
rulebox.addItem("R1");
rulebox.addItem("R2");
rulebox.addItem("R3");
rulebox.addItem("R4");
rulebox.addItem("EB");
rulebox.addItem("Tanh");
rulebox.addItem("Skew");
rulebox.addItem("SkewE");
rulebox.addItem("RSkew");
rulebox.addItem("RSkewE");
rulebox.addItem("Patel");
// rulebox.addItem("IGCI");
// rulebox.addItem("RC");
// rulebox.addItem("Nlo");
Lofs2.Rule _rule = (Lofs2.Rule) searchParams.get("rule", Lofs2.Rule.R3);
disableR4Items();
if (_rule == Lofs2.Rule.R1) {
rulebox.setSelectedItem("R1");
} else if (_rule == Lofs2.Rule.R1TimeLag) {
rulebox.setSelectedItem("R1-TL");
} else if (_rule == Lofs2.Rule.R2) {
rulebox.setSelectedItem("R2");
} else if (_rule == Lofs2.Rule.R3) {
rulebox.setSelectedItem("R3");
} else if (_rule == Lofs2.Rule.R4) {
rulebox.setSelectedItem("R4");
enableR4Items();
} else if (_rule == Lofs2.Rule.Tanh) {
rulebox.setSelectedItem("Tanh");
} else if (_rule == Lofs2.Rule.Skew) {
rulebox.setSelectedItem("Skew");
} else if (_rule == Lofs2.Rule.SkewE) {
rulebox.setSelectedItem("SkewE");
} else if (_rule == Lofs2.Rule.RSkew) {
rulebox.setSelectedItem("RSkew");
} else if (_rule == Lofs2.Rule.RSkewE) {
rulebox.setSelectedItem("RSkewE");
} else if (_rule == Lofs2.Rule.Patel) {
rulebox.setSelectedItem("Patel");
} else if (_rule == Lofs2.Rule.FastICA) {
rulebox.setSelectedItem("FastICA (see console)");
} else if (_rule == Lofs2.Rule.Nlo) {
rulebox.setSelectedItem("Nlo");
// } else if (_rule == Lofs2.Rule.IGCI) {
// rulebox.setSelectedItem("IGCI");
// } else if (_rule == Lofs2.Rule.RC) {
// rulebox.setSelectedItem("RC");
}
rulebox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
JComboBox box = (JComboBox) actionEvent.getSource();
String item = (String) box.getSelectedItem();
System.out.println(item);
if ("R4".equals(item)) {
enableR4Items();
} else {
disableR4Items();
}
if ("R1".equals(item)) {
searchParams.set("rule", Lofs2.Rule.R1);
} else if ("R1-TL".equals(item)) {
searchParams.set("rule", Lofs2.Rule.R1TimeLag);
} else if ("R2".equals(item)) {
searchParams.set("rule", Lofs2.Rule.R2);
} else if ("R3".equals(item)) {
searchParams.set("rule", Lofs2.Rule.R3);
} else if ("R4".equals(item)) {
searchParams.set("rule", Lofs2.Rule.R4);
} else if ("EB".equals(item)) {
searchParams.set("rule", Lofs2.Rule.EB);
} else if ("Tanh".equals(item)) {
searchParams.set("rule", Lofs2.Rule.Tanh);
} else if ("Skew".equals(item)) {
searchParams.set("rule", Lofs2.Rule.Skew);
} else if ("SkewE".equals(item)) {
searchParams.set("rule", Lofs2.Rule.SkewE);
} else if ("RSkew".equals(item)) {
searchParams.set("rule", Lofs2.Rule.RSkew);
} else if ("RSkewE".equals(item)) {
searchParams.set("rule", Lofs2.Rule.RSkewE);
} else if ("Patel".equals(item)) {
searchParams.set("rule", Lofs2.Rule.Patel);
} else if ("FastICA (see console)".equals(item)) {
searchParams.set("rule", Lofs2.Rule.FastICA);
} else if ("Nlo".equals(item)) {
searchParams.set("rule", Lofs2.Rule.Nlo);
// } else if ("IGCI".equals(item)) {
// searchParams.setRule(Lofs2.Rule.IGCI);
// } else if ("RC".equals(item)) {
// searchParams.setRule(Lofs2.Rule.RC);
} else {
throw new IllegalStateException();
}
}
});
JComboBox scoreBox = new JComboBox();
scoreBox.addItem("Anderson Darling");
scoreBox.addItem("Absolute Value");
scoreBox.addItem("Log Cosh");
// scoreBox.addItem("Maxent Approx");
// scoreBox.addItem("Other");
Lofs.Score _score = (Lofs.Score) searchParams.get("score", Lofs.Score.andersonDarling);
if (_score == Lofs.Score.andersonDarling) {
scoreBox.setSelectedItem("Anderson Darling");
} else if (_score == Lofs.Score.skew) {
scoreBox.setSelectedItem("Skew");
} else if (_score == Lofs.Score.kurtosis) {
scoreBox.setSelectedItem("Kurtosis");
} else if (_score == Lofs.Score.entropy) {
scoreBox.setSelectedItem("Entropy (delta = bins)");
} else if (_score == Lofs.Score.fifthMoment) {
scoreBox.setSelectedItem("Fifth Moment");
} else if (_score == Lofs.Score.absoluteValue) {
scoreBox.setSelectedItem("Absolute Value");
} else if (_score == Lofs.Score.exp) {
scoreBox.setSelectedItem("E(e^X)");
} else if (_score == Lofs.Score.logcosh) {
scoreBox.setSelectedItem("Log Cosh");
} else if (_score == Lofs.Score.other) {
scoreBox.setSelectedItem("Other");
}
scoreBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
JComboBox box = (JComboBox) actionEvent.getSource();
String item = (String) box.getSelectedItem();
System.out.println(item);
if ("Anderson Darling".equals(item)) {
searchParams.set("score", Lofs.Score.andersonDarling);
} else if ("Skew".equals(item)) {
searchParams.set("score", Lofs.Score.skew);
} else if ("Kurtosis".equals(item)) {
searchParams.set("score", Lofs.Score.kurtosis);
} else if ("Fifth Moment".equals(item)) {
searchParams.set("score", Lofs.Score.fifthMoment);
} else if ("Entropy (delta = bins)".equals(item)) {
searchParams.set("score", Lofs.Score.entropy);
} else if ("Absolute Value".equals(item)) {
searchParams.set("score", Lofs.Score.absoluteValue);
} else if ("E(e^X)".equals(item)) {
searchParams.set("score", Lofs.Score.exp);
} else if ("Exp Unstandardized".equals(item)) {
searchParams.set("score", Lofs.Score.expUnstandardized);
} else if ("-e^(-X^2/2)".equals(item)) {
searchParams.set("score", Lofs.Score.other);
} else if ("Log Cosh".equals(item)) {
searchParams.set("score", Lofs.Score.logcosh);
} else if ("Maxent Approx".equals(item)) {
searchParams.set("score", Lofs.Score.entropy);
} else if ("Other".equals(item)) {
searchParams.set("score", Lofs.Score.other);
} else {
throw new IllegalStateException();
}
}
});
Box b1 = Box.createVerticalBox();
b1.add(getParamsPanel());
b1.add(Box.createVerticalStrut(10));
Box b2 = Box.createHorizontalBox();
b2.add(Box.createGlue());
b2.add(getExecuteButton());
b1.add(b2);
b1.add(Box.createVerticalStrut(10));
Box b3b = Box.createHorizontalBox();
b3b.add(new JLabel("Rule:"));
b3b.add(Box.createHorizontalGlue());
b3b.add(rulebox);
b3b.add(Box.createHorizontalGlue());
b1.add(b3b);
Box b3c = Box.createHorizontalBox();
b3c.add(strongerDirection);
b3c.add(Box.createHorizontalGlue());
b1.add(b3c);
Box b3f = Box.createHorizontalBox();
b3f.add(label1);
b3f.add(epsilon);
b3f.add(Box.createHorizontalGlue());
b1.add(b3f);
Box b3f3 = Box.createHorizontalBox();
b3f3.add(label2);
b3f3.add(zeta);
b3f3.add(Box.createHorizontalGlue());
b1.add(b3f3);
Box b3e = Box.createHorizontalBox();
b3e.add(new JLabel("SL coef = "));
b3e.add(selfLoopStrength);
b3e.add(Box.createHorizontalGlue());
b1.add(b3e);
Box b3g = Box.createHorizontalBox();
b3g.add(new JLabel("Score:"));
b3g.add(scoreBox);
b3g.add(Box.createHorizontalGlue());
b1.add(b3g);
Box b4 = Box.createHorizontalBox();
JLabel label = new JLabel("<html>" + "*Please note that some" + "<br>searches may take a" + "<br>long time to complete." + "</html>");
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setVerticalAlignment(SwingConstants.CENTER);
label.setBorder(new TitledBorder(""));
b4.add(label);
b1.add(Box.createVerticalStrut(10));
b1.add(b4);
toolbar.add(b1);
return toolbar;
}
use of edu.cmu.tetradapp.util.DoubleTextField in project tetrad by cmu-phil.
the class LogParamsEditor 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 aField = new DoubleTextField(params.getDouble("a", 10.0), 6, NumberFormatUtil.getInstance().getNumberFormat());
aField.setFilter(new DoubleTextField.Filter() {
public double filter(double value, double oldValue) {
try {
params.set("a", value);
return value;
} catch (IllegalArgumentException e) {
return oldValue;
}
}
});
final IntTextField baseField = new IntTextField(params.getInt("base", 0), 4);
baseField.setFilter(new IntTextField.Filter() {
public int filter(int value, int oldValue) {
try {
params.set("base", 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 be logarithmically transformed by applying f(x) = ln(a + x) to each data point x." + "<br> Can also 'unlog' the data i.e., apply g(x) = exp(x) - a, or override the base"));
Box b9 = Box.createHorizontalBox();
b9.add(Box.createHorizontalGlue());
b9.add(new JLabel("<html> base (use 0 for natural log and base <i>e</i>): </html>"));
b9.add(baseField);
Box b7 = Box.createHorizontalBox();
b7.add(Box.createHorizontalGlue());
b7.add(new JLabel("<html><i>a = </i></html>"));
b7.add(aField);
JCheckBox unlog = new JCheckBox();
unlog.setSelected(params.getBoolean("unlog", false));
unlog.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JCheckBox box = (JCheckBox) e.getSource();
params.set("unlog", box.isSelected());
}
});
Box b8 = Box.createHorizontalBox();
b8.add(Box.createHorizontalGlue());
b8.add(new JLabel("<html>Unlog: </html>"));
b8.add(unlog);
b1.add(b2);
b1.add(Box.createVerticalStrut(5));
b1.add(b7);
b1.add(Box.createHorizontalGlue());
b1.add(b8);
b1.add(Box.createHorizontalGlue());
b1.add(b9);
b1.add(Box.createHorizontalGlue());
add(b1, BorderLayout.CENTER);
}
use of edu.cmu.tetradapp.util.DoubleTextField in project tetrad by cmu-phil.
the class RegressionParamsEditorPanel method buildAlphaArea.
private Box buildAlphaArea(double alpha) {
DoubleTextField field = new DoubleTextField(alpha, 4, NumberFormatUtil.getInstance().getNumberFormat());
field.setFilter((value, oldValue) -> {
if (0.0 <= value && value <= 1.0) {
params.set("alpha", value);
RegressionParamsEditorPanel.this.firePropertyChange("significanceChanged", oldValue, value);
return value;
}
return oldValue;
});
Box box = Box.createHorizontalBox();
box.add(new JLabel("Alpha: "));
box.add(field);
box.add(Box.createHorizontalGlue());
return box;
}
Aggregations