Program: 107820
Project: 107820
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 interrupt - The interrupt flag
 * @param progress 
 * @throws ParseException 
 */
StatisticsClassification(DataHandleInternal inputHandle,DataHandleInternal outputHandle,String[] features,String clazz,ARXLogisticRegressionConfiguration config,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,features,clazz,interrupt);
  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=new MultiClassLogisticRegression(specification,config);
    ClassificationMethod inputZR=new MultiClassZeroR(specification);
    ClassificationMethod outputLR=null;
    if (inputHandle != outputHandle) {
      outputLR=new MultiClassLogisticRegression(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);
          if (resultOutputLR != null) {
            correct=resultOutputLR.correct(actualValue);
            this.averageError+=resultOutputLR.error(actualValue);
            this.accuracy+=correct ? 1d : 0d;
            this.matrix.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();
  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 interrupt - The interrupt flag
 * @param progress 
 * @throws ParseException 
 */
StatisticsClassification(DataHandleInternal inputHandle,DataHandleInternal outputHandle,String[] features,String clazz,ARXLogisticRegressionConfiguration config,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,features,clazz,interrupt);
  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=new MultiClassLogisticRegression(specification,config);
    ClassificationMethod inputZR=new MultiClassZeroR(specification);
    ClassificationMethod outputLR=null;
    if (inputHandle != outputHandle) {
      outputLR=new MultiClassLogisticRegression(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);
          if (resultOutputLR != null) {
            correct=resultOutputLR.correct(actualValue);
            this.averageError+=resultOutputLR.error(actualValue);
            this.accuracy+=correct ? 1d : 0d;
            this.matrix.add(resultOutputLR.confidence(),correct);
          }
        }
        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;
  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;
}