use of edu.cmu.tetrad.util.PointXy in project tetrad by cmu-phil.
the class GraphUtils method arrangeByLayout.
public static void arrangeByLayout(Graph graph, HashMap<String, PointXy> layout) {
for (Node node : graph.getNodes()) {
PointXy point = layout.get(node.getName());
node.setCenter(point.getX(), point.getY());
}
}
use of edu.cmu.tetrad.util.PointXy in project tetrad by cmu-phil.
the class TestPoint method testPoint.
@Test
public void testPoint() {
PointXy p = new PointXy(25, 50);
PointXy q = new PointXy(35, 55);
PointXy r = new PointXy(25, 50);
assertTrue(!p.equals(q));
assertEquals(p, r);
PointXy s = new PointXy(q);
assertEquals(q, s);
}
use of edu.cmu.tetrad.util.PointXy in project tetrad by cmu-phil.
the class TimeLagGraphEditor method createGraphMenu.
private JMenu createGraphMenu() {
JMenu graph = new JMenu("Graph");
graph.add(new GraphPropertiesAction(getWorkbench()));
graph.add(new PathsAction(getWorkbench()));
// graph.add(new DirectedPathsAction(getWorkbench()));
// graph.add(new TreksAction(getWorkbench()));
// graph.add(new AllPathsAction(getWorkbench()));
// graph.add(new NeighborhoodsAction(getWorkbench()));
graph.addSeparator();
JMenuItem correlateExogenous = new JMenuItem("Correlate Exogenous Variables");
JMenuItem uncorrelateExogenous = new JMenuItem("Uncorrelate Exogenous Variables");
graph.add(correlateExogenous);
graph.add(uncorrelateExogenous);
graph.addSeparator();
correlateExogenous.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
correlateExogenousVariables();
getWorkbench().invalidate();
getWorkbench().repaint();
}
});
uncorrelateExogenous.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
uncorrelationExogenousVariables();
getWorkbench().invalidate();
getWorkbench().repaint();
}
});
JMenuItem randomGraph = new JMenuItem("Random Graph");
graph.add(randomGraph);
randomGraph.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
RandomGraphEditor editor = new RandomGraphEditor(workbench.getGraph(), true, parameters);
int ret = JOptionPane.showConfirmDialog(TimeLagGraphEditor.this, editor, "Edit Random DAG Parameters", JOptionPane.PLAIN_MESSAGE);
if (ret == JOptionPane.OK_OPTION) {
Graph graph = null;
Graph dag = new Dag();
int numTrials = 0;
while (graph == null && ++numTrials < 100) {
if (editor.isRandomForward()) {
dag = GraphUtils.randomGraphRandomForwardEdges(getGraph().getNodes(), editor.getNumLatents(), editor.getMaxEdges(), 30, 15, 15, false, true);
GraphUtils.arrangeBySourceGraph(dag, getWorkbench().getGraph());
HashMap<String, PointXy> layout = GraphUtils.grabLayout(workbench.getGraph().getNodes());
GraphUtils.arrangeByLayout(dag, layout);
} else if (editor.isUniformlySelected()) {
if (getGraph().getNumNodes() == editor.getNumNodes()) {
HashMap<String, PointXy> layout = GraphUtils.grabLayout(workbench.getGraph().getNodes());
dag = GraphUtils.randomGraph(getGraph().getNodes(), editor.getNumLatents(), editor.getMaxEdges(), editor.getMaxDegree(), editor.getMaxIndegree(), editor.getMaxOutdegree(), editor.isConnected());
GraphUtils.arrangeBySourceGraph(dag, getWorkbench().getGraph());
GraphUtils.arrangeByLayout(dag, layout);
} else {
List<Node> nodes = new ArrayList<>();
for (int i = 0; i < editor.getNumNodes(); i++) {
nodes.add(new ContinuousVariable("X" + (i + 1)));
}
dag = GraphUtils.randomGraph(nodes, editor.getNumLatents(), editor.getMaxEdges(), editor.getMaxDegree(), editor.getMaxIndegree(), editor.getMaxOutdegree(), editor.isConnected());
}
} else {
do {
if (getGraph().getNumNodes() == editor.getNumNodes()) {
HashMap<String, PointXy> layout = GraphUtils.grabLayout(workbench.getGraph().getNodes());
dag = GraphUtils.randomDag(getGraph().getNodes(), editor.getNumLatents(), editor.getMaxEdges(), 30, 15, 15, editor.isConnected());
GraphUtils.arrangeByLayout(dag, layout);
} else {
List<Node> nodes = new ArrayList<>();
for (int i = 0; i < editor.getNumNodes(); i++) {
nodes.add(new ContinuousVariable("X" + (i + 1)));
}
dag = GraphUtils.randomGraph(nodes, editor.getNumLatents(), editor.getMaxEdges(), 30, 15, 15, editor.isConnected());
}
} while (dag.getNumEdges() < editor.getMaxEdges());
}
boolean addCycles = editor.isAddCycles();
if (addCycles) {
int minNumCycles = editor.getMinNumCycles();
int minCycleLength = editor.getMinCycleLength();
// graph = DataGraphUtils.addCycles2(dag, minNumCycles, minCycleLength);
graph = GraphUtils.cyclicGraph2(editor.getNumNodes(), editor.getMaxEdges(), 8);
GraphUtils.addTwoCycles(graph, editor.getMinNumCycles());
} else {
graph = new EdgeListGraph(dag);
}
}
if (graph == null) {
JOptionPane.showMessageDialog(TimeLagGraphEditor.this, "Could not find a graph that fits those constrains.");
getWorkbench().setGraph(new EdgeListGraph(dag));
} else {
getWorkbench().setGraph(graph);
}
// getWorkbench().setGraph(new EdgeListGraph(dag));
// getWorkbench().setGraph(graph);
}
}
});
JMenuItem randomIndicatorModel = new JMenuItem("Random Multiple Indicator Model");
graph.add(randomIndicatorModel);
randomIndicatorModel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
RandomMimParamsEditor editor = new RandomMimParamsEditor(parameters);
int ret = JOptionPane.showConfirmDialog(JOptionUtils.centeringComp(), editor, "Edit Random MIM Parameters", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
if (ret == JOptionPane.OK_OPTION) {
int numFactors = Preferences.userRoot().getInt("randomMimNumFactors", 1);
int numStructuralNodes = Preferences.userRoot().getInt("numStructuralNodes", 3);
int maxStructuralEdges = Preferences.userRoot().getInt("numStructuralEdges", 3);
int measurementModelDegree = Preferences.userRoot().getInt("measurementModelDegree", 3);
int numLatentMeasuredImpureParents = Preferences.userRoot().getInt("latentMeasuredImpureParents", 0);
int numMeasuredMeasuredImpureParents = Preferences.userRoot().getInt("measuredMeasuredImpureParents", 0);
int numMeasuredMeasuredImpureAssociations = Preferences.userRoot().getInt("measuredMeasuredImpureAssociations", 0);
Graph graph;
if (numFactors == 1) {
graph = DataGraphUtils.randomSingleFactorModel(numStructuralNodes, maxStructuralEdges, measurementModelDegree, numLatentMeasuredImpureParents, numMeasuredMeasuredImpureParents, numMeasuredMeasuredImpureAssociations);
} else if (numFactors == 2) {
graph = DataGraphUtils.randomBifactorModel(numStructuralNodes, maxStructuralEdges, measurementModelDegree, numLatentMeasuredImpureParents, numMeasuredMeasuredImpureParents, numMeasuredMeasuredImpureAssociations);
} else {
throw new IllegalArgumentException("Can only make random MIMs for 1 or 2 factors, " + "sorry dude.");
}
getWorkbench().setGraph(graph);
}
}
});
graph.addSeparator();
graph.add(new JMenuItem(new SelectBidirectedAction(getWorkbench())));
graph.add(new JMenuItem(new SelectUndirectedAction(getWorkbench())));
// graph.add(action);
return graph;
}
Aggregations