use of edu.cmu.tetrad.data.DataModel in project tetrad by cmu-phil.
the class MimbuildEditor method getIndTestParamBox.
/**
* Factory to return the correct param editor for independence test params.
* This will go in a little box in the search editor.
*/
private JComponent getIndTestParamBox(Parameters params) {
if (params == null) {
throw new NullPointerException();
}
if (params instanceof Parameters) {
MimRunner runner = getMimRunner();
params.set("varNames", runner.getParams().get("varNames", null));
DataModel dataModel = runner.getData();
if (dataModel instanceof DataSet) {
DataSet data = (DataSet) runner.getData();
boolean discrete = data.isDiscrete();
return new BuildPureClustersIndTestParamsEditor2(params, discrete);
} else if (dataModel instanceof ICovarianceMatrix) {
return new BuildPureClustersIndTestParamsEditor2(params, false);
}
}
if (params instanceof Parameters) {
MimRunner runner = getMimRunner();
params.set("varNames", runner.getParams().get("varNames", null));
boolean discreteData = false;
if (runner.getData() instanceof DataSet) {
discreteData = ((DataSet) runner.getData()).isDiscrete();
}
return new PurifyIndTestParamsEditor(params, discreteData);
}
if (params instanceof Parameters) {
MimRunner runner = getMimRunner();
params.set("varNames", runner.getParams().get("varNames", null));
return new MimBuildIndTestParamsEditor(params);
}
throw new IllegalArgumentException("Unrecognized Parameters: " + params.getClass());
}
use of edu.cmu.tetrad.data.DataModel in project tetrad by cmu-phil.
the class LofsSearchEditorNew method addSpecialMenus.
protected void addSpecialMenus(JMenuBar menuBar) {
if (!(getAlgorithmRunner() instanceof IGesRunner)) {
JMenu test = new JMenu("Independence");
menuBar.add(test);
IndTestMenuItems.addIndependenceTestChoices(test, this);
// test.addSeparator();
//
// AlgorithmRunner algorithmRunner = getAlgorithmRunner();
// if (algorithmRunner instanceof IndTestProducer) {
// IndTestProducer p = (IndTestProducer) algorithmRunner;
// IndependenceFactsAction action =
// new IndependenceFactsAction(this, p, "Independence Facts...");
// test.add(action);
// }
}
JMenu graph = new JMenu("Graph");
JMenuItem showDags = new JMenuItem("Show DAGs in forbid_latent_common_causes");
// JMenuItem meekOrient = new JMenuItem("Meek Orientation");
JMenuItem dagInPattern = new JMenuItem("Choose DAG in forbid_latent_common_causes");
JMenuItem gesOrient = new JMenuItem("Global Score-based Reorientation");
JMenuItem nextGraph = new JMenuItem("Next Graph");
JMenuItem previousGraph = new JMenuItem("Previous Graph");
graph.add(new GraphPropertiesAction(getWorkbench()));
graph.add(new PathsAction(getWorkbench()));
graph.add(new TriplesAction(getWorkbench().getGraph(), getAlgorithmRunner()));
graph.addSeparator();
// graph.add(meekOrient);
graph.add(dagInPattern);
graph.add(gesOrient);
graph.addSeparator();
graph.add(previousGraph);
graph.add(nextGraph);
graph.addSeparator();
graph.add(showDags);
graph.addSeparator();
graph.add(new JMenuItem(new SelectBidirectedAction(getWorkbench())));
graph.add(new JMenuItem(new SelectUndirectedAction(getWorkbench())));
menuBar.add(graph);
showDags.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Window owner = (Window) getTopLevelAncestor();
new WatchedProcess(owner) {
public void watch() {
// Needs to be a pattern search; this isn't checked
// before running the algorithm because of allowable
// "slop"--e.g. bidirected edges.
AlgorithmRunner runner = getAlgorithmRunner();
Graph graph = runner.getGraph();
if (graph == null) {
JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "No result gaph.");
return;
}
PatternDisplay display = new PatternDisplay(graph);
GraphWorkbench workbench = getWorkbench();
EditorWindow editorWindow = new EditorWindow(display, "Independence Facts", "Close", false, workbench);
DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER);
editorWindow.setVisible(true);
}
};
}
});
// meekOrient.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e) {
// ImpliedOrientation rules = getAlgorithmRunner().getMeekRules();
// rules.setKnowledge((IKnowledge) getAlgorithmRunner().getParams().get("knowledge", new Knowledge2()));
// rules.orientImplied(getGraph());
// getGraphHistory().add(getGraph());
// getWorkbench().setGraph(getGraph());
// firePropertyChange("modelChanged", null, null);
// }
// });
dagInPattern.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Graph graph = new EdgeListGraph(getGraph());
// Removing bidirected edges from the pattern before selecting a DAG. 4
for (Edge edge : graph.getEdges()) {
if (Edges.isBidirectedEdge(edge)) {
graph.removeEdge(edge);
}
}
PatternToDag search = new PatternToDag(new EdgeListGraphSingleConnections(graph));
Graph dag = search.patternToDagMeek();
getGraphHistory().add(dag);
getWorkbench().setGraph(dag);
((AbstractAlgorithmRunner) getAlgorithmRunner()).setResultGraph(dag);
firePropertyChange("modelChanged", null, null);
}
});
gesOrient.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DataModel dataModel = getAlgorithmRunner().getDataModel();
final Graph graph = SearchGraphUtils.reorient(getGraph(), dataModel, getKnowledge());
getGraphHistory().add(graph);
getWorkbench().setGraph(graph);
firePropertyChange("modelChanged", null, null);
}
});
nextGraph.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Graph next = getGraphHistory().next();
getWorkbench().setGraph(next);
((AbstractAlgorithmRunner) getAlgorithmRunner()).setResultGraph(next);
firePropertyChange("modelChanged", null, null);
}
});
previousGraph.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Graph previous = getGraphHistory().previous();
getWorkbench().setGraph(previous);
((AbstractAlgorithmRunner) getAlgorithmRunner()).setResultGraph(previous);
firePropertyChange("modelChanged", null, null);
}
});
menuBar.add(new LayoutMenu(this));
}
use of edu.cmu.tetrad.data.DataModel in project tetrad by cmu-phil.
the class RandomSamplerAction method actionPerformed.
/**
* Performs the action of loading a session from a file.
*/
public void actionPerformed(ActionEvent e) {
DataModel dataModel = getDataEditor().getSelectedDataModel();
if (dataModel instanceof DataSet) {
DataSet dataSet = (DataSet) dataModel;
if (dataSet.getNumRows() == 0) {
JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Data set is empty.");
return;
}
JComponent editor = editor();
int selection = JOptionPane.showOptionDialog(JOptionUtils.centeringComp(), editor, "Sample Size", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { "Done", "Cancel" }, "Done");
if (selection != 0) {
return;
}
try {
DataSet newDataSet = RandomSampler.sample(dataSet, getSampleSize());
DataModelList list = new DataModelList();
list.add(newDataSet);
getDataEditor().reset(list);
getDataEditor().selectFirstTab();
} catch (Exception e1) {
String s = e1.getMessage();
if (s == null || "".equals(s)) {
s = "Could not construct random sample.";
}
JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), s);
}
} else {
JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Must be a tabular data set.");
}
}
use of edu.cmu.tetrad.data.DataModel in project tetrad by cmu-phil.
the class RegressionParamsPanel method getVarsFromData.
private List<String> getVarsFromData(Object[] parentModels) {
DataModel dataModel = null;
for (Object parentModel : parentModels) {
if (parentModel instanceof DataWrapper) {
DataWrapper dataWrapper = (DataWrapper) parentModel;
dataModel = dataWrapper.getSelectedDataModel();
}
}
if (dataModel == null) {
return null;
} else {
return new ArrayList<>(dataModel.getVariableNames());
}
}
use of edu.cmu.tetrad.data.DataModel in project tetrad by cmu-phil.
the class PurifyParamsEditor method setVarNames.
private boolean setVarNames(Object[] parentModels, Parameters params) {
DataModel dataModel = null;
for (Object parentModel : parentModels) {
if (parentModel instanceof DataWrapper) {
DataWrapper dataWrapper = (DataWrapper) parentModel;
dataModel = dataWrapper.getSelectedDataModel();
}
}
boolean discreteModel;
if (dataModel instanceof ICovarianceMatrix) {
discreteModel = false;
} else {
DataSet dataSet = (DataSet) dataModel;
assert dataSet != null;
discreteModel = dataSet.isDiscrete();
// try {
// new DataSet((DataSet) dataModel);
// discreteModel = true;
// }
// catch (IllegalArgumentException e) {
// discreteModel = false;
// }
}
getParams().set("varNames", params.get("varNames", null));
return discreteModel;
}
Aggregations