Program: 4479
Project: 4479
Buggy source:
/** 
 * Store a new item in our history. <p> This gets called for a bit whenever it is active and learning is enabled <p> Save duty cycle by normalizing it to the same iteration as the rest of the duty cycles which is lastTotalUpdate. <p> This is done to speed up computation in inference since all of the duty cycles can now be scaled by a single number. <p> The duty cycle is brought up to the current iteration only at inference and only when one of the duty cycles gets too large (to avoid overflow to larger data type) since the ratios between the duty cycles are what is important. As long as all of the duty cycles are at the same iteration their ratio is the same as it would be for any other iteration, because the update is simply a multiplication by a scalar that depends on the number of steps between the last update of the duty cycle and the current iteration.
 * @param iteration		the learning iteration number, which is only incrementedwhen learning is enabled
 * @param bucketIdx		the bucket index to store
 */
public void store(int iteration,int bucketIdx){
  if (lastTotalUpdate == -1) {
    lastTotalUpdate=iteration;
  }
  int statsLen=stats.size() - 1;
  if (bucketIdx > statsLen) {
    stats.add(new double[bucketIdx - statsLen]);
  }
  double dc=stats.get(bucketIdx);
  double denom=Math.pow((1.0 - classifier.alpha),(iteration - lastTotalUpdate));
  double dcNew=0;
  if (denom > 0)   dcNew=dc + (classifier.alpha / denom);
  if (denom == 0 || dcNew > DUTY_CYCLE_UPDATE_INTERVAL) {
    double exp=Math.pow((1.0 - classifier.alpha),(iteration - lastTotalUpdate));
    double dcT=0;
    for (int i=0; i < stats.size(); i++) {
      dcT*=exp;
      stats.set(i,dcT);
    }
    lastTotalUpdate=iteration;
    dc=stats.get(bucketIdx) + classifier.alpha;
  }
 else {
    dc=dcNew;
  }
  stats.set(bucketIdx,dc);
  if (classifier.verbosity >= 2) {
    System.out.println(String.format("String_Node_Str",id,bucketIdx,dc));
  }
}

Fixed version (ground truth):
/** 
 * Store a new item in our history. <p> This gets called for a bit whenever it is active and learning is enabled <p> Save duty cycle by normalizing it to the same iteration as the rest of the duty cycles which is lastTotalUpdate. <p> This is done to speed up computation in inference since all of the duty cycles can now be scaled by a single number. <p> The duty cycle is brought up to the current iteration only at inference and only when one of the duty cycles gets too large (to avoid overflow to larger data type) since the ratios between the duty cycles are what is important. As long as all of the duty cycles are at the same iteration their ratio is the same as it would be for any other iteration, because the update is simply a multiplication by a scalar that depends on the number of steps between the last update of the duty cycle and the current iteration.
 * @param iteration		the learning iteration number, which is only incrementedwhen learning is enabled
 * @param bucketIdx		the bucket index to store
 */
public void store(int iteration,int bucketIdx){
  if (lastTotalUpdate == -1) {
    lastTotalUpdate=iteration;
  }
  int statsLen=stats.size() - 1;
  if (bucketIdx > statsLen) {
    stats.add(new double[bucketIdx - statsLen]);
  }
  double dc=stats.get(bucketIdx);
  double denom=Math.pow((1.0 - classifier.alpha),(iteration - lastTotalUpdate));
  double dcNew=0;
  if (denom > 0)   dcNew=dc + (classifier.alpha / denom);
  if (denom == 0 || dcNew > DUTY_CYCLE_UPDATE_INTERVAL) {
    double exp=Math.pow((1.0 - classifier.alpha),(iteration - lastTotalUpdate));
    double dcT=0;
    for (int i=0; i < stats.size(); i++) {
      dcT=stats.get(i);
      dcT*=exp;
      stats.set(i,dcT);
    }
    lastTotalUpdate=iteration;
    dc=stats.get(bucketIdx) + classifier.alpha;
  }
 else {
    dc=dcNew;
  }
  stats.set(bucketIdx,dc);
  if (classifier.verbosity >= 2) {
    System.out.println(String.format("String_Node_Str",id,bucketIdx,dc));
  }
}