Program: 43866
Project: 43866
Buggy source:
private Instances calcSegmentation(Instances inst,Instances segments,Instances nonSegments){
  boolean isSegment=false;
  patterns=new double[dimensions][];
  shifts=new int[dimensions];
  shiftsCorrelation=new double[dimensions];
  double[][] values=new double[dimensions][inst.numInstances()];
  Vector<Instance> segment=new Vector<Instance>();
  for (int i=0; i < inst.numInstances(); i++) {
    int d=0;
    for (int j=0; j < inst.numAttributes(); j++) {
      if (inst.classIndex() != j && inst.attribute(j).type() == Attribute.NUMERIC) {
        values[d][i]=inst.get(i).value(j);
        d++;
      }
    }
  }
  getPatterns(0,values);
  calcShifts(0,values);
  int bestShift=bestShift();
  if (shifts[bestShift] > 0) {
    for (int i=0; i <= values[0].length - shiftSampleLength; i=i + shifts[bestShift]) {
      if (!isSegment) {
        getPatterns(i,values);
        calcShifts(i,values);
        bestShift=bestShift();
      }
      int correlations=calcCorrelations(i,values);
      if (correlations >= minAttributesWithSegments) {
        for (int j=i; j < i + shifts[bestShift]; j++) {
          segment.add(inst.get(j));
        }
        if (!isSegment) {
          getPatterns(i,values);
          calcShifts(i,values);
        }
        isSegment=true;
      }
 else {
        if (segment.size() > minSegmentLength) {
          segments.add(this.buildOutputInstance(segment,segments));
        }
 else {
          nonSegments.add(this.buildOutputInstance(segment,nonSegments));
        }
        segment.clear();
        i=i - shifts[bestShift];
        isSegment=false;
      }
    }
    if (segment.size() > minSegmentLength) {
      segments.add(this.buildOutputInstance(segment,segments));
    }
 else {
      nonSegments.add(this.buildOutputInstance(segment,nonSegments));
    }
    segment.clear();
  }
  return segments;
}

Fixed version (ground truth):
private Instances calcSegmentation(Instances inst,Instances segments,Instances nonSegments){
  boolean isSegment=false;
  patterns=new double[dimensions][];
  shifts=new int[dimensions];
  shiftsCorrelation=new double[dimensions];
  double[][] values=new double[dimensions][inst.numInstances()];
  Vector<Instance> segment=new Vector<Instance>();
  Vector<Instance> nonSegment=new Vector<Instance>();
  int timeAttIndex=-1;
  for (int i=0; i < inst.numAttributes(); i++) {
    if (inst.attribute(i).isDate()) {
      timeAttIndex=i;
      break;
    }
  }
  for (int i=0; i < inst.numInstances(); i++) {
    int d=0;
    for (int j=0; j < inst.numAttributes(); j++) {
      if (inst.classIndex() != j && inst.attribute(j).type() == Attribute.NUMERIC) {
        values[d][i]=inst.get(i).value(j);
        d++;
      }
    }
  }
  getPatterns(0,values);
  calcShifts(0,values);
  int bestShift=bestShift();
  if (shifts[bestShift] > 0) {
    for (int i=0; i <= values[0].length - shiftSampleLength; i=i + shifts[bestShift]) {
      if (!isSegment) {
        getPatterns(i,values);
        calcShifts(i,values);
        bestShift=bestShift();
      }
      int correlations=calcCorrelations(i,values);
      if (correlations >= minAttributesWithSegments) {
        for (int j=i; j < i + shifts[bestShift]; j++) {
          segment.add(inst.get(j));
        }
        if (!isSegment) {
          getPatterns(i,values);
          calcShifts(i,values);
        }
        isSegment=true;
      }
 else {
        if (segment.size() > minSegmentLength) {
          segments.add(this.buildOutputInstance(segment,segments));
        }
 else {
          if (nonSegment.isEmpty()) {
            nonSegment.addAll(segment);
          }
 else {
            Timestamp t1=new Timestamp((long)nonSegment.lastElement().value(timeAttIndex));
            Timestamp t2=new Timestamp((long)segment.firstElement().value(timeAttIndex));
            if (t2.getTime() - t1.getTime() == TIME_BETWEEN_SAMPLES) {
              nonSegment.addAll(segment);
            }
 else {
              nonSegments.add(this.buildOutputInstance(nonSegment,nonSegments));
              nonSegment.clear();
              nonSegment.addAll(segment);
            }
          }
        }
        segment.clear();
        i=i - shifts[bestShift];
        isSegment=false;
      }
    }
    if (segment.size() > minSegmentLength) {
      segments.add(this.buildOutputInstance(segment,segments));
    }
 else {
      nonSegments.add(this.buildOutputInstance(segment,nonSegments));
    }
    segment.clear();
  }
  return segments;
}