Esempio n. 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;
  }
Esempio n. 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;
  }
Esempio n. 3
0
 public double max() {
   return maxTracker.getMinimum();
 }
Esempio n. 4
0
 public double min() {
   return minTracker.getMinimum();
 }