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);
}
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);
}
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;
}
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));
}
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);
}
Aggregations