use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.
the class SemSimulation method createData.
@Override
public void createData(Parameters parameters) {
Graph graph = randomGraph.createGraph(parameters);
dataSets = new ArrayList<>();
graphs = new ArrayList<>();
ims = new ArrayList<>();
for (int i = 0; i < parameters.getInt("numRuns"); i++) {
System.out.println("Simulating dataset #" + (i + 1));
if (parameters.getBoolean("differentGraphs") && i > 0) {
graph = randomGraph.createGraph(parameters);
}
graphs.add(graph);
DataSet dataSet = simulate(graph, parameters);
if (parameters.getBoolean("standardize")) {
dataSet = DataUtils.standardizeData(dataSet);
}
double variance = parameters.getDouble("measurementVariance");
if (variance > 0) {
for (int k = 0; k < dataSet.getNumRows(); k++) {
for (int j = 0; j < dataSet.getNumColumns(); j++) {
double d = dataSet.getDouble(k, j);
double norm = RandomUtil.getInstance().nextNormal(0, Math.sqrt(variance));
dataSet.setDouble(k, j, d + norm);
}
}
}
if (parameters.getBoolean("randomizeColumns")) {
dataSet = DataUtils.reorderColumns(dataSet);
}
dataSet.setName("" + (i + 1));
dataSets.add(dataSet);
}
}
use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.
the class BayesNetSimulation method createData.
@Override
public void createData(Parameters parameters) {
Graph graph = randomGraph.createGraph(parameters);
dataSets = new ArrayList<>();
graphs = new ArrayList<>();
for (int i = 0; i < parameters.getInt("numRuns"); i++) {
System.out.println("Simulating dataset #" + (i + 1));
if (parameters.getBoolean("differentGraphs") && i > 0) {
graph = randomGraph.createGraph(parameters);
}
graphs.add(graph);
DataSet dataSet = simulate(graph, parameters);
dataSet.setName("" + (i + 1));
dataSets.add(dataSet);
}
}
use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.
the class SemThenDiscretize method createData.
@Override
public void createData(Parameters parameters) {
double percentDiscrete = parameters.getDouble("percentDiscrete");
boolean discrete = parameters.getString("dataType").equals("discrete");
boolean continuous = parameters.getString("dataType").equals("continuous");
if (discrete && percentDiscrete != 100.0) {
throw new IllegalArgumentException("To simulate discrete data, 'percentDiscrete' must be set to 0.0.");
} else if (continuous && percentDiscrete != 0.0) {
throw new IllegalArgumentException("To simulate continuoue data, 'percentDiscrete' must be set to 100.0.");
}
if (discrete)
this.dataType = DataType.Discrete;
if (continuous)
this.dataType = DataType.Continuous;
dataSets = new ArrayList<>();
shuffledOrder = null;
Graph graph = randomGraph.createGraph(parameters);
dataSets = new ArrayList<>();
graphs = new ArrayList<>();
for (int i = 0; i < parameters.getInt("numRuns"); i++) {
System.out.println("Simulating dataset #" + (i + 1));
if (parameters.getBoolean("differentGraphs") && i > 0) {
graph = randomGraph.createGraph(parameters);
}
graphs.add(graph);
DataSet dataSet = simulate(graph, parameters);
dataSet.setName("" + (i + 1));
dataSets.add(dataSet);
}
}
use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.
the class BuildPureClustersParamsEditor method setup.
public void setup() {
DoubleTextField alphaField = new DoubleTextField(params.getDouble("alpha", 0.001), 4, NumberFormatUtil.getInstance().getNumberFormat());
alphaField.setFilter(new DoubleTextField.Filter() {
public double filter(double value, double oldValue) {
try {
getParams().set("alpha", 0.001);
return value;
} catch (Exception e) {
return oldValue;
}
}
});
final TestType[] descriptions = TestType.getTestDescriptions();
JComboBox testSelector = new JComboBox(descriptions);
testSelector.setSelectedItem(getParams().get("tetradTestType", TestType.TETRAD_WISHART));
testSelector.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox combo = (JComboBox) e.getSource();
TestType testType = (TestType) combo.getSelectedItem();
getParams().set("tetradTestType", testType);
}
});
final TestType[] purifyDescriptions = TestType.getPurifyTestDescriptions();
JComboBox purifySelector = new JComboBox(purifyDescriptions);
purifySelector.setSelectedItem(getParams().get("purifyTestType", TestType.NONE));
purifySelector.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JComboBox combo = (JComboBox) e.getSource();
TestType testType = (TestType) combo.getSelectedItem();
getParams().set("purifyTestType", testType);
}
});
// Where is it setting the appropriate knowledge for the search?
DataModel dataModel = null;
for (Object parentModel : this.parentModels) {
if (parentModel instanceof DataWrapper) {
DataWrapper dataWrapper = (DataWrapper) parentModel;
dataModel = dataWrapper.getSelectedDataModel();
}
}
if (dataModel == null) {
throw new IllegalStateException("Null data model.");
}
List<String> varNames = new ArrayList<>(dataModel.getVariableNames());
boolean isDiscreteModel;
if (dataModel instanceof ICovarianceMatrix) {
isDiscreteModel = false;
} else {
DataSet dataSet = (DataSet) dataModel;
isDiscreteModel = dataSet.isDiscrete();
// try {
// new DataSet((DataSet) dataModel);
// isDiscreteModel = true;
// }
// catch (IllegalArgumentException e) {
// isDiscreteModel = false;
// }
}
params.set("varNames", varNames);
alphaField.setValue(params.getDouble("alpha", 0.001));
Box b = Box.createVerticalBox();
Box b1 = Box.createHorizontalBox();
b1.add(new JLabel("Alpha:"));
b1.add(Box.createHorizontalGlue());
b1.add(alphaField);
b.add(b1);
if (!isDiscreteModel) {
Box b2 = Box.createHorizontalBox();
b2.add(new JLabel("Statistical Test:"));
b2.add(Box.createHorizontalGlue());
b2.add(testSelector);
b.add(b2);
Box b3 = Box.createHorizontalBox();
b3.add(new JLabel("Purify Test:"));
b3.add(Box.createHorizontalGlue());
b3.add(purifySelector);
b.add(b3);
} else {
this.params.set("purifyTestType", TestType.DISCRETE_LRT);
this.params.set("tetradTestType", TestType.DISCRETE);
}
setLayout(new BorderLayout());
add(b, BorderLayout.CENTER);
}
use of edu.cmu.tetrad.data.DataSet in project tetrad by cmu-phil.
the class CalculatorEditor method setParentModels.
/**
* Grabs the data set that the calculator is working on.
*/
public void setParentModels(Object[] parentModels) {
if (parentModels == null || parentModels.length == 0) {
throw new IllegalArgumentException("There must be parent model");
}
DataWrapper data = null;
for (Object parent : parentModels) {
if (parent instanceof DataWrapper) {
data = (DataWrapper) parent;
}
}
if (data == null) {
throw new IllegalArgumentException("Should have have a data wrapper as a parent");
}
DataModel model = data.getSelectedDataModel();
if (!(model instanceof DataSet)) {
throw new IllegalArgumentException("The data must be tabular");
}
this.dataSet = (DataSet) model;
}
Aggregations