use of edu.cmu.tetrad.util.Parameters in project tetrad by cmu-phil.
the class IonSearchEditor method getToolbar.
/**
* Construct the toolbar panel.
*/
protected JPanel getToolbar() {
JPanel toolbar = new JPanel();
getExecuteButton().setText("Execute*");
getExecuteButton().addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
execute();
}
});
Box b1 = Box.createVerticalBox();
final Parameters params = getAlgorithmRunner().getParams();
JCheckBox pruneByAdjacenciesBox = new JCheckBox("Prune by Adjacencies");
pruneByAdjacenciesBox.setSelected(params.getBoolean("pruneByAdjacencies", true));
JCheckBox pruneByPathLengthBox = new JCheckBox("Prune by Path Length");
pruneByPathLengthBox.setSelected(params.getBoolean("pruneByPathLength", true));
pruneByAdjacenciesBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JCheckBox checkBox = (JCheckBox) e.getSource();
params.set("pruneByAdjacencies", checkBox.isSelected());
}
});
pruneByPathLengthBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JCheckBox checkBox = (JCheckBox) e.getSource();
params.set("pruneByPathLength", checkBox.isSelected());
}
});
Box paramsPanel = Box.createVerticalBox();
paramsPanel.setBorder(new TitledBorder("Parameters"));
Box b3a = Box.createHorizontalBox();
b3a.add(pruneByAdjacenciesBox);
b3a.add(Box.createHorizontalGlue());
paramsPanel.add(b3a);
Box b3b = Box.createHorizontalBox();
b3b.add(pruneByPathLengthBox);
b3b.add(Box.createHorizontalGlue());
paramsPanel.add(b3b);
b1.add(paramsPanel);
b1.add(Box.createVerticalStrut(10));
Box b2 = Box.createHorizontalBox();
b2.add(Box.createGlue());
b2.add(getExecuteButton());
b1.add(b2);
b1.add(Box.createVerticalStrut(10));
if (getAlgorithmRunner().getDataModel() instanceof DataSet) {
Box b3 = Box.createHorizontalBox();
b3.add(Box.createGlue());
b1.add(b3);
}
if (getAlgorithmRunner().getParams() instanceof Parameters) {
b1.add(Box.createVerticalStrut(5));
Box hBox = Box.createHorizontalBox();
hBox.add(Box.createHorizontalGlue());
b1.add(hBox);
b1.add(Box.createVerticalStrut(5));
}
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.tetrad.util.Parameters in project tetrad by cmu-phil.
the class IonSearchEditor method execute.
/**
* Executes the algorithm. The execution takes place inside a thread, so one
* cannot count on a result graph having been found when the method
*/
public void execute() {
Window owner = (Window) getTopLevelAncestor();
final WatchedProcess process = new WatchedProcess(owner) {
public void watch() {
getExecuteButton().setEnabled(false);
setErrorMessage(null);
if (!knowledgeMessageShown) {
Parameters searchParams = getAlgorithmRunner().getParams();
if (searchParams != null) {
IKnowledge knowledge = (IKnowledge) searchParams.get("knowledge", new Knowledge2());
if (!knowledge.isEmpty()) {
JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Using previously set knowledge. (To edit, use " + "the Knowledge menu.)");
knowledgeMessageShown = true;
}
}
}
try {
storeLatestWorkbenchGraph();
getAlgorithmRunner().execute();
IonRunner runner = (IonRunner) getAlgorithmRunner();
arrangeGraphs();
ionDisplay.resetGraphs(runner.getStoredGraphs());
} catch (Exception e) {
CharArrayWriter writer1 = new CharArrayWriter();
PrintWriter writer2 = new PrintWriter(writer1);
e.printStackTrace(writer2);
String message = writer1.toString();
writer2.close();
e.printStackTrace(System.out);
TetradLogger.getInstance().error(message);
String messageString = e.getMessage();
if (e.getCause() != null) {
messageString = e.getCause().getMessage();
}
if (messageString == null) {
messageString = message;
}
setErrorMessage(messageString);
TetradLogger.getInstance().error("************Algorithm stopped!");
getExecuteButton().setEnabled(true);
throw new RuntimeException(e);
}
getWorkbenchScroll().setBorder(new TitledBorder(getResultLabel()));
Graph resultGraph = resultGraph();
doDefaultArrangement(resultGraph);
getWorkbench().setBackground(Color.WHITE);
getWorkbench().setGraph(resultGraph);
getGraphHistory().clear();
getGraphHistory().add(resultGraph);
getWorkbench().repaint();
// For Mimbuild, e.g., that need to do a second stage.
firePropertyChange("algorithmFinished", null, null);
getExecuteButton().setEnabled(true);
firePropertyChange("modelChanged", null, null);
}
};
Thread watcher = new Thread() {
public void run() {
while (true) {
try {
sleep(300);
if (!process.isAlive()) {
getExecuteButton().setEnabled(true);
return;
}
} catch (InterruptedException e) {
getExecuteButton().setEnabled(true);
return;
}
}
}
};
watcher.start();
}
use of edu.cmu.tetrad.util.Parameters in project tetrad by cmu-phil.
the class LingSearchEditor method getToolbar.
/**
* Construct the toolbar panel.
*/
protected JPanel getToolbar() {
JPanel toolbar = new JPanel();
getExecuteButton().setText("Execute*");
getExecuteButton().addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
execute();
}
});
Box b1 = Box.createVerticalBox();
Box b21 = Box.createVerticalBox();
Box b211 = Box.createHorizontalBox();
b211.add(new JLabel("Threshold "));
Parameters params = getAlgorithmRunner().getParams();
double pruneFactor = params.getDouble("threshold", 0.5);
DoubleTextField field = new DoubleTextField(pruneFactor, 8, NumberFormatUtil.getInstance().getNumberFormat());
field.setFilter(new DoubleTextField.Filter() {
public double filter(double value, double oldValue) {
if (value > 0.0) {
setThreshold(value);
return value;
}
return oldValue;
}
});
b211.add(field);
b21.add(b211);
JPanel paramsPanel = new JPanel();
paramsPanel.add(b21);
paramsPanel.setBorder(new TitledBorder("Parameters"));
b1.add(paramsPanel);
b1.add(Box.createVerticalStrut(10));
Box b2 = Box.createHorizontalBox();
b2.add(Box.createGlue());
b2.add(getExecuteButton());
b1.add(b2);
b1.add(Box.createVerticalStrut(10));
if (getAlgorithmRunner().getDataModel() instanceof DataSet) {
Box b3 = Box.createHorizontalBox();
b3.add(Box.createGlue());
b1.add(b3);
}
if (getAlgorithmRunner().getParams() instanceof Parameters) {
b1.add(Box.createVerticalStrut(5));
Box hBox = Box.createHorizontalBox();
hBox.add(Box.createHorizontalGlue());
b1.add(hBox);
b1.add(Box.createVerticalStrut(5));
}
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.tetrad.util.Parameters in project tetrad by cmu-phil.
the class LingamSearchEditor method getToolbar.
/**
* Construct the toolbar panel.
*/
protected JPanel getToolbar() {
JPanel toolbar = new JPanel();
getExecuteButton().setText("Execute*");
getExecuteButton().addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
execute();
}
});
Box b1 = Box.createVerticalBox();
Box b21 = Box.createVerticalBox();
Box b211 = Box.createHorizontalBox();
b211.add(new JLabel("Prune Factor "));
Parameters params = getAlgorithmRunner().getParams();
double pruneFactor = params.getDouble("pruneFactor", 1.0);
DoubleTextField field = new DoubleTextField(pruneFactor, 8, NumberFormatUtil.getInstance().getNumberFormat());
field.setFilter(new DoubleTextField.Filter() {
public double filter(double value, double oldValue) {
if (value > 0.0) {
setPruneFactor(value);
return value;
}
return oldValue;
}
});
b211.add(field);
b21.add(b211);
JPanel paramsPanel = new JPanel();
paramsPanel.add(b21);
paramsPanel.setBorder(new TitledBorder("Parameters"));
b1.add(paramsPanel);
b1.add(Box.createVerticalStrut(10));
Box b2 = Box.createHorizontalBox();
b2.add(Box.createGlue());
b2.add(getExecuteButton());
b1.add(b2);
b1.add(Box.createVerticalStrut(10));
if (getAlgorithmRunner().getDataModel() instanceof DataSet) {
Box b3 = Box.createHorizontalBox();
b3.add(Box.createGlue());
b1.add(b3);
}
if (getAlgorithmRunner().getParams() instanceof Parameters) {
b1.add(Box.createVerticalStrut(5));
Box hBox = Box.createHorizontalBox();
hBox.add(Box.createHorizontalGlue());
b1.add(hBox);
b1.add(Box.createVerticalStrut(5));
}
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.tetrad.util.Parameters in project tetrad by cmu-phil.
the class MbSearchParamEditor 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);
if (varNames == null) {
varNames = getVarsFromData(parentModels);
if (varNames == null) {
varNames = getVarsFromGraph(parentModels);
}
if (varNames == null) {
throw new IllegalStateException("Variables are not accessible.");
}
params().set("varNames", varNames);
}
setBorder(new MatteBorder(10, 10, 10, 10, super.getBackground()));
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
// Set up components.
String[] variableNames = varNames.toArray(new String[varNames.size()]);
Arrays.sort(variableNames);
JComboBox varsBox = new JComboBox(variableNames);
varsBox.setMaximumSize(new Dimension(80, 24));
varsBox.setPreferredSize(new Dimension(80, 24));
String targetName = params.getString("targetName", null);
if (!Arrays.asList(variableNames).contains(targetName)) {
params.set("targetName", variableNames[0]);
targetName = params.getString("targetName", null);
}
if (targetName == null) {
targetName = (String) varsBox.getSelectedItem();
} else {
varsBox.setSelectedItem(targetName);
}
setTargetName(targetName);
params().set("targetName", targetName());
varsBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
JComboBox box = (JComboBox) e.getSource();
setTargetName((String) box.getSelectedItem());
params().set("targetName", targetName());
}
});
DoubleTextField alphaField = new DoubleTextField(params.getDouble("alpha", 0.001), 8, new DecimalFormat("0.0########"));
alphaField.setFilter(new DoubleTextField.Filter() {
public double filter(double value, double oldValue) {
try {
params().set("alpha", 0.001);
Preferences.userRoot().putDouble("alpha", params().getDouble("alpha", 0.001));
return value;
} catch (Exception e) {
return oldValue;
}
}
});
IntTextField pcDepthField = new IntTextField(params().getInt("depth", -1), 4);
pcDepthField.setFilter(new IntTextField.Filter() {
public int filter(int value, int oldValue) {
try {
params().set("depth", value);
Preferences.userRoot().putInt("pcDepth", params().getInt("depth", -1));
return value;
} catch (Exception e) {
return oldValue;
}
}
});
JButton knowledgeButton = new JButton("Edit");
knowledgeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
openKnowledgeEditor();
}
});
JCheckBox preventCycles = new JCheckBox();
preventCycles.setSelected(params.getBoolean("aggressivelyPreventCycles", false));
preventCycles.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JCheckBox box = (JCheckBox) e.getSource();
Parameters p = params;
p.set("aggressivelyPreventCycles", box.isSelected());
}
});
// Do Layout.
Box hBox = Box.createHorizontalBox();
hBox.add(new JLabel("Aggressively Prevent Cycles:"));
hBox.add(Box.createHorizontalGlue());
hBox.add(preventCycles);
add(hBox);
add(Box.createVerticalStrut(5));
Box b0 = Box.createHorizontalBox();
b0.add(new JLabel("Target:"));
b0.add(Box.createRigidArea(new Dimension(10, 0)));
b0.add(Box.createHorizontalGlue());
b0.add(varsBox);
add(b0);
Box b1 = Box.createHorizontalBox();
b1.add(new JLabel("Alpha:"));
b1.add(Box.createRigidArea(new Dimension(10, 0)));
b1.add(Box.createHorizontalGlue());
b1.add(alphaField);
add(b1);
Box b2 = Box.createHorizontalBox();
b2.add(new JLabel("Depth:"));
b2.add(Box.createRigidArea(new Dimension(10, 0)));
b2.add(Box.createHorizontalGlue());
b2.add(pcDepthField);
add(b2);
// Box b3 = Box.createHorizontalBox();
// b3.add(new JLabel("Knowledge:"));
// b3.add(Box.createRigidArea(new Dimension(10, 0)));
// b3.add(Box.createHorizontalGlue());
// b3.add(knowledgeButton);
//
//
// add(b3);
}
Aggregations