use of edu.cmu.tetrad.data.DataSet 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.DataSet in project tetrad by cmu-phil.
the class PValueImproverEditor method setGraphWorkbench.
private void setGraphWorkbench(final GraphWorkbench graphWorkbench) {
JTabbedPane tabbedPane = new JTabbedPane();
this.graphWorkbench = graphWorkbench;
if (getOriginalSemIm() != null) {
setOriginalSemIm(new SemIm(getWrapper().getOriginalSemIm()));
}
this.newSemIm = getWrapper().getNewSemIm();
if (getNewSemIm() != null) {
SemImEditor newEditor = new SemImEditor(new SemImWrapper(getNewSemIm()));
final GraphWorkbench workbench = newEditor.getWorkbench();
workbench.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
if ("modelChanged".equals(propertyChangeEvent.getPropertyName())) {
System.out.println(propertyChangeEvent);
Graph graph = workbench.getGraph();
System.out.println(graph);
try {
new Dag(graph);
} catch (IllegalArgumentException e) {
return;
}
Scorer scorer = new DagScorer((DataSet) getWrapper().getDataModel());
scorer.score(graph);
getWrapper().setNewSemIm(scorer.getEstSem());
setGraphWorkbench(graphWorkbench);
}
}
});
tabbedPane.addTab("New Model", newEditor);
}
if (getOriginalSemIm() != null) {
SemImEditor originalEditor = new SemImEditor(new SemImWrapper(getOriginalSemIm()));
tabbedPane.addTab("Original Model", originalEditor);
}
if (graphWorkbench != null) {
tabbedPane.addTab("forbid_latent_common_causes", graphWorkbench);
}
panel.removeAll();
panel.add(tabbedPane, BorderLayout.CENTER);
panel.revalidate();
panel.repaint();
firePropertyChange("modelChanged", null, null);
}
use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.
the class LoadTimeSeriesDataAction method loadTimeSeriesDataSet.
/**
* Method loadDataSet_TabDelim
*/
private void loadTimeSeriesDataSet() {
// select a file to load using the file chooser
JFileChooser chooser = getJFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
chooser.showOpenDialog(this.editor);
// get the file
File file = chooser.getSelectedFile();
Preferences.userRoot().put("fileSaveLocation", file.getParent());
try {
BufferedReader in = new BufferedReader(new FileReader(file));
String line;
StringTokenizer st;
// read in variable name and set up DataSet.
List<Node> variables = new LinkedList<>();
st = new StringTokenizer(in.readLine());
while (st.hasMoreTokens()) {
String name = st.nextToken();
ContinuousVariable var = new ContinuousVariable(name);
variables.add(var);
}
DataSet dataSet = new ColtDataSet(0, variables);
int row = -1;
while ((line = in.readLine()) != null) {
int col = -1;
st = new StringTokenizer(line);
while (st.hasMoreTokens()) {
String literal = st.nextToken();
if (literal.length() == 0) {
continue;
}
dataSet.setObject(row, ++col, literal);
}
}
TimeSeriesData dataSet3 = new TimeSeriesData(dataSet.getDoubleData(), dataSet.getVariableNames());
editor.getDataWrapper().setDataModel(dataSet3);
firePropertyChange("modelChanged", null, null);
editor.reset();
} catch (Exception e) {
e.printStackTrace();
}
}
use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.
the class SemEstimatorEditor method reestimate.
private void reestimate() {
SemOptimizer optimizer;
String type = wrapper.getSemOptimizerType();
switch(type) {
case "Regression":
optimizer = new SemOptimizerRegression();
break;
case "EM":
optimizer = new SemOptimizerEm();
break;
case "Powell":
optimizer = new SemOptimizerPowell();
break;
case "Random Search":
optimizer = new SemOptimizerScattershot();
break;
case "RICF":
optimizer = new SemOptimizerRicf();
break;
default:
throw new IllegalArgumentException("Unexpected optimizer type: " + type);
}
int numRestarts = wrapper.getNumRestarts();
optimizer.setNumRestarts(numRestarts);
java.util.List<SemEstimator> estimators = wrapper.getMultipleResultList();
java.util.List<SemEstimator> newEstimators = new ArrayList<>();
estimators.forEach(estimator -> {
SemPm semPm = estimator.getSemPm();
DataSet dataSet = estimator.getDataSet();
ICovarianceMatrix covMatrix = estimator.getCovMatrix();
SemEstimator newEstimator;
if (dataSet != null) {
newEstimator = new SemEstimator(dataSet, semPm, optimizer);
newEstimator.setNumRestarts(numRestarts);
newEstimator.setScoreType(wrapper.getScoreType());
} else if (covMatrix != null) {
newEstimator = new SemEstimator(covMatrix, semPm, optimizer);
newEstimator.setNumRestarts(numRestarts);
newEstimator.setScoreType(wrapper.getScoreType());
} else {
throw new IllegalStateException("Only continuous rectangular" + " data sets and covariance matrices can be processed.");
}
newEstimator.estimate();
newEstimators.add(newEstimator);
});
wrapper.setSemEstimator(newEstimators.get(0));
wrapper.setMultipleResultList(newEstimators);
resetSemImEditor();
}
use of edu.cmu.tetrad.data.DataSet 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.");
}
}
Aggregations