Program: 107992
Project: 107992
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 seed - The random seed, null, if the process should be randomized
 * @param samplingFraction - The sampling fraction
 * @throws ParseException 
 */
StatisticsClassification(DataHandleInternal inputHandle,DataHandleInternal outputHandle,String[] features,String clazz,Integer seed,double samplingFraction,WrappedBoolean interrupt) throws ParseException {
  this.interrupt=interrupt;
  if (samplingFraction <= 0d || samplingFraction > 1d) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (seed == null) {
    this.random=new Random();
  }
 else {
    this.random=new Random(seed);
  }
  ClassificationDataSpecification specification=new ClassificationDataSpecification(inputHandle,outputHandle,features,clazz,interrupt);
  int k=inputHandle.getNumRows() > 10 ? 10 : inputHandle.getNumRows();
  List<List<Integer>> folds=getFolds(inputHandle.getNumRows(),k);
  int classifications=0;
  for (int evaluationFold=0; evaluationFold < folds.size(); evaluationFold++) {
    ClassificationMethod inputLR=new MultiClassLogisticRegression(specification);
    ClassificationMethod inputZR=new MultiClassZeroR(specification);
    ClassificationMethod outputLR=null;
    if (inputHandle != outputHandle) {
      outputLR=new MultiClassLogisticRegression(specification);
    }
    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;
          }
        }
      }
      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);
          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);
          if (resultOutputLR != null) {
            correct=resultOutputLR.correct(actualValue);
            this.averageError+=resultOutputLR.error(actualValue);
            this.accuracy+=correct ? 1d : 0d;
            this.matrix.add(resultOutputLR.confidence(),correct);
          }
        }
      }
    }
 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();
  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 seed - The random seed, null, if the process should be randomized
 * @param samplingFraction - The sampling fraction
 * @throws ParseException 
 */
StatisticsClassification(DataHandleInternal inputHandle,DataHandleInternal outputHandle,String[] features,String clazz,Integer seed,double samplingFraction,WrappedBoolean interrupt) throws ParseException {
  this.interrupt=interrupt;
  if (samplingFraction <= 0d || samplingFraction > 1d) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (seed == null) {
    this.random=new Random();
  }
 else {
    this.random=new Random(seed);
  }
  ClassificationDataSpecification specification=new ClassificationDataSpecification(inputHandle,outputHandle,features,clazz,interrupt);
  int k=inputHandle.getNumRows() > 10 ? 10 : inputHandle.getNumRows();
  List<List<Integer>> folds=getFolds(inputHandle.getNumRows(),k);
  int classifications=0;
  for (int evaluationFold=0; evaluationFold < folds.size(); evaluationFold++) {
    ClassificationMethod inputLR=new MultiClassLogisticRegression(specification);
    ClassificationMethod inputZR=new MultiClassZeroR(specification);
    ClassificationMethod outputLR=null;
    if (inputHandle != outputHandle) {
      outputLR=new MultiClassLogisticRegression(specification);
    }
    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;
          }
        }
      }
      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);
          if (resultOutputLR != null) {
            correct=resultOutputLR.correct(actualValue);
            this.averageError+=resultOutputLR.error(actualValue);
            this.accuracy+=correct ? 1d : 0d;
            this.matrix.add(resultOutputLR.confidence(),correct);
          }
        }
      }
    }
 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();
  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;
}