use of edu.cmu.tetradapp.util.WatchedProcess in project tetrad by cmu-phil.
the class PcStableLocalSearchEditor method addSpecialMenus.
protected void addSpecialMenus(JMenuBar menuBar) {
if (!(getAlgorithmRunner() instanceof IGesRunner)) {
JMenu test = new JMenu("Independence");
menuBar.add(test);
IndTestMenuItems.addIndependenceTestChoices(test, this);
// test.addSeparator();
//
// AlgorithmRunner algorithmRunner = getAlgorithmRunner();
// if (algorithmRunner instanceof IndTestProducer) {
// IndTestProducer p = (IndTestProducer) algorithmRunner;
// IndependenceFactsAction action =
// new IndependenceFactsAction(this, p, "Independence Facts...");
// test.add(action);
// }
}
JMenu graph = new JMenu("Graph");
JMenuItem showDags = new JMenuItem("Show DAGs in forbid_latent_common_causes");
// JMenuItem meekOrient = new JMenuItem("Meek Orientation");
JMenuItem dagInPattern = new JMenuItem("Choose DAG in forbid_latent_common_causes");
JMenuItem gesOrient = new JMenuItem("Global Score-based Reorientation");
JMenuItem nextGraph = new JMenuItem("Next Graph");
JMenuItem previousGraph = new JMenuItem("Previous Graph");
// graph.add(new LayoutMenu(this));
graph.add(new GraphPropertiesAction(getWorkbench()));
graph.add(new PathsAction(getWorkbench()));
// graph.add(new DirectedPathsAction(getWorkbench()));
// graph.add(new TreksAction(getWorkbench()));
// graph.add(new AllPathsAction(getWorkbench()));
// graph.add(new NeighborhoodsAction(getWorkbench()));
graph.add(new TriplesAction(getWorkbench().getGraph(), getAlgorithmRunner()));
graph.addSeparator();
// graph.add(meekOrient);
graph.add(dagInPattern);
graph.add(gesOrient);
graph.addSeparator();
graph.add(previousGraph);
graph.add(nextGraph);
graph.addSeparator();
graph.add(showDags);
graph.addSeparator();
graph.add(new JMenuItem(new SelectBidirectedAction(getWorkbench())));
graph.add(new JMenuItem(new SelectUndirectedAction(getWorkbench())));
menuBar.add(graph);
showDags.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Window owner = (Window) getTopLevelAncestor();
new WatchedProcess(owner) {
public void watch() {
// Needs to be a pattern search; this isn't checked
// before running the algorithm because of allowable
// "slop"--e.g. bidirected edges.
AlgorithmRunner runner = getAlgorithmRunner();
Graph graph = runner.getGraph();
if (graph == null) {
JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "No result gaph.");
return;
}
// if (runner instanceof ImagesRunner) {
// GraphScorer scorer = ((ImagesRunner) runner).getGraphScorer();
// Graph _graph = ((ImagesRunner) runner).getTopGraphs().get(getIndex()).getGraph();
//
// ScoredGraphsDisplay display = new ScoredGraphsDisplay(_graph, scorer);
// GraphWorkbench workbench = getWorkbench();
//
// EditorWindow editorWindow =
// new EditorWindow(display, "Independence Facts",
// "Close", false, workbench);
// DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER);
// editorWindow.setVisible(true);
// }
// else {
PatternDisplay display = new PatternDisplay(graph);
GraphWorkbench workbench = getWorkbench();
EditorWindow editorWindow = new EditorWindow(display, "Independence Facts", "Close", false, workbench);
DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER);
editorWindow.setVisible(true);
// }
}
};
}
});
// meekOrient.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e) {
// ImpliedOrientation rules = getAlgorithmRunner().getMeekRules();
// rules.setKnowledge((IKnowledge) getAlgorithmRunner().getParams().get("knowledge", new Knowledge2()));
// rules.orientImplied(getGraph());
// getGraphHistory().add(getGraph());
// getWorkbench().setGraph(getGraph());
// firePropertyChange("modelChanged", null, null);
// }
// });
dagInPattern.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Graph graph = new EdgeListGraph(getGraph());
// Removing bidirected edges from the pattern before selecting a DAG. 4
for (Edge edge : graph.getEdges()) {
if (Edges.isBidirectedEdge(edge)) {
graph.removeEdge(edge);
}
}
PatternToDag search = new PatternToDag(new EdgeListGraphSingleConnections(graph));
Graph dag = search.patternToDagMeek();
getGraphHistory().add(dag);
getWorkbench().setGraph(dag);
((AbstractAlgorithmRunner) getAlgorithmRunner()).setResultGraph(dag);
firePropertyChange("modelChanged", null, null);
}
});
gesOrient.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DataModel dataModel = getAlgorithmRunner().getDataModel();
final Graph graph = SearchGraphUtils.reorient(getGraph(), dataModel, getKnowledge());
getGraphHistory().add(graph);
getWorkbench().setGraph(graph);
firePropertyChange("modelChanged", null, null);
}
});
nextGraph.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Graph next = getGraphHistory().next();
getWorkbench().setGraph(next);
((AbstractAlgorithmRunner) getAlgorithmRunner()).setResultGraph(next);
firePropertyChange("modelChanged", null, null);
}
});
previousGraph.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Graph previous = getGraphHistory().previous();
getWorkbench().setGraph(previous);
((AbstractAlgorithmRunner) getAlgorithmRunner()).setResultGraph(previous);
firePropertyChange("modelChanged", null, null);
}
});
// if (getAlgorithmRunner().supportsKnowledge()) {
// menuBar.add(new Knowledge2Menu(this));
// }
menuBar.add(new LayoutMenu(this));
}
use of edu.cmu.tetradapp.util.WatchedProcess in project tetrad by cmu-phil.
the class PathsAction method update.
private void update(final Graph graph, final JTextArea textArea, final List<Node> nodes1, final List<Node> nodes2, final String method) {
Window owner = (Window) JOptionUtils.centeringComp().getTopLevelAncestor();
final WatchedProcess process = new WatchedProcess(owner) {
public void watch() {
if ("Directed Paths".equals(method)) {
textArea.setText("");
allDirectedPaths(graph, textArea, nodes1, nodes2);
} else if ("Semidirected Paths".equals(method)) {
textArea.setText("");
allSemidirectedPaths(graph, textArea, nodes1, nodes2);
} else if ("Treks".equals(method)) {
textArea.setText("");
allTreks(graph, textArea, nodes1, nodes2);
} else if ("Adjacents".equals(method)) {
textArea.setText("");
adjacentNodes(graph, textArea, nodes1, nodes2);
}
}
};
}
use of edu.cmu.tetradapp.util.WatchedProcess in project tetrad by cmu-phil.
the class GeneralAlgorithmEditor method doSearch.
private void doSearch(final GeneralAlgorithmRunner runner) {
new WatchedProcess((Window) getTopLevelAncestor()) {
@Override
public void watch() {
AlgorithmModel algoModel = algorithmList.getSelectedValue();
if (algoModel != null) {
String title = String.format("Algorithm: %s", algoModel.getAlgorithm().getAnnotation().name());
algorithmGraphTitle.setText(title);
HpcAccount hpcAccount = null;
if (algoModel.getAlgorithm().getAnnotation().algoType() != AlgType.orient_pairwise && runner.getDataModelList().getModelList().size() == 1) {
String algoName = algoModel.getAlgorithm().getAnnotation().name();
hpcAccount = showRemoteComputingOptions(algoName);
}
if (hpcAccount == null) {
graphEditor.saveLayout();
runner.execute();
// Show graph
graphEditor.replace(runner.getGraphs());
graphEditor.validate();
firePropertyChange("modelChanged", null, null);
// Update the graphContainer
graphContainer.add(graphEditor);
changeCard(GRAPH_CARD);
} else {
try {
doRemoteCompute(runner, hpcAccount);
} catch (Exception exception) {
LOGGER.error("Unable to run algorithm.", exception);
}
}
}
}
};
}
use of edu.cmu.tetradapp.util.WatchedProcess 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.WatchedProcess in project tetrad by cmu-phil.
the class FgesSearchEditor 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) {
removeStatsTabs();
execute();
}
});
JButton statsButton = new JButton("Calc Stats");
statsButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Window owner = (Window) getTopLevelAncestor();
new WatchedProcess(owner) {
public void watch() {
calcStats();
}
};
}
});
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));
if (!(getAlgorithmRunner().getDataModel() instanceof ICovarianceMatrix)) {
Box b3 = Box.createHorizontalBox();
b3.add(Box.createGlue());
b3.add(statsButton);
b1.add(b3);
}
// if (getAlgorithmRunner().getParameters() instanceof Parameters) {
// Parameters params = (Parameters) getAlgorithmRunner().getParameters();
// JCheckBox preventCycles = new JCheckBox("Aggressively Prevent Cycles");
// preventCycles.setHorizontalTextPosition(AbstractButton.RIGHT);
// preventCycles.setSelected(params.isAggressivelyPreventCycles());
//
// preventCycles.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e) {
// JCheckBox box = (JCheckBox) e.getSource();
// Parameters params = (Parameters) getAlgorithmRunner().getParameters();
// params.setAggressivelyPreventCycles(box.isSelected());
// }
// });
//
// b1.add(Box.createVerticalStrut(5));
// Box hBox = Box.createHorizontalBox();
// hBox.add(Box.createHorizontalGlue());
// hBox.add(preventCycles);
// 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;
}
Aggregations