Search in sources :

Example 16 with GraphWorkbench

use of edu.cmu.tetradapp.workbench.GraphWorkbench in project tetrad by cmu-phil.

the class FtfcSearchEditor method workbenchScroll.

private JScrollPane workbenchScroll(String resultLabel) {
    Graph resultGraph = resultGraph();
    Graph sourceGraph = getMimRunner().getSourceGraph();
    Graph latestWorkbenchGraph = (Graph) getMimRunner().getParams().get("sourceGraph", null);
    boolean arrangedAll = GraphUtils.arrangeBySourceGraph(resultGraph, latestWorkbenchGraph);
    if (!arrangedAll) {
        GraphUtils.arrangeBySourceGraph(resultGraph, sourceGraph);
    }
    this.workbench = new GraphWorkbench(resultGraph);
    this.workbench.setAllowDoubleClickActions(false);
    this.workbenchScroll = new JScrollPane(getWorkbench());
    getWorkbenchScroll().setPreferredSize(new Dimension(450, 450));
    getWorkbenchScroll().setBorder(new TitledBorder(resultLabel));
    this.workbench.addMouseListener(new MouseAdapter() {

        public void mouseExited(MouseEvent e) {
            storeLatestWorkbenchGraph();
        }
    });
    return getWorkbenchScroll();
}
Also used : EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) MouseEvent(java.awt.event.MouseEvent) GraphWorkbench(edu.cmu.tetradapp.workbench.GraphWorkbench) MouseAdapter(java.awt.event.MouseAdapter) TitledBorder(javax.swing.border.TitledBorder)

Example 17 with GraphWorkbench

use of edu.cmu.tetradapp.workbench.GraphWorkbench in project tetrad by cmu-phil.

the class IonSearchEditor 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));
}
Also used : LayoutMenu(edu.cmu.tetradapp.workbench.LayoutMenu) PatternToDag(edu.cmu.tetrad.search.PatternToDag) ActionEvent(java.awt.event.ActionEvent) WatchedProcess(edu.cmu.tetradapp.util.WatchedProcess) ActionListener(java.awt.event.ActionListener) GraphWorkbench(edu.cmu.tetradapp.workbench.GraphWorkbench) DataModel(edu.cmu.tetrad.data.DataModel)

Example 18 with GraphWorkbench

use of edu.cmu.tetradapp.workbench.GraphWorkbench in project tetrad by cmu-phil.

the class LingSearchEditor method layoutByKnowledge.

public void layoutByKnowledge() {
    GraphWorkbench resultWorkbench = getWorkbench();
    Graph graph = resultWorkbench.getGraph();
    IKnowledge knowledge = (IKnowledge) getAlgorithmRunner().getParams().get("knowledge", new Knowledge2());
    SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge);
// resultWorkbench.setGraph(graph);
}
Also used : IKnowledge(edu.cmu.tetrad.data.IKnowledge) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) GraphWorkbench(edu.cmu.tetradapp.workbench.GraphWorkbench) Knowledge2(edu.cmu.tetrad.data.Knowledge2)

Example 19 with GraphWorkbench

use of edu.cmu.tetradapp.workbench.GraphWorkbench in project tetrad by cmu-phil.

the class GraphSelectionEditor method resetGraphs.

private void resetGraphs(GraphSelectionWrapper wrapper) {
    wrapper.calculateSelection();
    if (wrapper.getSelectedVariables() == null || wrapper.getSelectedVariables().isEmpty()) {
        initSelection(wrapper);
    }
    for (int i = 0; i < tabbedPane.getTabCount(); i++) {
        Graph selection = wrapper.getSelectionGraph(i);
        if (selection.getNumNodes() > 500) {
            throw new IllegalArgumentException("That is too many nodes for me to display (" + selection.getNumNodes() + ") I can only go up to 500 nodes.\n" + "Try a smaller selection.");
        }
        if (!layoutGraph.isEmpty()) {
            for (Node node : selection.getNodes()) {
                List<Integer> center = layoutGraph.get(node.getName());
                if (center != null) {
                    node.setCenter(center.get(0), center.get(1));
                }
            }
        } else {
        // GraphUtils.circleLayout(selection, 200, 200, 150);
        // GraphUtils.fruchtermanReingoldLayout(selection);
        }
        GraphWorkbench workbench = getWorkbench(i);
        workbench.setGraph(selection);
        List<Node> selected = wrapper.getSelectedVariables();
        for (Node node : selected) {
            if (wrapper.getHighlightInEditor().contains(node) && workbench.getGraph().containsNode(node)) {
                workbench.selectNode(node);
            }
        }
    }
}
Also used : Graph(edu.cmu.tetrad.graph.Graph) GraphWorkbench(edu.cmu.tetradapp.workbench.GraphWorkbench) Node(edu.cmu.tetrad.graph.Node) GraphNode(edu.cmu.tetrad.graph.GraphNode) DisplayNode(edu.cmu.tetradapp.workbench.DisplayNode) Point(java.awt.Point)

Example 20 with GraphWorkbench

use of edu.cmu.tetradapp.workbench.GraphWorkbench in project tetrad by cmu-phil.

the class FactorAnalysisEditor method setup.

// ==========================PROTECTED METHODS============================//
/**
 * Sets up the editor, does the layout, and so on.
 */
protected void setup(String resultLabel) {
    FactorAnalysisRunner runner = (FactorAnalysisRunner) getAlgorithmRunner();
    Graph graph = runner.getGraph();
    JTextArea display = new JTextArea(runner.getOutput());
    JScrollPane scrollPane = new JScrollPane(display);
    scrollPane.setPreferredSize(new Dimension(500, 400));
    display.setEditable(false);
    display.setFont(new Font("Monospaced", Font.PLAIN, 12));
    GraphUtils.circleLayout(graph, 225, 200, 150);
    GraphUtils.fruchtermanReingoldLayout(graph);
    GraphWorkbench workbench = new GraphWorkbench(graph);
    JScrollPane graphPane = new JScrollPane(workbench);
    graphPane.setPreferredSize(new Dimension(500, 400));
    Box box = Box.createHorizontalBox();
    box.add(scrollPane);
    box.add(Box.createHorizontalStrut(3));
    box.add(Box.createHorizontalStrut(5));
    box.add(Box.createHorizontalGlue());
    Box vBox = Box.createVerticalBox();
    vBox.add(Box.createVerticalStrut(15));
    vBox.add(box);
    vBox.add(Box.createVerticalStrut(5));
    box.add(graphPane);
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(vBox, BorderLayout.CENTER);
    add(panel);
}
Also used : TimeLagGraph(edu.cmu.tetrad.graph.TimeLagGraph) Graph(edu.cmu.tetrad.graph.Graph) GraphWorkbench(edu.cmu.tetradapp.workbench.GraphWorkbench) FactorAnalysisRunner(edu.cmu.tetradapp.model.FactorAnalysisRunner)

Aggregations

GraphWorkbench (edu.cmu.tetradapp.workbench.GraphWorkbench)53 Graph (edu.cmu.tetrad.graph.Graph)24 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)13 ActionEvent (java.awt.event.ActionEvent)11 ActionListener (java.awt.event.ActionListener)11 IKnowledge (edu.cmu.tetrad.data.IKnowledge)8 Knowledge2 (edu.cmu.tetrad.data.Knowledge2)8 WatchedProcess (edu.cmu.tetradapp.util.WatchedProcess)8 LayoutMenu (edu.cmu.tetradapp.workbench.LayoutMenu)7 MouseAdapter (java.awt.event.MouseAdapter)7 MouseEvent (java.awt.event.MouseEvent)7 PropertyChangeEvent (java.beans.PropertyChangeEvent)6 PropertyChangeListener (java.beans.PropertyChangeListener)6 TitledBorder (javax.swing.border.TitledBorder)6 DataModel (edu.cmu.tetrad.data.DataModel)4 PatternToDag (edu.cmu.tetrad.search.PatternToDag)3 CSH (javax.help.CSH)3 HelpBroker (javax.help.HelpBroker)3 EmptyBorder (javax.swing.border.EmptyBorder)3 MatteBorder (javax.swing.border.MatteBorder)3