use of edu.cmu.tetrad.data.DataType in project tetrad by cmu-phil.
the class GeneralAlgorithmEditor method refreshTestList.
private void refreshTestList() {
updatingTestModels = true;
indTestComboBox.removeAllItems();
AlgorithmModel algoModel = algorithmList.getSelectedValue();
if (algoModel != null && algoModel.isRequiredTest()) {
boolean linear = linearVarChkBox.isSelected();
boolean gaussian = gaussianVarChkBox.isSelected();
List<IndependenceTestModel> models = IndependenceTestModels.getInstance().getModels(dataType);
if (linear && gaussian) {
models.stream().filter(e -> e.getIndependenceTest().getClazz().isAnnotationPresent(Linear.class)).filter(e -> e.getIndependenceTest().getClazz().isAnnotationPresent(Gaussian.class)).forEach(e -> indTestComboBox.addItem(e));
} else if (linear) {
models.stream().filter(e -> e.getIndependenceTest().getClazz().isAnnotationPresent(Linear.class)).filter(e -> !e.getIndependenceTest().getClazz().isAnnotationPresent(Gaussian.class)).forEach(e -> indTestComboBox.addItem(e));
} else if (gaussian) {
models.stream().filter(e -> !e.getIndependenceTest().getClazz().isAnnotationPresent(Linear.class)).filter(e -> e.getIndependenceTest().getClazz().isAnnotationPresent(Gaussian.class)).forEach(e -> indTestComboBox.addItem(e));
} else {
models.stream().forEach(e -> indTestComboBox.addItem(e));
}
}
updatingTestModels = false;
if (indTestComboBox.getItemCount() > 0) {
indTestComboBox.setEnabled(true);
Map<DataType, IndependenceTestModel> map = defaultIndTestModels.get(algoModel);
if (map == null) {
map = new EnumMap<>(DataType.class);
defaultIndTestModels.put(algoModel, map);
}
IndependenceTestModel testModel = map.get(dataType);
if (testModel == null) {
testModel = IndependenceTestModels.getInstance().getDefaultModel(dataType);
if (testModel == null) {
testModel = indTestComboBox.getItemAt(0);
}
}
indTestComboBox.setSelectedItem(testModel);
} else {
indTestComboBox.setEnabled(false);
}
}
use of edu.cmu.tetrad.data.DataType in project tetrad by cmu-phil.
the class IndependenceTestModels method initModelMap.
private void initModelMap() {
// initialize enum map
DataType[] dataTypes = DataType.values();
for (DataType dataType : dataTypes) {
modelMap.put(dataType, new LinkedList<>());
}
// group by datatype
models.stream().forEach(e -> {
DataType[] types = e.getIndependenceTest().getAnnotation().dataType();
for (DataType dataType : types) {
modelMap.get(dataType).add(e);
}
});
// merge continuous datatype with mixed datatype
List<IndependenceTestModel> mergedModels = Stream.concat(modelMap.get(DataType.Continuous).stream(), modelMap.get(DataType.Mixed).stream()).sorted().collect(Collectors.toList());
modelMap.put(DataType.Continuous, mergedModels);
// merge discrete datatype with mixed datatype
mergedModels = Stream.concat(modelMap.get(DataType.Discrete).stream(), modelMap.get(DataType.Mixed).stream()).sorted().collect(Collectors.toList());
modelMap.put(DataType.Discrete, mergedModels);
// make map values unmodifiable
modelMap.forEach((k, v) -> modelMap.put(k, Collections.unmodifiableList(v)));
}
use of edu.cmu.tetrad.data.DataType in project tetrad by cmu-phil.
the class ScoreModels method initDefaultModelMap.
private void initDefaultModelMap() {
DataType[] dataTypes = DataType.values();
for (DataType dataType : dataTypes) {
List<ScoreModel> list = getModels(dataType);
if (!list.isEmpty()) {
String property = getProperty(dataType);
if (property == null) {
defaultModelMap.put(dataType, list.get(0));
} else {
String value = TetradProperties.getInstance().getValue(property);
if (value == null) {
defaultModelMap.put(dataType, list.get(0));
} else {
Optional<ScoreModel> result = list.stream().filter(e -> e.getScore().getClazz().getName().equals(value)).findFirst();
defaultModelMap.put(dataType, result.isPresent() ? result.get() : list.get(0));
}
}
}
}
}
use of edu.cmu.tetrad.data.DataType in project tetrad by cmu-phil.
the class ScoreModels method initModelMap.
private void initModelMap() {
// initialize enum map
DataType[] dataTypes = DataType.values();
for (DataType dataType : dataTypes) {
modelMap.put(dataType, new LinkedList<>());
}
// group by datatype
models.stream().forEach(e -> {
DataType[] types = e.getScore().getAnnotation().dataType();
for (DataType dataType : types) {
modelMap.get(dataType).add(e);
}
});
// merge continuous datatype with mixed datatype
List<ScoreModel> mergedModels = Stream.concat(modelMap.get(DataType.Continuous).stream(), modelMap.get(DataType.Mixed).stream()).sorted().collect(Collectors.toList());
modelMap.put(DataType.Continuous, mergedModels);
// merge discrete datatype with mixed datatype
mergedModels = Stream.concat(modelMap.get(DataType.Discrete).stream(), modelMap.get(DataType.Mixed).stream()).sorted().collect(Collectors.toList());
modelMap.put(DataType.Discrete, mergedModels);
// make map values unmodifiable
modelMap.forEach((k, v) -> modelMap.put(k, Collections.unmodifiableList(v)));
}
Aggregations