コード例 #1
0
  /**
   * Push a value onto this window. Returns the value that gets shifted off of the end if there is
   * one. Returns null if there wasn't one.
   *
   * @param value
   */
  public double pushValue(double value) {
    double shifted = Double.NEGATIVE_INFINITY;
    if (values.size() >= maxSize) {
      double oldValue = values.removeFirst();

      shifted = oldValue;

      sum -= oldValue;
      sumOfSquares -= oldValue * oldValue;
      deltaSum -= (values.peekFirst() - oldValue);
    }

    sum += value;
    sumOfSquares += value * value;

    if (values.size() > 0) {
      deltaSum += (value - values.peekLast());
    }

    values.addLast(value);
    minTracker.offer(value);
    maxTracker.offer(value);

    return shifted;
  }
コード例 #2
0
  public SlidingWindow(int maxSize) {
    this.maxSize = maxSize;
    this.values = new DoubleDeque(maxSize);

    this.minTracker = DoubleAscendingMinimaWindow.minimaTracker(maxSize);
    this.maxTracker = DoubleAscendingMinimaWindow.maximaTracker(maxSize);

    // yuck
    this.sum = 0d;
    this.sumOfSquares = 0d;
    this.deltaSum = 0d;
    this.deltaRSum = 0d;
  }
コード例 #3
0
 public double max() {
   return maxTracker.getMinimum();
 }
コード例 #4
0
 public double min() {
   return minTracker.getMinimum();
 }