Search in sources :

Example 46 with IKnowledge

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

the class CpcRunner method execute.

// ===================PUBLIC METHODS OVERRIDING ABSTRACT================//
public void execute() {
    IKnowledge knowledge = (IKnowledge) getParams().get("knowledge", new Knowledge2());
    if (trueGraph != null) {
        CpcOrienter orienter = new CpcOrienter(getIndependenceTest(), knowledge);
        Graph graph = GraphUtils.undirectedGraph(trueGraph);
        orienter.orient(graph);
        if (getSourceGraph() != null) {
            GraphUtils.arrangeBySourceGraph(graph, getSourceGraph());
        } else if (knowledge.isDefaultToKnowledgeLayout()) {
            SearchGraphUtils.arrangeByKnowledgeTiers(graph, knowledge);
        } else {
            GraphUtils.circleLayout(graph, 200, 200, 150);
        }
        setResultGraph(graph);
    } else {
        Cpc cpc = new Cpc(getIndependenceTest());
        cpc.setKnowledge(knowledge);
        cpc.setAggressivelyPreventCycles(this.isAggressivelyPreventCycles());
        cpc.setDepth(getParams().getInt("depth", -1));
        Graph graph = cpc.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);
        setCpcFields(cpc);
    }
}
Also used : IKnowledge(edu.cmu.tetrad.data.IKnowledge) Knowledge2(edu.cmu.tetrad.data.Knowledge2)

Example 47 with IKnowledge

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

the class KnowledgeBoxEditor method menuBar.

private JMenuBar menuBar() {
    JMenuBar menuBar = new JMenuBar();
    JMenu file = new JMenu("File");
    menuBar.add(file);
    JMenuItem load = new JMenuItem("Load");
    JMenuItem save = new JMenuItem("Save");
    file.add(load);
    file.add(save);
    load.addActionListener((e) -> {
        JFileChooser chooser = new JFileChooser();
        String sessionSaveLocation = Preferences.userRoot().get("fileSaveLocation", "");
        chooser.setCurrentDirectory(new File(sessionSaveLocation));
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        int ret1 = chooser.showOpenDialog(JOptionUtils.centeringComp());
        if (!(ret1 == JFileChooser.APPROVE_OPTION)) {
            return;
        }
        final File selectedFile = chooser.getSelectedFile();
        if (selectedFile == null) {
            return;
        }
        Preferences.userRoot().put("fileSaveLocation", selectedFile.getParent());
        try {
            IKnowledge knowledge = new DataReader().parseKnowledge(selectedFile);
            if (knowledge == null) {
                throw new NullPointerException("No knowledge found in this file. Perhaps the formatting is off");
            }
            setKnowledge(knowledge);
            resetTabbedPane(KnowledgeBoxEditor.this.tabbedPane);
        } catch (Exception e1) {
            JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), e1.getMessage());
            e1.printStackTrace();
        }
    });
    save.addActionListener((e) -> {
        JFileChooser chooser = new JFileChooser();
        String sessionSaveLocation = Preferences.userRoot().get("fileSaveLocation", "");
        chooser.setCurrentDirectory(new File(sessionSaveLocation));
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        int ret1 = chooser.showSaveDialog(JOptionUtils.centeringComp());
        if (!(ret1 == JFileChooser.APPROVE_OPTION)) {
            return;
        }
        final File selectedFile = chooser.getSelectedFile();
        if (selectedFile == null) {
            return;
        }
        Preferences.userRoot().put("fileSaveLocation", selectedFile.getParent());
        try {
            Knowledge.saveKnowledge(knowledgeBoxModel.getKnowledge(), new FileWriter(selectedFile));
        } catch (Exception e1) {
            JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), e1.getMessage());
        }
    });
    return menuBar;
}
Also used : IKnowledge(edu.cmu.tetrad.data.IKnowledge) DataReader(edu.cmu.tetrad.data.DataReader) JFileChooser(javax.swing.JFileChooser) FileWriter(java.io.FileWriter) JMenuItem(javax.swing.JMenuItem) File(java.io.File) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException)

Example 48 with IKnowledge

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

the class KnowledgeBoxEditor method textDisplay.

private Component textDisplay() {
    final JButton testButton = new JButton("Test");
    final JButton loadFromTextPaneButton = new JButton("Load from Text Pane");
    final JButton loadFromFileButton = new JButton("Load from File");
    testButton.addActionListener((e) -> {
        try {
            String text = getTextArea().getText();
            DataReader reader = new DataReader();
            reader.parseKnowledge(text.toCharArray());
            JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Looks good.");
        } catch (Exception e1) {
            JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), e1.getMessage());
        }
    });
    loadFromTextPaneButton.addActionListener((e) -> {
        try {
            String text = getTextArea().getText();
            DataReader reader = new DataReader();
            IKnowledge knowledge = reader.parseKnowledge(text.toCharArray());
            setKnowledge(knowledge);
            resetTabbedPane(KnowledgeBoxEditor.this.tabbedPane);
        } catch (Exception e1) {
            JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), e1.getMessage());
        }
    });
    loadFromFileButton.addActionListener((e) -> {
        JFileChooser chooser = new JFileChooser();
        String sessionSaveLocation = Preferences.userRoot().get("fileSaveLocation", "");
        chooser.setCurrentDirectory(new File(sessionSaveLocation));
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        int ret1 = chooser.showOpenDialog(JOptionUtils.centeringComp());
        if (!(ret1 == JFileChooser.APPROVE_OPTION)) {
            return;
        }
        final File file = chooser.getSelectedFile();
        if (file == null) {
            return;
        }
        Preferences.userRoot().put("fileSaveLocation", file.getParent());
        try {
            IKnowledge knowledge = new DataReader().parseKnowledge(file);
            setKnowledge(knowledge);
            resetTabbedPane(KnowledgeBoxEditor.this.tabbedPane);
        } catch (Exception e1) {
            JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), e1.getMessage());
        }
    });
    Box b = Box.createVerticalBox();
    textArea = new JTextArea();
    resetTextDisplay();
    b.add(getTextArea());
    Box b2 = Box.createHorizontalBox();
    b2.add(Box.createHorizontalGlue());
    b2.add(testButton);
    b2.add(loadFromTextPaneButton);
    b2.add(loadFromFileButton);
    b.add(b2);
    return b;
}
Also used : IKnowledge(edu.cmu.tetrad.data.IKnowledge) DataReader(edu.cmu.tetrad.data.DataReader) JTextArea(javax.swing.JTextArea) JFileChooser(javax.swing.JFileChooser) JButton(javax.swing.JButton) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) File(java.io.File) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException)

Example 49 with IKnowledge

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

the class GlassoSearchEditor 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) Graph(edu.cmu.tetrad.graph.Graph) GraphWorkbench(edu.cmu.tetradapp.workbench.GraphWorkbench) Knowledge2(edu.cmu.tetrad.data.Knowledge2)

Example 50 with IKnowledge

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

the class CopyKnowledgeAction method actionPerformed.

/**
 * Copies a parentally closed selection of session nodes in the frontmost
 * session editor to the clipboard.
 */
public void actionPerformed(ActionEvent e) {
    IKnowledge knowledge = knowledgeEditable.getKnowledge();
    KnowledgeSelection selection = new KnowledgeSelection(knowledge);
    InternalClipboard.getInstance().setContents(selection, this);
}
Also used : IKnowledge(edu.cmu.tetrad.data.IKnowledge)

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