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);
}
}
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;
}
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;
}
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);
}
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);
}
Aggregations