use of edu.cmu.tetradapp.util.IntTextField in project tetrad by cmu-phil.
the class FgesSearchEditor method calcStats.
private void calcStats() {
FgesRunner runner = (FgesRunner) getAlgorithmRunner();
if (runner.getTopGraphs().isEmpty()) {
throw new IllegalArgumentException("No patterns were recorded. Please adjust the number of " + "patterns to store.");
}
Graph resultGraph = runner.getTopGraphs().get(runner.getIndex()).getGraph();
if (!(getAlgorithmRunner().getDataModel() instanceof ICovarianceMatrix)) {
// resultGraph may be the output of a PC search.
// Such graphs sometimes contain doubly directed edges.
// We converte such edges to directed edges here.
// For the time being an orientation is arbitrarily selected.
Set<Edge> allEdges = resultGraph.getEdges();
for (Edge edge : allEdges) {
if (edge.getEndpoint1() == Endpoint.ARROW && edge.getEndpoint2() == Endpoint.ARROW) {
// Option 1 orient it from node1 to node2
resultGraph.setEndpoint(edge.getNode1(), edge.getNode2(), Endpoint.ARROW);
// Option 2 remove such edges:
resultGraph.removeEdge(edge);
}
}
Graph dag = SearchGraphUtils.dagFromPattern(resultGraph);
// DataSet dataSet = (DataSet) getAlgorithmRunner().getDataModel();
// String report;
//
// if (dataSet.isContinuous()) {
// report = reportIfContinuous(dag, dataSet);
// } else if (dataSet.isDiscrete()) {
// report = reportIfDiscrete(dag, dataSet);
// } else {
// throw new IllegalArgumentException("");
// }
String bayesFactorsReport = ((FgesRunner) getAlgorithmRunner()).getBayesFactorsReport(dag);
// String bootstrapEdgeCountsReport = ((ImagesRunner) getAlgorithmRunner()).getBootstrapEdgeCountsReport(25);
JScrollPane dagWorkbenchScroll = dagWorkbenchScroll(dag);
// modelStatsText = new JTextArea();
JTextArea logBayesFactorsScroll = new JTextArea();
// bootstrapEdgeCountsScroll = new JTextArea();
// modelStatsText.setLineWrap(true);
// modelStatsText.setWrapStyleWord(true);
// modelStatsText.setText(report);
logBayesFactorsScroll.setLineWrap(true);
logBayesFactorsScroll.setWrapStyleWord(true);
logBayesFactorsScroll.setText(bayesFactorsReport);
// bootstrapEdgeCountsScroll.setLineWrap(true);
// bootstrapEdgeCountsScroll.setWrapStyleWord(true);
// bootstrapEdgeCountsScroll.setText(bootstrapEdgeCountsReport);
// JPanel bootstrapPanel = new JPanel();
// bootstrapPanel.setLayout(new BorderLayout());
// bootstrapPanel.add(bootstrapEdgeCountsScroll, BorderLayout.CENTER);
JTextArea modelStatisticsScroll = new JTextArea();
// bootstrapEdgeCountsScroll = new JTextArea();
// modelStatsText.setLineWrap(true);
// modelStatsText.setWrapStyleWord(true);
// modelStatsText.setText(report);
modelStatisticsScroll.setLineWrap(true);
modelStatisticsScroll.setWrapStyleWord(true);
modelStatisticsScroll.setText(reportIfDiscrete(dag, (DataSet) getDataModel()));
Box b = Box.createHorizontalBox();
b.add(new JLabel("# Bootstraps = "));
final IntTextField numBootstraps = new IntTextField(25, 8);
numBootstraps.setFilter(new IntTextField.Filter() {
public int filter(int value, int oldValue) {
if (value < 0)
return oldValue;
else
return value;
}
});
b.add(numBootstraps);
JButton goButton = new JButton("Go!");
goButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
Window owner = (Window) getTopLevelAncestor();
new WatchedProcess(owner) {
public void watch() {
int n = numBootstraps.getValue();
// String bootstrapEdgeCountsReport = ((ImagesRunner) getAlgorithmRunner()).getBootstrapEdgeCountsReport(n);
// bootstrapEdgeCountsScroll.setText(bootstrapEdgeCountsReport);
}
};
}
});
b.add(Box.createHorizontalGlue());
b.add(goButton);
// bootstrapPanel.add(b, BorderLayout.NORTH);
removeStatsTabs();
tabbedPane.addTab("DAG in pattern", dagWorkbenchScroll);
// tabbedPane.addTab("DAG Model Statistics", new JScrollPane(modelStatsText));
tabbedPane.addTab("Log Bayes Factors", new JScrollPane(logBayesFactorsScroll));
// tabbedPane.addTab("Edge Bootstraps", new JScrollPane(bootstrapPanel));
tabbedPane.addTab("Model Stats", new JScrollPane(modelStatisticsScroll));
}
}
use of edu.cmu.tetradapp.util.IntTextField 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;
}
use of edu.cmu.tetradapp.util.IntTextField in project tetrad by cmu-phil.
the class BayesPmParamsEditor method setup.
public void setup() {
lowerBoundField = new IntTextField(getParams().getInt("lowerBoundNumVals", 2), 4);
lowerBoundField.setFilter(new IntTextField.Filter() {
public int filter(int value, int oldValue) {
try {
getParams().set("lowerBoundNumVals", value);
return value;
} catch (Exception e) {
return oldValue;
}
}
});
upperBoundField = new IntTextField(getParams().getInt("upperBoundNumVals", 2), 4);
upperBoundField.setFilter(new IntTextField.Filter() {
public int filter(int value, int oldValue) {
try {
getParams().set("upperBoundNumVals", value);
return value;
} catch (Exception e) {
return oldValue;
}
}
});
// construct the workbench.
setLayout(new BorderLayout());
JRadioButton setUpManually = new JRadioButton("<html>" + "Set up manually.</html>");
JRadioButton automaticallyAssigned = new JRadioButton("<html>" + "Automatically assigned.</html>");
ButtonGroup group = new ButtonGroup();
group.add(setUpManually);
group.add(automaticallyAssigned);
// continue workbench construction.
Box b1 = Box.createVerticalBox();
Box b2 = Box.createHorizontalBox();
b2.add(new JLabel("Categories for variables should be:"));
b2.add(Box.createHorizontalGlue());
b1.add(b2);
b1.add(Box.createVerticalStrut(5));
Box b3 = Box.createHorizontalBox();
b3.add(setUpManually);
b3.add(Box.createHorizontalGlue());
// b3.add(fixedField);
b1.add(b3);
Box b4 = Box.createHorizontalBox();
b4.add(Box.createHorizontalStrut(25));
b4.add(new JLabel("<html>" + "All variables will initially have 2 categories, '0' and '1', " + "<br>which can then be changed variable by variable in the editor." + "</html>"));
b4.add(Box.createHorizontalGlue());
b1.add(b4);
b1.add(Box.createVerticalStrut(10));
Box b5 = Box.createHorizontalBox();
b5.add(automaticallyAssigned);
b5.add(Box.createHorizontalGlue());
b1.add(b5);
Box b6 = Box.createHorizontalBox();
b6.add(Box.createHorizontalStrut(25));
b6.add(new JLabel("<html>" + "Each variable will be automatically be assigned a number" + "<br>of categories (for simulation, e.g.). " + "</html>"));
b6.add(Box.createHorizontalGlue());
b1.add(b6);
b1.add(Box.createVerticalStrut(10));
Box b7 = Box.createHorizontalBox();
b7.add(Box.createHorizontalStrut(25));
b7.add(new JLabel("Least number of categories for each variable: "));
b7.add(Box.createHorizontalGlue());
b7.add(lowerBoundField);
b1.add(b7);
Box b8 = Box.createHorizontalBox();
b8.add(Box.createHorizontalStrut(25));
b8.add(new JLabel("Greatest number of categories for each variable: "));
b8.add(Box.createHorizontalGlue());
b8.add(upperBoundField);
b1.add(b8);
b1.add(Box.createHorizontalGlue());
add(b1, BorderLayout.CENTER);
if (getParams().getString("bayesPmInitializationMode", "automatic").equals("automatic")) {
setUpManually.setSelected(true);
lowerBoundField.setEnabled(false);
upperBoundField.setEnabled(false);
} else {
automaticallyAssigned.setSelected(true);
lowerBoundField.setEnabled(true);
upperBoundField.setEnabled(true);
}
setUpManually.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
getParams().set("bayesPmInitializationMode", "manual");
lowerBoundField.setEnabled(false);
upperBoundField.setEnabled(false);
}
});
automaticallyAssigned.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
getParams().set("bayesPmInitializationMode", "automatic");
lowerBoundField.setEnabled(true);
upperBoundField.setEnabled(true);
}
});
}
use of edu.cmu.tetradapp.util.IntTextField in project tetrad by cmu-phil.
the class BootstrapSamplerParamsEditor 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 IntTextField sampleSizeField = new IntTextField(params.getInt("sampleSize", 1000), 6);
sampleSizeField.setFilter(new IntTextField.Filter() {
public int filter(int value, int oldValue) {
try {
params.set("sampleSize", 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 sampled with replacement to create a new" + "<br>dataset with the number of samples entered below."));
Box b7 = Box.createHorizontalBox();
b7.add(Box.createHorizontalGlue());
b7.add(new JLabel("<html>" + "<i>Sample size: </i>" + "</html>"));
b7.add(sampleSizeField);
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.IntTextField in project tetrad by cmu-phil.
the class BayesDataParamsEditor method setup.
/**
* Constructs the GUI.
*/
public void setup() {
// set up text and ties them to the parameters object being edited.
IntTextField sampleSizeField = new IntTextField(getParams().getInt("sampleSize", 1000), 8);
sampleSizeField.setFilter(new IntTextField.Filter() {
public int filter(int value, int oldValue) {
try {
getParams().set("sampleSize", value);
return value;
} catch (Exception e) {
return oldValue;
}
}
});
IntTextField numDataSetsField = new IntTextField(getParams().getInt("numDataSets", 1), 8);
numDataSetsField.setFilter(new IntTextField.Filter() {
public int filter(int value, int oldValue) {
try {
getParams().set("numDataSets", value);
return value;
} catch (Exception e) {
return oldValue;
}
}
});
// JCheckBox latentDataSaved = new JCheckBox("Include Latent Variables",
// Preferences.userRoot().getBoolean("latentDataSaved", getParameters().isIncludeLatents()));
JCheckBox latentDataSaved = new JCheckBox("Include Latent Variables", getParams().getBoolean("latentDataSaved", false));
latentDataSaved.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JCheckBox checkBox = (JCheckBox) e.getSource();
params.set("latentDataSaved", checkBox.isSelected());
}
});
// construct the workbench.
setLayout(new BorderLayout());
// continue workbench construction.
Box b = Box.createVerticalBox();
Box b1 = Box.createHorizontalBox();
b1.add(new JLabel("Sample size: "));
b1.add(Box.createHorizontalGlue());
b1.add(sampleSizeField);
b.add(b1);
Box b1a = Box.createHorizontalBox();
b1a.add(new JLabel("Num data sets: "));
b1a.add(Box.createHorizontalGlue());
b1a.add(numDataSetsField);
b.add(b1a);
Box b2 = Box.createHorizontalBox();
b2.add(latentDataSaved);
b.add(b2);
add(b, BorderLayout.CENTER);
setBorder(new EmptyBorder(5, 5, 5, 5));
}
Aggregations