Program: 143989
Project: 143989
Buggy source:
private ExperimentResults runExperiment(){
  logger.info("String_Node_Str");
  Map<Label,DataSet<PredictedDataInstance<Vector,Double>>> classifierDataSet=new HashMap<>();
  Map<Label,DataSet<PredictedDataInstance<Vector,Double>>> testingDataSet=new HashMap<>();
  Map<DataInstance<Vector>,Map<Label,Double>> selectionDataSet=new HashMap<>();
  for (  Label label : labels) {
    DataSet<PredictedDataInstance<Vector,Double>> classifierDataSetCopy=new DataSetInMemory<>();
    DataSet<PredictedDataInstance<Vector,Double>> testingDataSetCopy=new DataSetInMemory<>();
    for (    PredictedDataInstance<Vector,Double> instance : predictedDataSet.get(label)) {
      classifierDataSetCopy.add(new PredictedDataInstance<>(instance.name(),instance.features(),instance.label(),instance.source(),instance.probability()));
      testingDataSetCopy.add(new PredictedDataInstance<>(instance.name(),instance.features(),instance.label(),instance.source(),instance.probability()));
    }
    classifierDataSet.put(label,classifierDataSetCopy);
    testingDataSet.put(label,testingDataSetCopy);
  }
  for (  Map.Entry<Label,DataSet<PredictedDataInstance<Vector,Double>>> instanceEntry : classifierDataSet.entrySet())   for (  PredictedDataInstance<Vector,Double> predictedInstance : instanceEntry.getValue()) {
    DataInstance<Vector> instance=new DataInstance<>(predictedInstance.name(),predictedInstance.features());
    if (!selectionDataSet.containsKey(instance))     selectionDataSet.put(instance,new HashMap<>());
    selectionDataSet.get(instance).put(instanceEntry.getKey(),predictedInstance.probability());
  }
  final long experimentStartTime=System.currentTimeMillis();
  ExperimentResults results=new ExperimentResults();
  Map<DataInstance<Vector>,Map<Label,Boolean>> activeLearningDataSet=new HashMap<>();
  for (  DataInstance<Vector> instance : dataSet.keySet())   activeLearningDataSet.put(instance,new HashMap<>());
  ConstrainedLearning.Builder learningBuilder=new ConstrainedLearning.Builder(activeLearningDataSet).activeLearningMethod(activeLearningMethod).addConstraints(constraints.getConstraints());
  learningBuilder.addLabels(labels);
  Learning learning=learningBuilder.build();
  int numberOfExamplesPicked=0;
  int previousNumberOfExamplesPicked=0;
  int iterationNumber=0;
  while (true) {
    PrecisionRecall<Vector,Double> fullPrecisionRecall=new PrecisionRecall<>(1000);
    PrecisionRecall<Vector,Double> testingPrecisionRecall=new PrecisionRecall<>(1000);
    labels.stream().forEach(label -> {
      if (resultTypes.contains(ResultType.AVERAGE_AUC_FULL_DATA_SET))       fullPrecisionRecall.addResult(label.getName(),classifierDataSet.get(label),dataInstance -> dataSet.get(new DataInstance<>(dataInstance.name(),dataInstance.features())).get(label));
      if (resultTypes.contains(ResultType.AVERAGE_AUC_TESTING_DATA_SET))       testingPrecisionRecall.addResult(label.getName(),testingDataSet.get(label),dataInstance -> dataSet.get(new DataInstance<>(dataInstance.name(),dataInstance.features())).get(label));
    }
);
    if (resultTypes.contains(ResultType.AVERAGE_AUC_FULL_DATA_SET))     results.averageAreasUnderTheCurve.put(iterationNumber,fullPrecisionRecall.getAreaUnderCurves().stream().mapToDouble(area -> area == null ? 0.0 : area.isNaN() ? 0.0 : area).average().orElse(0));
    if (resultTypes.contains(ResultType.AVERAGE_AUC_TESTING_DATA_SET))     results.averageTestingAreasUnderTheCurve.put(iterationNumber,testingPrecisionRecall.getAreaUnderCurves().stream().mapToDouble(area -> area == null ? 0.0 : area.isNaN() ? 0.0 : area).average().orElse(0));
    if (resultTypes.contains(ResultType.NUMBER_OF_EXAMPLES_PICKED))     results.numberOfExamplesPicked.put(iterationNumber,numberOfExamplesPicked);
    final long startTime=System.nanoTime();
switch (examplePickingMethod) {
case BATCH:
      List<Learning.InstanceToLabel> selectedInstances=learning.pickInstancesToLabel(selectionDataSet,numberOfExamplesToPickPerIteration);
    for (    Learning.InstanceToLabel instance : selectedInstances) {
      boolean trueLabel=dataSet.get(instance.getInstance()).get(instance.getLabel());
      Map<Label,Boolean> fixedLabels=new HashMap<>(learning.getLabels(instance.getInstance()));
      learning.labelInstance(instance,trueLabel);
      Map<Label,Boolean> newFixedLabels=new HashMap<>(learning.getLabels(instance.getInstance()));
      fixedLabels.keySet().forEach(newFixedLabels::remove);
      for (      Map.Entry<Label,Boolean> instanceLabelEntry : fixedLabels.entrySet()) {
        for (        PredictedDataInstance<Vector,Double> predictedInstance : classifierDataSet.get(instanceLabelEntry.getKey()))         if (predictedInstance.name().equals(instance.getInstance().name())) {
          testingDataSet.get(instanceLabelEntry.getKey()).remove(predictedInstance);
          predictedInstance.label(1.0);
          predictedInstance.probability(instanceLabelEntry.getValue() ? 1.0 : 0.0);
          selectionDataSet.get(new DataInstance<>(predictedInstance.name(),predictedInstance.features())).remove(instanceLabelEntry.getKey());
          break;
        }
      }
    }
  numberOfExamplesPicked+=selectedInstances.size();
break;
case PSEUDO_SEQUENTIAL:
for (int exampleNumber=0; exampleNumber < numberOfExamplesToPickPerIteration; exampleNumber++) {
Learning.InstanceToLabel instance=learning.pickInstanceToLabel(selectionDataSet);
if (instance == null) break;
boolean trueLabel=dataSet.get(instance.getInstance()).get(instance.getLabel());
Map<Label,Boolean> fixedLabels=new HashMap<>(learning.getLabels(instance.getInstance()));
learning.labelInstance(instance,trueLabel);
Map<Label,Boolean> newFixedLabels=new HashMap<>(learning.getLabels(instance.getInstance()));
fixedLabels.keySet().forEach(newFixedLabels::remove);
for (PredictedDataInstance<Vector,Double> predictedInstance : classifierDataSet.get(instance.getLabel())) if (predictedInstance.name().equals(instance.getInstance().name())) {
  for (  Map.Entry<Label,Boolean> instanceLabelEntry : fixedLabels.entrySet()) {
    testingDataSet.get(instanceLabelEntry.getKey()).remove(predictedInstance);
    predictedInstance.label(1.0);
    predictedInstance.probability(instanceLabelEntry.getValue() ? 1.0 : 0.0);
  }
  break;
}
selectionDataSet.get(instance.getInstance()).remove(instance.getLabel());
numberOfExamplesPicked++;
}
break;
}
final long endTime=System.nanoTime();
if (resultTypes.contains(ResultType.ACTIVE_LEARNING_METHOD_TIMES)) results.activeLearningMethodTimesTaken.put(iterationNumber,endTime - startTime);
if (numberOfExamplesPicked == previousNumberOfExamplesPicked || ++iterationNumber >= maximumNumberOfIterations) break;
previousNumberOfExamplesPicked=numberOfExamplesPicked;
}
final long experimentEndTime=System.currentTimeMillis();
results.timeTaken=experimentEndTime - experimentStartTime;
return results;
}

Fixed version (ground truth):
private ExperimentResults runExperiment(){
  logger.info("String_Node_Str");
  Map<Label,DataSet<PredictedDataInstance<Vector,Double>>> classifierDataSet=new HashMap<>();
  Map<Label,DataSet<PredictedDataInstance<Vector,Double>>> testingDataSet=new HashMap<>();
  for (  Label label : labels) {
    DataSet<PredictedDataInstance<Vector,Double>> classifierDataSetCopy=new DataSetInMemory<>();
    DataSet<PredictedDataInstance<Vector,Double>> testingDataSetCopy=new DataSetInMemory<>();
    for (    PredictedDataInstance<Vector,Double> instance : predictedDataSetInstances.get(label)) {
      classifierDataSetCopy.add(new PredictedDataInstance<>(instance.name(),instance.features(),instance.label(),instance.source(),instance.probability()));
      testingDataSetCopy.add(new PredictedDataInstance<>(instance.name(),instance.features(),instance.label(),instance.source(),instance.probability()));
    }
    classifierDataSet.put(label,classifierDataSetCopy);
    testingDataSet.put(label,testingDataSetCopy);
  }
  final long experimentStartTime=System.currentTimeMillis();
  ExperimentResults results=new ExperimentResults();
  Map<DataInstance<Vector>,Map<Label,Boolean>> activeLearningDataSet=new HashMap<>();
  for (  DataInstance<Vector> instance : dataSet.keySet())   activeLearningDataSet.put(instance,new HashMap<>());
  ConstrainedLearning.Builder learningBuilder=new ConstrainedLearning.Builder(activeLearningDataSet,instanceToLabel -> predictedDataSet.get(instanceToLabel.getInstance()).get(instanceToLabel.getLabel())).activeLearningMethod(activeLearningMethod).addConstraints(constraints.getConstraints());
  learningBuilder.addLabels(labels);
  Learning learning=learningBuilder.build();
  for (  Map.Entry<Label,DataSet<PredictedDataInstance<Vector,Double>>> instanceEntry : classifierDataSet.entrySet())   for (  PredictedDataInstance<Vector,Double> predictedInstance : instanceEntry.getValue())   learning.addInstanceToLabel(new DataInstance<>(predictedInstance.name(),predictedInstance.features()),instanceEntry.getKey());
  int numberOfExamplesPicked=0;
  int previousNumberOfExamplesPicked=0;
  int iterationNumber=0;
  while (true) {
    PrecisionRecall<Vector,Double> fullPrecisionRecall=new PrecisionRecall<>(1000);
    PrecisionRecall<Vector,Double> testingPrecisionRecall=new PrecisionRecall<>(1000);
    labels.stream().forEach(label -> {
      if (resultTypes.contains(ResultType.AVERAGE_AUC_FULL_DATA_SET))       fullPrecisionRecall.addResult(label.getName(),classifierDataSet.get(label),dataInstance -> dataSet.get(new DataInstance<>(dataInstance.name(),dataInstance.features())).get(label));
      if (resultTypes.contains(ResultType.AVERAGE_AUC_TESTING_DATA_SET))       testingPrecisionRecall.addResult(label.getName(),testingDataSet.get(label),dataInstance -> dataSet.get(new DataInstance<>(dataInstance.name(),dataInstance.features())).get(label));
    }
);
    if (resultTypes.contains(ResultType.AVERAGE_AUC_FULL_DATA_SET))     results.averageAreasUnderTheCurve.put(iterationNumber,fullPrecisionRecall.getAreaUnderCurves().stream().mapToDouble(area -> area == null ? 0.0 : area.isNaN() ? 0.0 : area).average().orElse(0));
    if (resultTypes.contains(ResultType.AVERAGE_AUC_TESTING_DATA_SET))     results.averageTestingAreasUnderTheCurve.put(iterationNumber,testingPrecisionRecall.getAreaUnderCurves().stream().mapToDouble(area -> area == null ? 0.0 : area.isNaN() ? 0.0 : area).average().orElse(0));
    if (resultTypes.contains(ResultType.NUMBER_OF_EXAMPLES_PICKED))     results.numberOfExamplesPicked.put(iterationNumber,numberOfExamplesPicked);
    final long startTime=System.nanoTime();
switch (examplePickingMethod) {
case BATCH:
      List<Learning.InstanceToLabel> selectedInstances=learning.pickInstancesToLabel(numberOfExamplesToPickPerIteration);
    for (    Learning.InstanceToLabel instance : selectedInstances) {
      boolean trueLabel=dataSet.get(instance.getInstance()).get(instance.getLabel());
      Map<Label,Boolean> fixedLabels=new HashMap<>(learning.getLabels(instance.getInstance()));
      learning.labelInstance(instance,trueLabel);
      Map<Label,Boolean> newFixedLabels=new HashMap<>(learning.getLabels(instance.getInstance()));
      fixedLabels.keySet().forEach(newFixedLabels::remove);
      for (      Map.Entry<Label,Boolean> instanceLabelEntry : newFixedLabels.entrySet()) {
        for (        PredictedDataInstance<Vector,Double> predictedInstance : classifierDataSet.get(instanceLabelEntry.getKey()))         if (predictedInstance.name().equals(instance.getInstance().name())) {
          testingDataSet.get(instanceLabelEntry.getKey()).remove(predictedInstance);
          predictedInstance.label(1.0);
          predictedInstance.probability(instanceLabelEntry.getValue() ? 1.0 : 0.0);
          break;
        }
      }
    }
  numberOfExamplesPicked+=selectedInstances.size();
break;
case PSEUDO_SEQUENTIAL:
for (int exampleNumber=0; exampleNumber < numberOfExamplesToPickPerIteration; exampleNumber++) {
Learning.InstanceToLabel instance=learning.pickInstanceToLabel();
if (instance == null) break;
boolean trueLabel=dataSet.get(instance.getInstance()).get(instance.getLabel());
Map<Label,Boolean> fixedLabels=new HashMap<>(learning.getLabels(instance.getInstance()));
learning.labelInstance(instance,trueLabel);
Map<Label,Boolean> newFixedLabels=new HashMap<>(learning.getLabels(instance.getInstance()));
fixedLabels.keySet().forEach(newFixedLabels::remove);
for (Map.Entry<Label,Boolean> instanceLabelEntry : newFixedLabels.entrySet()) {
  for (  PredictedDataInstance<Vector,Double> predictedInstance : classifierDataSet.get(instanceLabelEntry.getKey()))   if (predictedInstance.name().equals(instance.getInstance().name())) {
    testingDataSet.get(instanceLabelEntry.getKey()).remove(predictedInstance);
    predictedInstance.label(1.0);
    predictedInstance.probability(instanceLabelEntry.getValue() ? 1.0 : 0.0);
    break;
  }
}
numberOfExamplesPicked++;
}
break;
}
final long endTime=System.nanoTime();
if (resultTypes.contains(ResultType.ACTIVE_LEARNING_METHOD_TIMES)) results.activeLearningMethodTimesTaken.put(iterationNumber,endTime - startTime);
if (numberOfExamplesPicked == previousNumberOfExamplesPicked || ++iterationNumber >= maximumNumberOfIterations) break;
previousNumberOfExamplesPicked=numberOfExamplesPicked;
}
final long experimentEndTime=System.currentTimeMillis();
results.timeTaken=experimentEndTime - experimentStartTime;
return results;
}