/** Creates a new holder for sliding-window instances. */
 public CompactCandidateSegmentGroup(FeatureFactory factory, CandidateSegmentGroup group) {
   // The length of the original sequence
   this.sequenceLength = group.getSequenceLength();
   // The maximum length of any sliding window
   this.maxWindowSize = group.getMaxWindowSize();
   this.totalSize = group.size();
   this.classNameSet = group.classNameSet();
   this.subPopId = group.getSubpopulationId();
   unitInstance = new Instance[sequenceLength];
   delta = new Delta[sequenceLength][maxWindowSize];
   label = new ClassLabel[sequenceLength][maxWindowSize];
   segmentSource = new Object[sequenceLength][maxWindowSize];
   for (int i = 0; i < sequenceLength; i++) {
     unitInstance[i] = factory.compress(group.getSubsequenceInstance(i, i + 1));
   }
   for (int i = 0; i < sequenceLength; i++) {
     for (int j = i + 1; j - i <= maxWindowSize; j++) {
       if (group.getSubsequenceInstance(i, j) != null) {
         label[i][j - i - 1] = group.getSubsequenceLabel(i, j);
         segmentSource[i][j - i - 1] = group.getSubsequenceInstance(i, j).getSource();
         delta[i][j - i - 1] = new Delta(factory, i, j, group.getSubsequenceInstance(i, j));
       }
     }
   }
 }
 public Delta(FeatureFactory factory, int start, int end, Instance segmentInstance) {
   for (Iterator<Feature> i = featureSet(start, end, segmentInstance).iterator();
       i.hasNext(); ) {
     Feature f = i.next();
     // replace the feature with its canonical version, so
     // that variant versions are not stored in the
     // deltaWeight, zeroWeights hash tables
     f = factory.getFeature(f);
     double segmentWeight = segmentInstance.getWeight(f);
     if (segmentWeight == 0) zeroWeights.add(f);
     else {
       double sumWeight = getSumWeight(start, end, f);
       if (segmentWeight != sumWeight) deltaWeight.put(f, segmentWeight - sumWeight);
     }
   }
   /*
    System.out.println("segmentInstance: "+segmentInstance);
    System.out.println("deltaInstance:   "+new DeltaInstance(start,end,this,
    segmentInstance.getSource(),
    segmentInstance.getSubpopulationId()));
   */
 }