Search in sources :

Example 31 with Parameters

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();
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) WatchedProcess(edu.cmu.tetradapp.util.WatchedProcess) Knowledge2(edu.cmu.tetrad.data.Knowledge2) IOException(java.io.IOException) CharArrayWriter(java.io.CharArrayWriter) IKnowledge(edu.cmu.tetrad.data.IKnowledge) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) PrintWriter(java.io.PrintWriter)

Example 32 with Parameters

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;
}
Also used : EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) Parameters(edu.cmu.tetrad.util.Parameters) MouseEvent(java.awt.event.MouseEvent) GraphWorkbench(edu.cmu.tetradapp.workbench.GraphWorkbench) MouseAdapter(java.awt.event.MouseAdapter)

Example 33 with Parameters

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.");
                }
            }
        }
    });
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) Node(edu.cmu.tetrad.graph.Node) HasCalculatorParams(edu.cmu.tetradapp.model.HasCalculatorParams) InternalFrameAdapter(javax.swing.event.InternalFrameAdapter) InternalFrameEvent(javax.swing.event.InternalFrameEvent) ArrayList(java.util.ArrayList) List(java.util.List) ParseException(java.text.ParseException)

Example 34 with Parameters

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);
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters)

Example 35 with Parameters

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);
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters)

Aggregations

Parameters (edu.cmu.tetrad.util.Parameters)134 Comparison (edu.cmu.tetrad.algcomparison.Comparison)30 Graph (edu.cmu.tetrad.graph.Graph)26 Algorithms (edu.cmu.tetrad.algcomparison.algorithm.Algorithms)25 DataSet (edu.cmu.tetrad.data.DataSet)22 Knowledge2 (edu.cmu.tetrad.data.Knowledge2)20 IKnowledge (edu.cmu.tetrad.data.IKnowledge)18 Simulations (edu.cmu.tetrad.algcomparison.simulation.Simulations)17 RandomForward (edu.cmu.tetrad.algcomparison.graph.RandomForward)14 ArrayList (java.util.ArrayList)14 SemBicScore (edu.cmu.tetrad.algcomparison.score.SemBicScore)13 Test (org.junit.Test)13 Node (edu.cmu.tetrad.graph.Node)11 ActionEvent (java.awt.event.ActionEvent)10 ActionListener (java.awt.event.ActionListener)10 Algorithm (edu.cmu.tetrad.algcomparison.algorithm.Algorithm)8 Fges (edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.Fges)8 DataModel (edu.cmu.tetrad.data.DataModel)8 TitledBorder (javax.swing.border.TitledBorder)8 FisherZ (edu.cmu.tetrad.algcomparison.independence.FisherZ)7