use of edu.cmu.tetradapp.ui.model.ScoreModels in project tetrad by cmu-phil.
the class GeneralAlgorithmEditor method refreshScoreList.
private void refreshScoreList() {
updatingScoreModels = true;
scoreComboBox.removeAllItems();
AlgorithmModel algoModel = algorithmList.getSelectedValue();
if (algoModel != null && algoModel.isRequiredScore()) {
boolean linear = linearVarChkBox.isSelected();
boolean gaussian = gaussianVarChkBox.isSelected();
List<ScoreModel> models = ScoreModels.getInstance().getModels(dataType);
List<ScoreModel> scoreModels = new LinkedList<>();
if (linear && gaussian) {
models.stream().filter(e -> e.getScore().getClazz().isAnnotationPresent(Linear.class)).filter(e -> e.getScore().getClazz().isAnnotationPresent(Gaussian.class)).forEach(e -> scoreModels.add(e));
} else if (linear) {
models.stream().filter(e -> e.getScore().getClazz().isAnnotationPresent(Linear.class)).filter(e -> !e.getScore().getClazz().isAnnotationPresent(Gaussian.class)).forEach(e -> scoreModels.add(e));
} else if (gaussian) {
models.stream().filter(e -> !e.getScore().getClazz().isAnnotationPresent(Linear.class)).filter(e -> e.getScore().getClazz().isAnnotationPresent(Gaussian.class)).forEach(e -> scoreModels.add(e));
} else {
models.stream().forEach(e -> scoreModels.add(e));
}
// or BDeu score for discrete data
if (TsImages.class.equals(algoModel.getAlgorithm().getClazz())) {
switch(dataType) {
case Continuous:
scoreModels.stream().filter(e -> e.getScore().getClazz().equals(SemBicScore.class)).forEach(e -> scoreComboBox.addItem(e));
break;
case Discrete:
scoreModels.stream().filter(e -> e.getScore().getClazz().equals(BdeuScore.class)).forEach(e -> scoreComboBox.addItem(e));
break;
}
} else {
scoreModels.forEach(e -> scoreComboBox.addItem(e));
}
}
updatingScoreModels = false;
if (scoreComboBox.getItemCount() > 0) {
scoreComboBox.setEnabled(true);
Map<DataType, ScoreModel> map = defaultScoreModels.get(algoModel);
if (map == null) {
map = new EnumMap<>(DataType.class);
defaultScoreModels.put(algoModel, map);
}
ScoreModel scoreModel = map.get(dataType);
if (scoreModel == null) {
scoreModel = ScoreModels.getInstance().getDefaultModel(dataType);
if (scoreModel == null) {
scoreModel = scoreComboBox.getItemAt(0);
}
}
scoreComboBox.setSelectedItem(scoreModel);
} else {
scoreComboBox.setEnabled(false);
}
}
Aggregations