Program: 54673
Project: 54673
Buggy source:
/** 
 * {@inheritDoc} 
 */
@Override protected void _fit(Dataframe trainingData){
  ModelParameters modelParameters=kb().getModelParameters();
  int n=modelParameters.getN();
  int d=modelParameters.getD();
  kb().getTrainingParameters().setMultiProbabilityWeighted(false);
  Map<List<Object>,Double> likelihoods=modelParameters.getLogLikelihoods();
  Map<Object,Double> logPriors=modelParameters.getLogPriors();
  Set<Object> classesSet=modelParameters.getClasses();
  Map<Object,Double> sumOfLog1minusProb=modelParameters.getSumOfLog1minusProb();
  DatabaseConnector dbc=kb().getDbc();
  Map<Object,Integer> totalFeatureOccurrencesForEachClass=dbc.getBigMap("String_Node_Str",MapType.HASHMAP,StorageHint.IN_MEMORY,false,true);
  for (  Record r : trainingData) {
    Object theClass=r.getY();
    if (classesSet.add(theClass)) {
      logPriors.put(theClass,1.0);
      totalFeatureOccurrencesForEachClass.put(theClass,0);
      sumOfLog1minusProb.put(theClass,0.0);
    }
 else {
      logPriors.put(theClass,logPriors.get(theClass) + 1.0);
    }
  }
  streamExecutor.forEach(StreamMethods.stream(trainingData.getXDataTypes().keySet().stream(),isParallelized()),feature -> {
    for (    Object theClass : classesSet) {
      List<Object> featureClassTuple=Arrays.<Object>asList(feature,theClass);
      likelihoods.put(featureClassTuple,0.0);
    }
  }
);
  for (  Record r : trainingData) {
    Object theClass=r.getY();
    double sumOfOccurrences=streamExecutor.sum(StreamMethods.stream(r.getX().entrySet().stream(),isParallelized()).mapToDouble(entry -> {
      Object feature=entry.getKey();
      Double occurrences=TypeInference.toDouble(entry.getValue());
      if (occurrences != null && occurrences > 0.0) {
        List<Object> featureClassTuple=Arrays.<Object>asList(feature,theClass);
        likelihoods.put(featureClassTuple,likelihoods.get(featureClassTuple) + 1.0);
        return 1.0;
      }
      return 0.0;
    }
));
    totalFeatureOccurrencesForEachClass.put(theClass,totalFeatureOccurrencesForEachClass.get(theClass) + (int)sumOfOccurrences);
  }
  for (  Map.Entry<Object,Double> entry : logPriors.entrySet()) {
    Object theClass=entry.getKey();
    Double count=entry.getValue();
    logPriors.put(theClass,Math.log(count / n));
  }
  streamExecutor.forEach(StreamMethods.stream(likelihoods.entrySet().stream(),isParallelized()),entry -> {
    List<Object> featureClassTuple=entry.getKey();
    Object theClass=featureClassTuple.get(1);
    Double occurrences=entry.getValue();
    if (occurrences == null) {
      occurrences=0.0;
    }
    Double smoothedProbability=(occurrences + 1.0) / (totalFeatureOccurrencesForEachClass.get(theClass) + d);
    likelihoods.put(featureClassTuple,smoothedProbability);
    double log1minusP=Math.log(1.0 - smoothedProbability);
synchronized (sumOfLog1minusProb) {
      sumOfLog1minusProb.put(theClass,sumOfLog1minusProb.get(theClass) + log1minusP);
    }
  }
);
  dbc.dropBigMap("String_Node_Str",totalFeatureOccurrencesForEachClass);
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
@Override protected void _fit(Dataframe trainingData){
  ModelParameters modelParameters=kb().getModelParameters();
  int n=modelParameters.getN();
  int d=modelParameters.getD();
  kb().getTrainingParameters().setMultiProbabilityWeighted(false);
  Map<List<Object>,Double> likelihoods=modelParameters.getLogLikelihoods();
  Map<Object,Double> logPriors=modelParameters.getLogPriors();
  Set<Object> classesSet=modelParameters.getClasses();
  Map<Object,Double> sumOfLog1minusProb=modelParameters.getSumOfLog1minusProb();
  DatabaseConnector dbc=kb().getDbc();
  Map<Object,Integer> totalFeatureOccurrencesForEachClass=dbc.getBigMap("String_Node_Str",MapType.HASHMAP,StorageHint.IN_MEMORY,false,true);
  for (  Record r : trainingData) {
    Object theClass=r.getY();
    if (classesSet.add(theClass)) {
      logPriors.put(theClass,1.0);
      totalFeatureOccurrencesForEachClass.put(theClass,0);
      sumOfLog1minusProb.put(theClass,0.0);
    }
 else {
      logPriors.put(theClass,logPriors.get(theClass) + 1.0);
    }
  }
  streamExecutor.forEach(StreamMethods.stream(trainingData.getXDataTypes().keySet().stream(),isParallelized()),feature -> {
    for (    Object theClass : classesSet) {
      List<Object> featureClassTuple=Arrays.<Object>asList(feature,theClass);
      likelihoods.put(featureClassTuple,0.0);
    }
  }
);
  for (  Record r : trainingData) {
    Object theClass=r.getY();
    double sumOfOccurrences=streamExecutor.sum(StreamMethods.stream(r.getX().entrySet().stream(),isParallelized()).mapToDouble(entry -> {
      Object feature=entry.getKey();
      Double occurrences=TypeInference.toDouble(entry.getValue());
      if (occurrences != null && occurrences > 0.0) {
        List<Object> featureClassTuple=Arrays.<Object>asList(feature,theClass);
        likelihoods.put(featureClassTuple,likelihoods.get(featureClassTuple) + 1.0);
        return 1.0;
      }
      return 0.0;
    }
));
    totalFeatureOccurrencesForEachClass.put(theClass,totalFeatureOccurrencesForEachClass.get(theClass) + (int)sumOfOccurrences);
  }
  for (  Map.Entry<Object,Double> entry : logPriors.entrySet()) {
    Object theClass=entry.getKey();
    Double count=entry.getValue();
    logPriors.put(theClass,Math.log(count / n));
  }
  for (  Object theClass : classesSet) {
    double sumLog1minusP=streamExecutor.sum(StreamMethods.stream(trainingData.getXDataTypes().keySet().stream(),isParallelized()).mapToDouble(feature -> {
      List<Object> featureClassTuple=Arrays.<Object>asList(feature,theClass);
      Double occurrences=likelihoods.get(featureClassTuple);
      if (occurrences == null) {
        occurrences=0.0;
      }
      Double smoothedProbability=(occurrences + 1.0) / (totalFeatureOccurrencesForEachClass.get(theClass) + d);
      likelihoods.put(featureClassTuple,smoothedProbability);
      double log1minusP=Math.log(1.0 - smoothedProbability);
      return log1minusP;
    }
));
    sumOfLog1minusProb.put(theClass,sumOfLog1minusProb.get(theClass) + sumLog1minusP);
  }
  dbc.dropBigMap("String_Node_Str",totalFeatureOccurrencesForEachClass);
}