Program: 107764
Project: 107764
Buggy source:
/** 
 * Creates a new set of statistics for the given classification task
 * @param inputHandle - The input features handle
 * @param outputHandle - The output features handle
 * @param features - The feature attributes
 * @param clazz - The class attributes
 * @param config - The configuration
 * @param scaling 
 * @param interrupt - The interrupt flag
 * @param progress 
 * @throws ParseException 
 */
StatisticsClassification(DataHandleInternal inputHandle,DataHandleInternal outputHandle,String[] features,String clazz,ARXClassificationConfiguration<?> config,ARXFeatureScaling scaling,WrappedBoolean interrupt,WrappedInteger progress) throws ParseException {
  this.interrupt=interrupt;
  this.progress=progress;
  this.numSamples=getNumSamples(inputHandle.getNumRows(),config);
  if (!config.isDeterministic()) {
    this.random=new Random();
  }
 else {
    this.random=new Random(config.getSeed());
  }
  ClassificationDataSpecification specification=new ClassificationDataSpecification(inputHandle,outputHandle,scaling,features,clazz,interrupt);
  this.numClasses=specification.classMap.size();
  int k=numSamples > config.getNumFolds() ? config.getNumFolds() : numSamples;
  List<List<Integer>> folds=getFolds(inputHandle.getNumRows(),numSamples,k);
  int classifications=0;
  double total=100d / ((double)numSamples * (double)folds.size());
  double done=0d;
  double[] inputConfidences=new double[numSamples * (1 + numClasses)];
  double[] outputConfidences=(inputHandle == outputHandle) ? null : new double[numSamples * (1 + numClasses)];
  double[] zerorConfidences=new double[numSamples * (1 + numClasses)];
  int confidencesIndex=0;
  for (int evaluationFold=0; evaluationFold < folds.size(); evaluationFold++) {
    ClassificationMethod inputClassifier=getClassifier(specification,config);
    ClassificationMethod inputZeroR=new MultiClassZeroR(specification);
    ClassificationMethod outputClassifier=null;
    if (inputHandle != outputHandle) {
      outputClassifier=getClassifier(specification,config);
    }
    try {
      boolean trained=false;
      for (int trainingFold=0; trainingFold < folds.size(); trainingFold++) {
        if (trainingFold != evaluationFold) {
          for (          int index : folds.get(trainingFold)) {
            checkInterrupt();
            inputClassifier.train(inputHandle,outputHandle,index);
            inputZeroR.train(inputHandle,outputHandle,index);
            if (outputClassifier != null && !outputHandle.isOutlier(index)) {
              outputClassifier.train(outputHandle,outputHandle,index);
            }
            trained=true;
            this.progress.value=(int)((++done) * total);
          }
        }
      }
      inputClassifier.close();
      inputZeroR.close();
      if (outputClassifier != null) {
        outputClassifier.close();
      }
      for (      int index : folds.get(evaluationFold)) {
        checkInterrupt();
        if (trained) {
          ClassificationResult resultInput=inputClassifier.classify(inputHandle,index);
          ClassificationResult resultInputZR=inputZeroR.classify(inputHandle,index);
          ClassificationResult resultOutput=outputClassifier == null ? null : outputClassifier.classify(outputHandle,index);
          classifications++;
          String actualValue=outputHandle.getValue(index,specification.classIndex,true);
          this.zeroRAverageError+=resultInputZR.error(actualValue);
          this.zeroRAccuracy+=resultInputZR.correct(actualValue) ? 1d : 0d;
          double[] confidences=resultInputZR.confidences();
          zerorConfidences[confidencesIndex]=index;
          System.arraycopy(confidences,0,zerorConfidences,confidencesIndex + 1,confidences.length);
          boolean correct=resultInput.correct(actualValue);
          this.originalAverageError+=resultInput.error(actualValue);
          this.originalAccuracy+=correct ? 1d : 0d;
          confidences=resultInput.confidences();
          inputConfidences[confidencesIndex]=index;
          System.arraycopy(confidences,0,inputConfidences,confidencesIndex + 1,confidences.length);
          if (resultOutput != null) {
            correct=resultOutput.correct(actualValue);
            this.averageError+=resultOutput.error(actualValue);
            this.accuracy+=correct ? 1d : 0d;
            confidences=resultOutput.confidences();
            outputConfidences[confidencesIndex]=index;
            System.arraycopy(confidences,0,outputConfidences,confidencesIndex + 1,confidences.length);
          }
          confidencesIndex+=numClasses + 1;
        }
        this.progress.value=(int)((++done) * total);
      }
    }
 catch (    Exception e) {
      if (e instanceof ComputationInterruptedException) {
        throw e;
      }
 else {
        throw new UnexpectedErrorException(e);
      }
    }
  }
  this.zeroRAverageError/=(double)classifications;
  this.zeroRAccuracy/=(double)classifications;
  this.originalAverageError/=(double)classifications;
  this.originalAccuracy/=(double)classifications;
  for (  String attr : specification.classMap.keySet()) {
    zerorROC.put(attr,new ROCCurve(attr,zerorConfidences,numClasses,specification.classMap.get(attr),outputHandle,specification.classIndex));
  }
  for (  String attr : specification.classMap.keySet()) {
    originalROC.put(attr,new ROCCurve(attr,inputConfidences,numClasses,specification.classMap.get(attr),outputHandle,specification.classIndex));
  }
  if (inputHandle != outputHandle) {
    for (    String attr : specification.classMap.keySet()) {
      ROC.put(attr,new ROCCurve(attr,outputConfidences,numClasses,specification.classMap.get(attr),outputHandle,specification.classIndex));
    }
  }
  if (inputHandle != outputHandle) {
    this.averageError/=(double)classifications;
    this.accuracy/=(double)classifications;
  }
 else {
    this.averageError=this.originalAverageError;
    this.accuracy=this.originalAccuracy;
  }
  this.numMeasurements=classifications;
}

Fixed version (ground truth):
/** 
 * Creates a new set of statistics for the given classification task
 * @param inputHandle - The input features handle
 * @param outputHandle - The output features handle
 * @param features - The feature attributes
 * @param clazz - The class attributes
 * @param config - The configuration
 * @param scaling 
 * @param interrupt - The interrupt flag
 * @param progress 
 * @throws ParseException 
 */
StatisticsClassification(DataHandleInternal inputHandle,DataHandleInternal outputHandle,String[] features,String clazz,ARXClassificationConfiguration<?> config,ARXFeatureScaling scaling,WrappedBoolean interrupt,WrappedInteger progress) throws ParseException {
  this.interrupt=interrupt;
  this.progress=progress;
  this.numSamples=getNumSamples(inputHandle.getNumRows(),config);
  if (!config.isDeterministic()) {
    this.random=new Random();
  }
 else {
    this.random=new Random(config.getSeed());
  }
  ClassificationDataSpecification specification=new ClassificationDataSpecification(inputHandle,outputHandle,scaling,features,clazz,interrupt);
  this.numClasses=specification.classMap.size();
  int k=numSamples > config.getNumFolds() ? config.getNumFolds() : numSamples;
  List<List<Integer>> folds=getFolds(inputHandle.getNumRows(),numSamples,k);
  int classifications=0;
  double total=100d / ((double)numSamples * (double)folds.size());
  double done=0d;
  double[] inputConfidences=new double[numSamples * (1 + numClasses)];
  double[] outputConfidences=(inputHandle == outputHandle) ? null : new double[numSamples * (1 + numClasses)];
  double[] zerorConfidences=new double[numSamples * (1 + numClasses)];
  int confidencesIndex=0;
  for (int evaluationFold=0; evaluationFold < folds.size(); evaluationFold++) {
    ClassificationMethod inputClassifier=getClassifier(specification,config);
    ClassificationMethod inputZeroR=new MultiClassZeroR(specification);
    ClassificationMethod outputClassifier=null;
    if (inputHandle != outputHandle) {
      outputClassifier=getClassifier(specification,config);
    }
    try {
      boolean trained=false;
      for (int trainingFold=0; trainingFold < folds.size(); trainingFold++) {
        if (trainingFold != evaluationFold) {
          for (          int index : folds.get(trainingFold)) {
            checkInterrupt();
            inputClassifier.train(inputHandle,outputHandle,index);
            inputZeroR.train(inputHandle,outputHandle,index);
            if (outputClassifier != null && !outputHandle.isOutlier(index)) {
              outputClassifier.train(outputHandle,outputHandle,index);
              trained=true;
            }
            this.progress.value=(int)((++done) * total);
          }
        }
      }
      inputClassifier.close();
      inputZeroR.close();
      if (outputClassifier != null && trained) {
        outputClassifier.close();
      }
      for (      int index : folds.get(evaluationFold)) {
        checkInterrupt();
        ClassificationResult resultInput=inputClassifier.classify(inputHandle,index);
        ClassificationResult resultInputZR=inputZeroR.classify(inputHandle,index);
        ClassificationResult resultOutput=outputClassifier == null || !trained ? null : outputClassifier.classify(outputHandle,index);
        classifications++;
        String actualValue=outputHandle.getValue(index,specification.classIndex,true);
        this.zeroRAverageError+=resultInputZR.error(actualValue);
        this.zeroRAccuracy+=resultInputZR.correct(actualValue) ? 1d : 0d;
        double[] confidences=resultInputZR.confidences();
        zerorConfidences[confidencesIndex]=index;
        System.arraycopy(confidences,0,zerorConfidences,confidencesIndex + 1,confidences.length);
        boolean correct=resultInput.correct(actualValue);
        this.originalAverageError+=resultInput.error(actualValue);
        this.originalAccuracy+=correct ? 1d : 0d;
        confidences=resultInput.confidences();
        inputConfidences[confidencesIndex]=index;
        System.arraycopy(confidences,0,inputConfidences,confidencesIndex + 1,confidences.length);
        if (resultOutput != null) {
          correct=resultOutput.correct(actualValue);
          this.averageError+=resultOutput.error(actualValue);
          this.accuracy+=correct ? 1d : 0d;
          confidences=resultOutput.confidences();
          outputConfidences[confidencesIndex]=index;
          System.arraycopy(confidences,0,outputConfidences,confidencesIndex + 1,confidences.length);
        }
        confidencesIndex+=numClasses + 1;
        this.progress.value=(int)((++done) * total);
      }
    }
 catch (    Exception e) {
      if (e instanceof ComputationInterruptedException) {
        throw e;
      }
 else {
        throw new UnexpectedErrorException(e);
      }
    }
  }
  this.zeroRAverageError/=(double)classifications;
  this.zeroRAccuracy/=(double)classifications;
  this.originalAverageError/=(double)classifications;
  this.originalAccuracy/=(double)classifications;
  for (  String attr : specification.classMap.keySet()) {
    zerorROC.put(attr,new ROCCurve(attr,zerorConfidences,numClasses,specification.classMap.get(attr),outputHandle,specification.classIndex));
  }
  for (  String attr : specification.classMap.keySet()) {
    originalROC.put(attr,new ROCCurve(attr,inputConfidences,numClasses,specification.classMap.get(attr),outputHandle,specification.classIndex));
  }
  if (inputHandle != outputHandle) {
    for (    String attr : specification.classMap.keySet()) {
      ROC.put(attr,new ROCCurve(attr,outputConfidences,numClasses,specification.classMap.get(attr),outputHandle,specification.classIndex));
    }
  }
  if (inputHandle != outputHandle) {
    this.averageError/=(double)classifications;
    this.accuracy/=(double)classifications;
  }
 else {
    this.averageError=this.originalAverageError;
    this.accuracy=this.originalAccuracy;
  }
  this.numMeasurements=classifications;
}