use of edu.cmu.tetradapp.model.DataWrapper 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.tetradapp.model.DataWrapper 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;
}
use of edu.cmu.tetradapp.model.DataWrapper in project tetrad by cmu-phil.
the class PcSearchParamEditor method setup.
public void setup() {
/*
The variable names from the object being searched over (usually data).
*/
List<String> varNames = (List<String>) params.get("varNames", null);
DataModel dataModel1 = null;
Graph graph = null;
for (Object parentModel1 : this.parentModels) {
if (parentModel1 instanceof DataWrapper) {
DataWrapper dataWrapper = (DataWrapper) parentModel1;
dataModel1 = dataWrapper.getSelectedDataModel();
}
if (parentModel1 instanceof GraphWrapper) {
GraphWrapper graphWrapper = (GraphWrapper) parentModel1;
graph = graphWrapper.getGraph();
}
if (parentModel1 instanceof DagWrapper) {
DagWrapper dagWrapper = (DagWrapper) parentModel1;
graph = dagWrapper.getDag();
}
if (parentModel1 instanceof SemGraphWrapper) {
SemGraphWrapper semGraphWrapper = (SemGraphWrapper) parentModel1;
graph = semGraphWrapper.getGraph();
}
}
if (dataModel1 != null) {
varNames = new ArrayList<>(dataModel1.getVariableNames());
} else if (graph != null) {
Iterator<Node> it = graph.getNodes().iterator();
varNames = new ArrayList();
Node temp;
while (it.hasNext()) {
temp = it.next();
if (temp.getNodeType() == NodeType.MEASURED) {
varNames.add(temp.getName());
}
}
} else {
throw new NullPointerException("Null model (no graph or data model " + "passed to the search).");
}
this.params.set("varNames", varNames);
IntTextField depthField = new IntTextField(this.params.getInt("depth", -1), 4);
depthField.setFilter(new IntTextField.Filter() {
public int filter(int value, int oldValue) {
try {
PcSearchParamEditor.this.params.set("depth", value);
Preferences.userRoot().putInt("depth", value);
return value;
} catch (Exception e) {
return oldValue;
}
}
});
double alpha = params.getDouble("alpha", 0.001);
if (!Double.isNaN(alpha)) {
alphaField = new DoubleTextField(alpha, 4, NumberFormatUtil.getInstance().getNumberFormat());
alphaField.setFilter(new DoubleTextField.Filter() {
public double filter(double value, double oldValue) {
try {
PcSearchParamEditor.this.params.set("alpha", 0.001);
Preferences.userRoot().putDouble("alpha", value);
return value;
} catch (Exception e) {
return oldValue;
}
}
});
}
setBorder(new MatteBorder(10, 10, 10, 10, super.getBackground()));
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
if (!Double.isNaN(alpha)) {
Box b2 = Box.createHorizontalBox();
b2.add(new JLabel("Alpha Value:"));
b2.add(Box.createGlue());
b2.add(alphaField);
add(b2);
add(Box.createVerticalStrut(10));
}
Box b3 = Box.createHorizontalBox();
b3.add(new JLabel("Search Depth:"));
b3.add(Box.createGlue());
b3.add(depthField);
add(b3);
add(Box.createVerticalStrut(10));
}
use of edu.cmu.tetradapp.model.DataWrapper 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.tetradapp.model.DataWrapper 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