use of edu.cmu.tetrad.util.Parameters in project tetrad by cmu-phil.
the class AbstractSearchEditor 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
*/
void execute() {
Window owner = (Window) getTopLevelAncestor();
final WatchedProcess process = new WatchedProcess(owner) {
public void watch() {
try {
getExecuteButton().setEnabled(false);
} catch (Exception e) {
throw new RuntimeException(e);
}
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();
} 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 AbstractSearchEditor method workbenchScroll.
JScrollPane workbenchScroll(String resultLabel) {
Graph resultGraph = resultGraph();
Graph sourceGraph = algorithmRunner.getSourceGraph();
Parameters searchParams = algorithmRunner.getParams();
Graph latestWorkbenchGraph = null;
if (searchParams != null) {
latestWorkbenchGraph = (Graph) searchParams.get("sourceGraph", null);
}
if (latestWorkbenchGraph == null) {
GraphUtils.arrangeBySourceGraph(resultGraph, sourceGraph);
} else {
GraphUtils.arrangeBySourceGraph(resultGraph, latestWorkbenchGraph);
}
// boolean arrangedAll = DataGraphUtils.arrangeBySourceGraph(resultGraph,
// latestWorkbenchGraph);
//
// if (!arrangedAll) {
// arrangedAll =
// DataGraphUtils.arrangeBySourceGraph(resultGraph, sourceGraph);
// }
// if (!arrangedAll) {
// DataGraphUtils.circleLayout(resultGraph, 200, 200, 150);
// }
this.workbench = new GraphWorkbench(resultGraph);
graphHistory.clear();
graphHistory.add(resultGraph);
this.workbench.setAllowDoubleClickActions(false);
this.workbench.setAllowNodeEdgeSelection(true);
this.workbenchScroll = new JScrollPane(workbench);
// workbenchScroll.setPreferredSize(new Dimension(450, 450));
// workbenchScroll.setBorder(new TitledBorder(resultLabel));
this.workbench.addMouseListener(new MouseAdapter() {
public void mouseExited(MouseEvent e) {
storeLatestWorkbenchGraph();
}
});
return workbenchScroll;
}
use of edu.cmu.tetrad.util.Parameters in project tetrad by cmu-phil.
the class CalculatorAction method actionPerformed.
/**
* Launches the calculator editoir.
*/
public void actionPerformed(ActionEvent e) {
final CalculatorEditor editor = new CalculatorEditor();
Parameters params = wrapper.getParams();
if (params instanceof HasCalculatorParams) {
params = ((HasCalculatorParams) params).getCalculatorParams();
}
editor.setParams(params);
editor.setParentModels(new Object[] { wrapper });
editor.setup();
EditorWindow editorWindow = new EditorWindow(editor, editor.getName(), "Save", true, dataEditor);
DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER);
editorWindow.pack();
editorWindow.setVisible(true);
editorWindow.addInternalFrameListener(new InternalFrameAdapter() {
public void internalFrameClosed(InternalFrameEvent e) {
EditorWindow window = (EditorWindow) e.getSource();
if (window.isCanceled()) {
return;
}
if (editor.finalizeEdit()) {
List<String> equations = new ArrayList<>();
String _displayEquations = Preferences.userRoot().get("calculator_equations", "");
String[] displayEquations = _displayEquations.split("///");
for (String equation : displayEquations) {
if (equation.contains("$")) {
for (Node node : editor.getDataSet().getVariables()) {
equations.add(equation.replace("$", node.getName()));
}
} else {
equations.add(equation);
}
}
String[] eqs = equations.toArray(new String[0]);
try {
Transformation.transform(editor.getDataSet(), eqs);
} catch (ParseException e1) {
throw new IllegalStateException("Parse error while applying equations to dataset.");
}
}
}
});
}
use of edu.cmu.tetrad.util.Parameters in project tetrad by cmu-phil.
the class LingSearchEditor method setThreshold.
private void setThreshold(double value) {
Parameters params = getAlgorithmRunner().getParams();
params.set("threshold", value);
}
use of edu.cmu.tetrad.util.Parameters in project tetrad by cmu-phil.
the class LingamSearchEditor method setPruneFactor.
private void setPruneFactor(double value) {
Parameters params = getAlgorithmRunner().getParams();
params.set("pruneFactor", value);
}
Aggregations