use of edu.cmu.tetradapp.workbench.GraphWorkbench in project tetrad by cmu-phil.
the class ScoredGraphsDisplay method setup.
private void setup() {
if (dagsToScores.isEmpty()) {
throw new IllegalArgumentException("Empty map.");
}
double max = Double.NEGATIVE_INFINITY;
for (Graph dag : dagsToScores.keySet()) {
if (dagsToScores.get(dag) > max)
max = dagsToScores.get(dag);
}
final List<Graph> dags = new ArrayList<>();
if (max != Double.NEGATIVE_INFINITY && showHighestScoreOnly) {
for (Graph dag : dagsToScores.keySet()) {
if (dagsToScores.get(dag) == max) {
dags.add(dag);
}
}
} else {
for (Graph dag : dagsToScores.keySet()) {
dags.add(dag);
}
}
if (max != Double.NEGATIVE_INFINITY) {
Collections.sort(dags, new Comparator<Graph>() {
public int compare(Graph graph, Graph graph1) {
return (int) Math.signum(dagsToScores.get(graph) - dagsToScores.get(graph1));
}
});
}
this.dags = dags;
if (dags.size() == 0) {
throw new IllegalArgumentException("No graphs to display.");
}
int index = -1;
Graph dag = scoredGraphsWrapper.getGraph();
if (dag == null) {
scoredGraphsWrapper.setSelectedGraph(dags.get(0));
dag = scoredGraphsWrapper.getGraph();
}
index = dags.indexOf(dag);
if (index == -1) {
dag = dags.get(0);
index = 0;
}
workbench = new GraphWorkbench(dag);
final SpinnerNumberModel model = new SpinnerNumberModel(index + 1, 1, dags.size(), 1);
model.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
int index = model.getNumber().intValue() - 1;
workbench.setGraph(dags.get(index));
if (scoredGraphsWrapper != null) {
scoredGraphsWrapper.setSelectedGraph(dags.get(index));
}
setScore(index - 1);
firePropertyChange("modelChanged", null, null);
}
});
final JSpinner spinner = new JSpinner();
spinner.setModel(model);
final JLabel totalLabel = new JLabel(" of " + dags.size() + " ");
scoreLabel = new JLabel();
setScore(dags.size() - 1);
spinner.setPreferredSize(new Dimension(50, 20));
spinner.setMaximumSize(spinner.getPreferredSize());
Box b = Box.createVerticalBox();
Box b1 = Box.createHorizontalBox();
b1.add(Box.createHorizontalGlue());
b1.add(new JLabel("DAG "));
b1.add(spinner);
b1.add(totalLabel);
b1.add(Box.createHorizontalGlue());
b1.add(new JLabel("Score = "));
b1.add(scoreLabel);
b1.add(Box.createHorizontalStrut(10));
b1.add(Box.createHorizontalGlue());
b1.add(new JButton(new CopySubgraphAction(this)));
b.add(b1);
Box b2 = Box.createHorizontalBox();
JPanel graphPanel = new JPanel();
graphPanel.setLayout(new BorderLayout());
JScrollPane jScrollPane = new JScrollPane(workbench);
jScrollPane.setPreferredSize(new Dimension(400, 400));
graphPanel.add(jScrollPane);
graphPanel.setBorder(new TitledBorder("Maximum Scoring DAGs in forbid_latent_common_causes"));
b2.add(graphPanel);
b.add(b2);
setLayout(new BorderLayout());
add(menuBar(), BorderLayout.NORTH);
add(b, BorderLayout.CENTER);
}
use of edu.cmu.tetradapp.workbench.GraphWorkbench in project tetrad by cmu-phil.
the class FofcSearchEditor method workbenchScroll.
private JScrollPane workbenchScroll(String resultLabel) {
Graph resultGraph = resultGraph();
Graph sourceGraph = getMimRunner().getSourceGraph();
Graph latestWorkbenchGraph = (Graph) getMimRunner().getParams().get("sourceGraph", null);
boolean arrangedAll = GraphUtils.arrangeBySourceGraph(resultGraph, latestWorkbenchGraph);
if (!arrangedAll) {
GraphUtils.arrangeBySourceGraph(resultGraph, sourceGraph);
}
this.workbench = new GraphWorkbench(resultGraph);
this.workbench.setAllowDoubleClickActions(false);
this.workbenchScroll = new JScrollPane(getWorkbench());
getWorkbenchScroll().setPreferredSize(new Dimension(450, 450));
getWorkbenchScroll().setBorder(new TitledBorder(resultLabel));
this.workbench.addMouseListener(new MouseAdapter() {
public void mouseExited(MouseEvent e) {
storeLatestWorkbenchGraph();
}
});
return getWorkbenchScroll();
}
use of edu.cmu.tetradapp.workbench.GraphWorkbench in project tetrad by cmu-phil.
the class FtfcSearchEditor method updateDisplayPanel.
private void updateDisplayPanel() {
displayPanel.removeAll();
JTabbedPane tabbedPane = new JTabbedPane();
if (getMimRunner().getStructureGraph() != null) {
if (getMimRunner().getStructureGraph() != null) {
// DataGraphUtils.circleLayout(structureGraph, 200, 200, 150);
Graph structureGraph = getMimRunner().getStructureGraph();
doDefaultArrangement(structureGraph);
GraphWorkbench structureWorkbench = new GraphWorkbench(structureGraph);
structureWorkbench.setAllowDoubleClickActions(false);
tabbedPane.add("Structure Model", new JScrollPane(structureWorkbench));
}
}
if (getMimRunner().getClusters() != null) {
ClusterEditor editor = new ClusterEditor(getMimRunner().getClusters(), getMimRunner().getData().getVariableNames());
tabbedPane.add("Measurement Model", editor);
}
if (getMimRunner().getFullGraph() != null) {
Graph fullGraph = getMimRunner().getFullGraph();
doDefaultArrangement(fullGraph);
GraphUtils.fruchtermanReingoldLayout(fullGraph);
GraphWorkbench fullGraphBench = new GraphWorkbench(fullGraph);
tabbedPane.add("Full Graph", new JScrollPane(fullGraphBench));
}
displayPanel.add(tabbedPane, BorderLayout.CENTER);
displayPanel.revalidate();
displayPanel.repaint();
}
use of edu.cmu.tetradapp.workbench.GraphWorkbench in project tetrad by cmu-phil.
the class FactorAnalysisAction method createDialog.
private JPanel createDialog(FactorAnalysis analysis) {
double threshold = .2;
TetradMatrix unrotatedSolution = analysis.successiveResidual();
TetradMatrix rotatedSolution = analysis.successiveFactorVarimax(unrotatedSolution);
DataSet dataSet = (DataSet) dataEditor.getSelectedDataModel();
NumberFormat nf = NumberFormatUtil.getInstance().getNumberFormat();
String output = "Unrotated Factor Loading Matrix:\n";
output += tableString(unrotatedSolution, nf, Double.POSITIVE_INFINITY);
if (unrotatedSolution.columns() != 1) {
output += "\n\nRotated Matrix (using sequential varimax):\n";
output += tableString(rotatedSolution, nf, threshold);
// temp = rotatedSolution.toString();
// temp = temp.split("\n", 2)[1];
// output += temp;
}
JTextArea display = new JTextArea(output);
JScrollPane scrollPane = new JScrollPane(display);
scrollPane.setPreferredSize(new Dimension(500, 400));
display.setEditable(false);
display.setFont(new Font("Monospaced", Font.PLAIN, 12));
// editorPanel.addPropertyChangeListener(new NormalityTestListener(display));
SemGraph graph = new SemGraph();
Vector<Node> observedVariables = new Vector<>();
for (Node a : dataSet.getVariables()) {
graph.addNode(a);
observedVariables.add(a);
}
Vector<Node> factors = new Vector<>();
for (int i = 0; i < rotatedSolution.columns(); i++) {
ContinuousVariable factor = new ContinuousVariable("Factor" + (i + 1));
factor.setNodeType(NodeType.LATENT);
graph.addNode(factor);
factors.add(factor);
}
for (int i = 0; i < rotatedSolution.rows(); i++) {
for (int j = 0; j < rotatedSolution.columns(); j++) {
if (Math.abs(rotatedSolution.get(i, j)) > threshold) {
graph.addDirectedEdge(factors.get(j), observedVariables.get(i));
// HEY JOE -- rotatedSolution.get(i, j) is the edge coeficient
}
}
}
GraphUtils.circleLayout(graph, 225, 200, 150);
GraphUtils.fruchtermanReingoldLayout(graph);
GraphWorkbench workbench = new GraphWorkbench(graph);
JScrollPane graphPane = new JScrollPane(workbench);
graphPane.setPreferredSize(new Dimension(500, 400));
Box box = Box.createHorizontalBox();
box.add(scrollPane);
box.add(Box.createHorizontalStrut(3));
// box.add(editorPanel);
box.add(Box.createHorizontalStrut(5));
box.add(Box.createHorizontalGlue());
Box vBox = Box.createVerticalBox();
vBox.add(Box.createVerticalStrut(15));
vBox.add(box);
vBox.add(Box.createVerticalStrut(5));
box.add(graphPane);
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(vBox, BorderLayout.CENTER);
return panel;
}
use of edu.cmu.tetradapp.workbench.GraphWorkbench 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);
}
Aggregations