Search in sources :

Example 11 with IKnowledge

use of edu.cmu.tetrad.data.IKnowledge in project tetrad by cmu-phil.

the class CpcLocalRunner method execute.

// ===================PUBLIC METHODS OVERRIDING ABSTRACT================//
public void execute() {
    IKnowledge knowledge = (IKnowledge) getParams().get("knowledge", new Knowledge2());
    IndependenceTest independenceTest = getIndependenceTest();
    Parameters testParams = getParams();
    CpcLocal search = new CpcLocal(independenceTest);
    search.setAggressivelyPreventCycles(isAggressivelyPreventCycles());
    search.setKnowledge(knowledge);
    Graph graph = search.search();
    if (getSourceGraph() != null) {
        GraphUtils.arrangeBySourceGraph(graph, getSourceGraph());
    } else if (knowledge.isDefaultToKnowledgeLayout()) {
        SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge);
    } else {
        GraphUtils.circleLayout(graph, 200, 200, 150);
    }
    setResultGraph(graph);
}
Also used : IKnowledge(edu.cmu.tetrad.data.IKnowledge) Parameters(edu.cmu.tetrad.util.Parameters) Knowledge2(edu.cmu.tetrad.data.Knowledge2)

Example 12 with IKnowledge

use of edu.cmu.tetrad.data.IKnowledge 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 13 with IKnowledge

use of edu.cmu.tetrad.data.IKnowledge 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 14 with IKnowledge

use of edu.cmu.tetrad.data.IKnowledge in project tetrad by cmu-phil.

the class LingSearchEditor 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
 */
public void execute() {
    Window owner = (Window) getTopLevelAncestor();
    final WatchedProcess process = new WatchedProcess(owner) {

        public void watch() {
            getExecuteButton().setEnabled(false);
            setErrorMessage(null);
            if (!knowledgeMessageShown) {
                IKnowledge knowledge = (IKnowledge) getAlgorithmRunner().getParams().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();
                LingRunner runner = (LingRunner) getAlgorithmRunner();
                arrangeGraphs();
                lingDisplay.resetGraphs(runner.getStoredGraphs());
            } 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 : WatchedProcess(edu.cmu.tetradapp.util.WatchedProcess) Knowledge2(edu.cmu.tetrad.data.Knowledge2) TitledBorder(javax.swing.border.TitledBorder) CharArrayWriter(java.io.CharArrayWriter) IKnowledge(edu.cmu.tetrad.data.IKnowledge) LingRunner(edu.cmu.tetradapp.model.LingRunner) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) Graph(edu.cmu.tetrad.graph.Graph) PrintWriter(java.io.PrintWriter)

Example 15 with IKnowledge

use of edu.cmu.tetrad.data.IKnowledge in project tetrad by cmu-phil.

the class FciCcdSearchEditor 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);
}
Also used : IKnowledge(edu.cmu.tetrad.data.IKnowledge) GraphWorkbench(edu.cmu.tetradapp.workbench.GraphWorkbench) Knowledge2(edu.cmu.tetrad.data.Knowledge2)

Aggregations

IKnowledge (edu.cmu.tetrad.data.IKnowledge)58 Knowledge2 (edu.cmu.tetrad.data.Knowledge2)46 Parameters (edu.cmu.tetrad.util.Parameters)18 Graph (edu.cmu.tetrad.graph.Graph)12 ArrayList (java.util.ArrayList)10 GraphWorkbench (edu.cmu.tetradapp.workbench.GraphWorkbench)8 IOException (java.io.IOException)7 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)5 CharArrayWriter (java.io.CharArrayWriter)5 DataReader (edu.cmu.tetrad.data.DataReader)4 DataSet (edu.cmu.tetrad.data.DataSet)4 Node (edu.cmu.tetrad.graph.Node)4 WatchedProcess (edu.cmu.tetradapp.util.WatchedProcess)4 File (java.io.File)4 PrintWriter (java.io.PrintWriter)4 List (java.util.List)4 KnowledgeBoxInput (edu.cmu.tetrad.data.KnowledgeBoxInput)3 KnowledgeEdge (edu.cmu.tetrad.data.KnowledgeEdge)3 Test (org.junit.Test)3 BdeuScore (edu.cmu.tetrad.algcomparison.score.BdeuScore)2