Program: 64439
Project: 64439
Buggy source:
@Override public void trainOnInstance(MultiLabelInstance instance){
  if (attributesMask == null)   initializeAttibutesMask(instance);
  int numOutputs=instance.numberOutputTargets();
  int numInputs=instance.numInputAttributes();
  if (!hasStarted) {
    if (outputsToLearn == null) {
      outputsToLearn=new int[numOutputs];
      for (int i=0; i < numOutputs; i++) {
        outputsToLearn[i]=i;
      }
    }
    if (inputsToLearn == null) {
      inputsToLearn=new int[numInputs];
      for (int i=0; i < numInputs; i++) {
        if (attributesMask[i])         inputsToLearn[i]=i;
      }
    }
    literalStatistics=new DoubleVector[outputsToLearn.length];
    varianceShift=new double[outputsToLearn.length];
    for (int i=0; i < outputsToLearn.length; i++) {
      literalStatistics[i]=new DoubleVector(new double[5]);
      varianceShift[i]=instance.valueOutputAttribute(outputsToLearn[i]);
    }
    if (outputsToLearn.length == instance.numOutputAttributes())     instanceTransformer=new NoInstanceTransformation();
 else     instanceTransformer=new InstanceOutputAttributesSelector((InstancesHeader)instance.dataset(),outputsToLearn);
    hasStarted=true;
  }
  double weight=instance.weight();
  DoubleVector[] exampleStatistics=new DoubleVector[outputsToLearn.length];
  for (int i=0; i < outputsToLearn.length; i++) {
    double target=instance.valueOutputAttribute(outputsToLearn[i]);
    double sum=weight * target;
    double squaredSum=weight * target * target;
    double sumShifted=weight * target - varianceShift[i];
    double squaredSumShifted=weight * (target - varianceShift[i]) * (target - varianceShift[i]);
    exampleStatistics[i]=new DoubleVector(new double[]{weight,sum,squaredSum,sumShifted,squaredSumShifted});
    literalStatistics[i].addValues(exampleStatistics[i].getArrayRef());
  }
  if (this.attributeObservers == null)   this.attributeObservers=new AutoExpandVector<AttributeStatisticsObserver>();
  for (int i=0; i < inputsToLearn.length; i++) {
    if (attributesMask[inputsToLearn[i]]) {
      AttributeStatisticsObserver obs=this.attributeObservers.get(inputsToLearn[i]);
      if (obs == null) {
        if (instance.attribute(inputsToLearn[i]).isNumeric()) {
          obs=((NumericStatisticsObserver)numericStatisticsObserver.copy());
        }
 else         if (instance.attribute(inputsToLearn[i]).isNominal()) {
          obs=((NominalStatisticsObserver)nominalStatisticsObserver.copy());
        }
        this.attributeObservers.set(inputsToLearn[i],obs);
      }
      obs.observeAttribute(instance.valueInputAttribute(inputsToLearn[i]),exampleStatistics);
    }
  }
  Instance transformedInstance=instanceTransformer.sourceInstanceToTarget(instance);
  Prediction prediction=null;
  Prediction targetPrediction=learner.getPredictionForInstance(transformedInstance);
  if (targetPrediction != null)   prediction=instanceTransformer.targetPredictionToSource(targetPrediction);
  if (prediction != null)   errorMeasurer.addPrediction(prediction,instance);
  learner.trainOnInstance(transformedInstance);
  weightSeen+=instance.weight();
}

Fixed version (ground truth):
@Override public void trainOnInstance(MultiLabelInstance instance){
  if (attributesMask == null)   initializeAttibutesMask(instance);
  int numOutputs=instance.numberOutputTargets();
  int numInputs=instance.numInputAttributes();
  if (!hasStarted) {
    if (outputsToLearn == null) {
      outputsToLearn=new int[numOutputs];
      for (int i=0; i < numOutputs; i++) {
        outputsToLearn[i]=i;
      }
    }
    if (inputsToLearn == null) {
      inputsToLearn=new int[numInputs];
      for (int i=0; i < numInputs; i++) {
        if (attributesMask[i])         inputsToLearn[i]=i;
      }
    }
    literalStatistics=new DoubleVector[outputsToLearn.length];
    varianceShift=new double[outputsToLearn.length];
    for (int i=0; i < outputsToLearn.length; i++) {
      literalStatistics[i]=new DoubleVector(new double[5]);
      varianceShift[i]=instance.valueOutputAttribute(outputsToLearn[i]);
    }
    instanceHeader=(InstancesHeader)instance.dataset();
    hasStarted=true;
  }
  double weight=instance.weight();
  DoubleVector[] exampleStatistics=new DoubleVector[outputsToLearn.length];
  for (int i=0; i < outputsToLearn.length; i++) {
    double target=instance.valueOutputAttribute(outputsToLearn[i]);
    double sum=weight * target;
    double squaredSum=weight * target * target;
    double sumShifted=weight * target - varianceShift[i];
    double squaredSumShifted=weight * (target - varianceShift[i]) * (target - varianceShift[i]);
    exampleStatistics[i]=new DoubleVector(new double[]{weight,sum,squaredSum,sumShifted,squaredSumShifted});
    literalStatistics[i].addValues(exampleStatistics[i].getArrayRef());
  }
  if (this.attributeObservers == null)   this.attributeObservers=new AutoExpandVector<AttributeStatisticsObserver>();
  for (int i=0; i < inputsToLearn.length; i++) {
    if (attributesMask[inputsToLearn[i]]) {
      AttributeStatisticsObserver obs=this.attributeObservers.get(inputsToLearn[i]);
      if (obs == null) {
        if (instance.attribute(inputsToLearn[i]).isNumeric()) {
          obs=((NumericStatisticsObserver)numericStatisticsObserver.copy());
        }
 else         if (instance.attribute(inputsToLearn[i]).isNominal()) {
          obs=((NominalStatisticsObserver)nominalStatisticsObserver.copy());
        }
        this.attributeObservers.set(inputsToLearn[i],obs);
      }
      obs.observeAttribute(instance.valueInputAttribute(inputsToLearn[i]),exampleStatistics);
    }
  }
  Instance transformedInstance=instanceTransformer.sourceInstanceToTarget(instance);
  Prediction prediction=null;
  Prediction targetPrediction=learner.getPredictionForInstance(transformedInstance);
  if (targetPrediction != null)   prediction=instanceTransformer.targetPredictionToSource(targetPrediction);
  if (prediction != null)   errorMeasurer.addPrediction(prediction,instance);
  learner.trainOnInstance(transformedInstance);
  weightSeen+=instance.weight();
}