Program: 107879
Project: 107879
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;
  double samplingFraction=(double)config.getMaxRecords() / (double)inputHandle.getNumRows();
  if (samplingFraction <= 0d) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (samplingFraction > 1d) {
    samplingFraction=1d;
  }
  if (!config.isDeterministic()) {
    this.random=new Random();
  }
 else {
    this.random=new Random(config.getSeed());
  }
  ClassificationDataSpecification specification=new ClassificationDataSpecification(inputHandle,outputHandle,scaling,features,clazz,interrupt);
  for (  String classValue : specification.classMap.keySet()) {
    rocCurves.put(classValue,new ROCCurve());
    originalRocCurves.put(classValue,new ROCCurve());
  }
  int k=inputHandle.getNumRows() > config.getNumFolds() ? config.getNumFolds() : inputHandle.getNumRows();
  List<List<Integer>> folds=getFolds(inputHandle.getNumRows(),k);
  int classifications=0;
  double total=100d / ((double)inputHandle.getNumRows() * (double)folds.size());
  double done=0d;
  for (int evaluationFold=0; evaluationFold < folds.size(); evaluationFold++) {
    ClassificationMethod inputLR=getClassifier(specification,config);
    ClassificationMethod inputZR=new MultiClassZeroR(specification);
    ClassificationMethod outputLR=null;
    if (inputHandle != outputHandle) {
      outputLR=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();
            inputLR.train(inputHandle,outputHandle,index);
            inputZR.train(inputHandle,outputHandle,index);
            if (outputLR != null && !outputHandle.isOutlier(index)) {
              outputLR.train(outputHandle,outputHandle,index);
            }
            trained=true;
            this.progress.value=(int)((++done) * total);
          }
        }
      }
      inputLR.close();
      inputZR.close();
      if (outputLR != null) {
        outputLR.close();
      }
      for (      int index : folds.get(evaluationFold)) {
        checkInterrupt();
        if (trained) {
          ClassificationResult resultInputLR=inputLR.classify(inputHandle,index);
          ClassificationResult resultInputZR=inputZR.classify(inputHandle,index);
          ClassificationResult resultOutputLR=outputLR == null ? null : outputLR.classify(outputHandle,index);
          classifications++;
          String actualValue=outputHandle.getValue(index,specification.classIndex,true);
          this.zeroRAverageError+=resultInputZR.error(actualValue);
          this.zeroRAccuracy+=resultInputZR.correct(actualValue) ? 1d : 0d;
          boolean correct=resultInputLR.correct(actualValue);
          this.originalAverageError+=resultInputLR.error(actualValue);
          this.originalAccuracy+=correct ? 1d : 0d;
          this.originalMatrix.add(resultInputLR.confidence(),correct);
          this.originalRocCurves.get(actualValue).add(resultInputLR.confidence(),correct);
          if (resultOutputLR != null) {
            correct=resultOutputLR.correct(actualValue);
            this.averageError+=resultOutputLR.error(actualValue);
            this.accuracy+=correct ? 1d : 0d;
            this.matrix.add(resultOutputLR.confidence(),correct);
            this.rocCurves.get(actualValue).add(resultOutputLR.confidence(),correct);
          }
        }
        this.progress.value=(int)((++done) * total);
      }
    }
 catch (    Exception e) {
      throw new RuntimeException(e);
    }
  }
  this.zeroRAverageError/=(double)classifications;
  this.zeroRAccuracy/=(double)classifications;
  this.originalAverageError/=(double)classifications;
  this.originalAccuracy/=(double)classifications;
  this.originalMatrix.pack();
  for (  ROCCurve curve : this.rocCurves.values()) {
    curve.pack();
  }
  for (  ROCCurve curve : this.originalRocCurves.values()) {
    curve.pack();
  }
  if (inputHandle != outputHandle) {
    this.averageError/=(double)classifications;
    this.accuracy/=(double)classifications;
    this.matrix.pack();
  }
 else {
    this.averageError=this.originalAverageError;
    this.accuracy=this.originalAccuracy;
    this.matrix=this.originalMatrix;
  }
  this.numClasses=specification.classMap.size();
  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;
  double samplingFraction=(double)config.getMaxRecords() / (double)inputHandle.getNumRows();
  if (samplingFraction <= 0d) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (samplingFraction > 1d) {
    samplingFraction=1d;
  }
  if (!config.isDeterministic()) {
    this.random=new Random();
  }
 else {
    this.random=new Random(config.getSeed());
  }
  ClassificationDataSpecification specification=new ClassificationDataSpecification(inputHandle,outputHandle,scaling,features,clazz,interrupt);
  for (  String classValue : specification.classMap.keySet()) {
    ROC.put(classValue,new ROCCurve());
    originalROC.put(classValue,new ROCCurve());
  }
  int k=inputHandle.getNumRows() > config.getNumFolds() ? config.getNumFolds() : inputHandle.getNumRows();
  List<List<Integer>> folds=getFolds(inputHandle.getNumRows(),k);
  int classifications=0;
  double total=100d / ((double)inputHandle.getNumRows() * (double)folds.size());
  double done=0d;
  for (int evaluationFold=0; evaluationFold < folds.size(); evaluationFold++) {
    ClassificationMethod inputLR=getClassifier(specification,config);
    ClassificationMethod inputZR=new MultiClassZeroR(specification);
    ClassificationMethod outputLR=null;
    if (inputHandle != outputHandle) {
      outputLR=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();
            inputLR.train(inputHandle,outputHandle,index);
            inputZR.train(inputHandle,outputHandle,index);
            if (outputLR != null && !outputHandle.isOutlier(index)) {
              outputLR.train(outputHandle,outputHandle,index);
            }
            trained=true;
            this.progress.value=(int)((++done) * total);
          }
        }
      }
      inputLR.close();
      inputZR.close();
      if (outputLR != null) {
        outputLR.close();
      }
      for (      int index : folds.get(evaluationFold)) {
        checkInterrupt();
        if (trained) {
          ClassificationResult resultInputLR=inputLR.classify(inputHandle,index);
          ClassificationResult resultInputZR=inputZR.classify(inputHandle,index);
          ClassificationResult resultOutputLR=outputLR == null ? null : outputLR.classify(outputHandle,index);
          classifications++;
          String actualValue=outputHandle.getValue(index,specification.classIndex,true);
          this.zeroRAverageError+=resultInputZR.error(actualValue);
          this.zeroRAccuracy+=resultInputZR.correct(actualValue) ? 1d : 0d;
          boolean correct=resultInputLR.correct(actualValue);
          this.originalAverageError+=resultInputLR.error(actualValue);
          this.originalAccuracy+=correct ? 1d : 0d;
          this.originalMatrix.add(resultInputLR.confidence(),correct);
          this.originalROC.get(actualValue).exists();
          this.originalROC.get(specification.classMapInverse.get(resultInputLR.index())).add(resultInputLR.confidence(),correct);
          if (resultOutputLR != null) {
            correct=resultOutputLR.correct(actualValue);
            this.averageError+=resultOutputLR.error(actualValue);
            this.accuracy+=correct ? 1d : 0d;
            this.matrix.add(resultOutputLR.confidence(),correct);
            this.ROC.get(actualValue).exists();
            this.ROC.get(specification.classMapInverse.get(resultOutputLR.index())).add(resultOutputLR.confidence(),correct);
          }
        }
        this.progress.value=(int)((++done) * total);
      }
    }
 catch (    Exception e) {
      throw new RuntimeException(e);
    }
  }
  this.zeroRAverageError/=(double)classifications;
  this.zeroRAccuracy/=(double)classifications;
  this.originalAverageError/=(double)classifications;
  this.originalAccuracy/=(double)classifications;
  this.originalMatrix.pack();
  for (  ROCCurve curve : this.ROC.values()) {
    curve.pack(classifications);
  }
  for (  ROCCurve curve : this.originalROC.values()) {
    curve.pack(classifications);
  }
  if (inputHandle != outputHandle) {
    this.averageError/=(double)classifications;
    this.accuracy/=(double)classifications;
    this.matrix.pack();
  }
 else {
    this.averageError=this.originalAverageError;
    this.accuracy=this.originalAccuracy;
    this.matrix=this.originalMatrix;
  }
  this.numClasses=specification.classMap.size();
  this.numMeasurements=classifications;
}