private void addCovMatrixTestMenuItems(JMenu test) { IndTestType testType = getTestType(); if (testType != IndTestType.FISHER_Z // && testType != IndTestType.CORRELATION_T ) { setTestType(IndTestType.FISHER_Z); } ButtonGroup group = new ButtonGroup(); JCheckBoxMenuItem fishersZ = new JCheckBoxMenuItem("Fisher's Z"); group.add(fishersZ); test.add(fishersZ); // JCheckBoxMenuItem tTest = new JCheckBoxMenuItem("Cramer's T"); // group.add(tTest); // test.add(tTest); testType = getTestType(); if (testType == IndTestType.FISHER_Z) { fishersZ.setSelected(true); } // else if (testType == IndTestType.CORRELATION_T) { // tTest.setSelected(true); // } fishersZ.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { setTestType(IndTestType.FISHER_Z); JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Using Fisher's Z."); } }); // tTest.addActionListener(new ActionListener() { // public void actionPerformed(ActionEvent e) { // setTestType(IndTestType.CORRELATION_T); // JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), // "Using Cramer's T."); // } // }); }
private JMenu createGraphMenu() { JMenu graph = new JMenu("Graph"); 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.addSeparator(); JMenuItem correlateExogenous = new JMenuItem("Correlate Exogenous Variables"); JMenuItem uncorrelateExogenous = new JMenuItem("Uncorrelate Exogenous Variables"); graph.add(correlateExogenous); graph.add(uncorrelateExogenous); graph.addSeparator(); correlateExogenous.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { correlateExogenousVariables(); getWorkbench().invalidate(); getWorkbench().repaint(); } }); uncorrelateExogenous.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { uncorrelationExogenousVariables(); getWorkbench().invalidate(); getWorkbench().repaint(); } }); JMenuItem randomGraph = new JMenuItem("Random Graph"); graph.add(randomGraph); randomGraph.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { RandomGraphEditor editor = new RandomGraphEditor(workbench.getGraph(), true); int ret = JOptionPane.showConfirmDialog( TimeLagGraphEditor.this, editor, "Edit Random DAG Parameters", JOptionPane.PLAIN_MESSAGE); if (ret == JOptionPane.OK_OPTION) { Graph graph = null; Graph dag = new Dag(); int numTrials = 0; while (graph == null && ++numTrials < 100) { if (editor.isRandomForward()) { dag = GraphUtils.randomGraphRandomForwardEdges( getGraph().getNodes(), editor.getNumLatents(), editor.getMaxEdges()); GraphUtils.arrangeBySourceGraph(dag, getWorkbench().getGraph()); HashMap<String, PointXy> layout = GraphUtils.grabLayout(workbench.getGraph().getNodes()); GraphUtils.arrangeByLayout(dag, layout); } else if (editor.isUniformlySelected()) { if (getGraph().getNumNodes() == editor.getNumNodes()) { HashMap<String, PointXy> layout = GraphUtils.grabLayout(workbench.getGraph().getNodes()); dag = GraphUtils.randomGraph( getGraph().getNodes(), editor.getNumLatents(), editor.getMaxEdges(), editor.getMaxDegree(), editor.getMaxIndegree(), editor.getMaxOutdegree(), editor.isConnected()); GraphUtils.arrangeBySourceGraph(dag, getWorkbench().getGraph()); GraphUtils.arrangeByLayout(dag, layout); } else { dag = GraphUtils.randomGraph( editor.getNumNodes(), editor.getNumLatents(), editor.getMaxEdges(), editor.getMaxDegree(), editor.getMaxIndegree(), editor.getMaxOutdegree(), editor.isConnected()); } } else { do { if (getGraph().getNumNodes() == editor.getNumNodes()) { HashMap<String, PointXy> layout = GraphUtils.grabLayout(workbench.getGraph().getNodes()); dag = GraphUtils.randomDag( getGraph().getNodes(), editor.getNumLatents(), editor.getMaxEdges(), 30, 15, 15, editor.isConnected()); GraphUtils.arrangeByLayout(dag, layout); } else { dag = GraphUtils.randomGraph( editor.getNumNodes(), editor.getNumLatents(), editor.getMaxEdges(), 30, 15, 15, editor.isConnected()); } } while (dag.getNumEdges() < editor.getMaxEdges()); } boolean addCycles = editor.isAddCycles(); if (addCycles) { int minNumCycles = editor.getMinNumCycles(); int minCycleLength = editor.getMinCycleLength(); // graph = DataGraphUtils.addCycles2(dag, minNumCycles, // minCycleLength); graph = GraphUtils.cyclicGraph4(editor.getNumNodes(), editor.getMaxEdges()); GraphUtils.addTwoCycles(graph, editor.getMinNumCycles()); } else { graph = new EdgeListGraph(dag); } } if (graph == null) { JOptionPane.showMessageDialog( TimeLagGraphEditor.this, "Could not find a graph that fits those constrains."); getWorkbench().setGraph(new EdgeListGraph(dag)); } else { getWorkbench().setGraph(graph); } // getWorkbench().setGraph(new EdgeListGraph(dag)); // getWorkbench().setGraph(graph); } } }); JMenuItem randomIndicatorModel = new JMenuItem("Random Multiple Indicator Model"); graph.add(randomIndicatorModel); randomIndicatorModel.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { RandomMimParamsEditor editor = new RandomMimParamsEditor(); int ret = JOptionPane.showConfirmDialog( JOptionUtils.centeringComp(), editor, "Edit Random MIM Parameters", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (ret == JOptionPane.OK_OPTION) { int numStructuralNodes = Preferences.userRoot().getInt("numStructuralNodes", 3); int maxStructuralEdges = Preferences.userRoot().getInt("numStructuralEdges", 3); int measurementModelDegree = Preferences.userRoot().getInt("measurementModelDegree", 3); int numLatentMeasuredImpureParents = Preferences.userRoot().getInt("latentMeasuredImpureParents", 0); int numMeasuredMeasuredImpureParents = Preferences.userRoot().getInt("measuredMeasuredImpureParents", 0); int numMeasuredMeasuredImpureAssociations = Preferences.userRoot().getInt("measuredMeasuredImpureAssociations", 0); Graph graph = DataGraphUtils.randomSingleFactorModel( numStructuralNodes, maxStructuralEdges, measurementModelDegree, numLatentMeasuredImpureParents, numMeasuredMeasuredImpureParents, numMeasuredMeasuredImpureAssociations); getWorkbench().setGraph(graph); } } }); graph.addSeparator(); graph.add(new JMenuItem(new SelectBidirectedAction(getWorkbench()))); graph.add(new JMenuItem(new SelectUndirectedAction(getWorkbench()))); // graph.addSeparator(); // IndependenceFactsAction action = new IndependenceFactsAction( // JOptionUtils.centeringComp(), this, "D Separation Facts..."); // graph.add(action); return graph; }
/** * Creates the "file" menu, which allows the user to load, save, and post workbench models. * * @return this menu. */ private JMenu createEditMenu() { JMenu edit = new JMenu("Edit"); // JMenuItem copy = new JMenuItem(new CopySubgraphAction(this)); // JMenuItem paste = new JMenuItem(new PasteSubgraphAction(this)); // // copy.setAccelerator( // KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK)); // paste.setAccelerator( // KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK)); // // edit.add(copy); // edit.add(paste); edit.addSeparator(); JMenuItem configuration = new JMenuItem("Configuration..."); edit.add(configuration); configuration.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { final TimeLagGraph graph = (TimeLagGraph) getLayoutEditable().getGraph(); class ConfigurationEditor extends JPanel { private int maxLag; private int numInitialLags; public ConfigurationEditor(final TimeLagGraph graph) { maxLag = graph.getMaxLag(); numInitialLags = graph.getNumInitialLags(); final SpinnerModel maxLagSpinnerModel = new SpinnerNumberModel(graph.getMaxLag(), 0, 300, 1); JSpinner maxLagSpinner = new JSpinner(maxLagSpinnerModel); maxLagSpinner.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { JSpinner spinner = (JSpinner) e.getSource(); SpinnerNumberModel model = (SpinnerNumberModel) spinner.getModel(); int value = (Integer) model.getValue(); setMaxLag(value); } }); final SpinnerModel initialLagsSpinnerModel = new SpinnerNumberModel(graph.getNumInitialLags(), 1, 300, 1); JSpinner initialLagsSpinner = new JSpinner(initialLagsSpinnerModel); initialLagsSpinner.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { JSpinner spinner = (JSpinner) e.getSource(); SpinnerNumberModel model = (SpinnerNumberModel) spinner.getModel(); int value = (Integer) model.getValue(); setNumInitialLags(value); } }); setLayout(new BorderLayout()); Box box = Box.createVerticalBox(); Box b1 = Box.createHorizontalBox(); b1.add(new JLabel("Time lag graph configuration:")); b1.add(Box.createHorizontalGlue()); box.add(b1); Box b2 = Box.createHorizontalBox(); b2.add(new JLabel("Maximum Lag = ")); b2.add(Box.createHorizontalGlue()); b2.add(maxLagSpinner); box.add(b2); Box b3 = Box.createHorizontalBox(); b3.add(new JLabel("# Initial Lags = ")); b3.add(Box.createHorizontalGlue()); b3.add(initialLagsSpinner); box.add(b3); box.setBorder(new EmptyBorder(10, 10, 10, 10)); add(box, BorderLayout.CENTER); } public int getMaxLag() { return maxLag; } public void setMaxLag(int maxLag) { this.maxLag = maxLag; } public int getNumInitialLags() { return numInitialLags; } public void setNumInitialLags(int numInitialLags) { this.numInitialLags = numInitialLags; } } final ConfigurationEditor editor = new ConfigurationEditor((TimeLagGraph) getGraph()); EditorWindow editorWindow = new EditorWindow(editor, "Configuration...", "Save", true, TimeLagGraphEditor.this); 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; } graph.setMaxLag(editor.getMaxLag()); graph.setNumInitialLags(editor.getNumInitialLags()); LayoutUtils.lastLayout(getLayoutEditable()); } }); } }); return edit; }
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 Pattern"); JMenuItem meekOrient = new JMenuItem("Meek Orientation"); JMenuItem dagInPattern = new JMenuItem("Choose DAG in Pattern"); JMenuItem gesOrient = new JMenuItem("Global Score-based Reorientation"); JMenuItem nextGraph = new JMenuItem("Next Graph"); JMenuItem previousGraph = new JMenuItem("Previous Graph"); 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(), 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.getResultGraph(); if (graph == null) { JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "No result gaph."); return; } if (runner instanceof GesRunner) { GraphScorer scorer = ((GesRunner) runner).getGraphScorer(); Graph _graph = ((GesRunner) 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(getAlgorithmRunner().getParams().getKnowledge()); 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 Pattern(graph)); Graph dag = search.patternToDagMeekRules(); 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); } }); menuBar.add(new LayoutMenu(this)); }