Esempio n. 1
0
  /**
   * Computes the specified quantile elements over the values previously added.
   *
   * @param phis the quantiles for which elements are to be computed. Each phi must be in the
   *     interval [0.0,1.0]. <tt>phis</tt> must be sorted ascending.
   * @return the approximate quantile elements.
   */
  public DoubleArrayList quantileElements(DoubleArrayList phis) {
    /*
    //check parameter
    DoubleArrayList sortedPhiList = phis.copy();
    sortedPhiList.sort();
    if (! phis.equals(sortedPhiList)) {
    	throw new IllegalArgumentException("Phis must be sorted ascending.");
    }
    */

    // System.out.println("starting to augment missing values, if necessary...");

    phis = preProcessPhis(phis);

    long[] triggerPositions = new long[phis.size()];
    long totalSize = this.bufferSet.totalSize();
    for (int i = phis.size(); --i >= 0; ) {
      triggerPositions[i] = Utils.epsilonCeiling(phis.get(i) * totalSize) - 1;
    }

    // System.out.println("triggerPositions="+cern.colt.Arrays.toString(triggerPositions));
    // System.out.println("starting to determine quantiles...");
    // System.out.println(bufferSet);

    DoubleBuffer[] fullBuffers = bufferSet._getFullOrPartialBuffers();
    double[] quantileElements = new double[phis.size()];

    // do the main work: determine values at given positions in sorted sequence
    return new DoubleArrayList(bufferSet.getValuesAtPositions(fullBuffers, triggerPositions));
  }
Esempio n. 2
0
 /** Returns a String representation of the receiver. */
 public String toString() {
   String s = this.getClass().getName();
   s = s.substring(s.lastIndexOf('.') + 1);
   int b = bufferSet.b();
   int k = bufferSet.k();
   return s
       + "(mem="
       + memory()
       + ", b="
       + b
       + ", k="
       + k
       + ", size="
       + size()
       + ", totalSize="
       + this.bufferSet.totalSize()
       + ")";
 }
Esempio n. 3
0
  /** Not yet commented. */
  protected void collapse() {
    DoubleBuffer[] toCollapse = buffersToCollapse();
    DoubleBuffer outputBuffer = bufferSet.collapse(toCollapse);

    int minLevel = toCollapse[0].level();
    outputBuffer.level(minLevel + 1);

    postCollapse(toCollapse);
  }
Esempio n. 4
0
  /**
   * Adds a value to the receiver.
   *
   * @param value the value to add.
   */
  public void add(double value) {
    totalElementsFilled++;
    if (!sampleNextElement()) return;

    // System.out.println("adding "+value);

    if (currentBufferToFill == null) {
      if (bufferSet._getFirstEmptyBuffer() == null) collapse();
      newBuffer();
    }

    currentBufferToFill.add(value);
    if (currentBufferToFill.isFull()) currentBufferToFill = null;
  }
Esempio n. 5
0
  /**
   * Adds the part of the specified list between indexes <tt>from</tt> (inclusive) and <tt>to</tt>
   * (inclusive) to the receiver.
   *
   * @param values the list of which elements shall be added.
   * @param from the index of the first element to be added (inclusive).
   * @param to the index of the last element to be added (inclusive).
   */
  public void addAllOfFromTo(DoubleArrayList values, int from, int to) {
    /*
    // the obvious version, but we can do quicker...
    double[] theValues = values.elements();
    int theSize=values.size();
    for (int i=0; i<theSize; ) add(theValues[i++]);
    */

    double[] valuesToAdd = values.elements();
    int k = this.bufferSet.k();
    int bufferSize = k;
    double[] bufferValues = null;
    if (currentBufferToFill != null) {
      bufferValues = currentBufferToFill.values.elements();
      bufferSize = currentBufferToFill.size();
    }

    for (int i = from - 1; ++i <= to; ) {
      if (sampleNextElement()) {
        if (bufferSize == k) { // full
          if (bufferSet._getFirstEmptyBuffer() == null) collapse();
          newBuffer();
          if (!currentBufferToFill.isAllocated) currentBufferToFill.allocate();
          currentBufferToFill.isSorted = false;
          bufferValues = currentBufferToFill.values.elements();
          bufferSize = 0;
        }

        bufferValues[bufferSize++] = valuesToAdd[i];
        if (bufferSize == k) { // full
          currentBufferToFill.values.setSize(bufferSize);
          currentBufferToFill = null;
        }
      }
    }
    if (this.currentBufferToFill != null) {
      this.currentBufferToFill.values.setSize(bufferSize);
    }

    this.totalElementsFilled += to - from + 1;
  }
Esempio n. 6
0
 /**
  * Returns the number of elements currently needed to store all contained elements. This number
  * usually differs from the results of method <tt>size()</tt>, according to the underlying
  * datastructure.
  */
 public long totalMemory() {
   return bufferSet.b() * bufferSet.k();
 }
Esempio n. 7
0
 /**
  * Returns how many percent of the elements contained in the receiver are <tt>&lt;= element</tt>.
  * Does linear interpolation if the element is not contained but lies in between two contained
  * elements.
  *
  * @param the element to search for.
  * @return the percentage <tt>p</tt> of elements <tt>&lt;= element</tt> (<tt>0.0 &lt;= p
  *     &lt;=1.0)</tt>.
  */
 public double phi(double element) {
   return bufferSet.phi(element);
 }
Esempio n. 8
0
 /**
  * Returns the number of elements currently needed to store all contained elements. This number
  * usually differs from the results of method <tt>size()</tt>, according to the underlying
  * datastructure.
  */
 public long memory() {
   return bufferSet.memory();
 }
Esempio n. 9
0
 /** Returns whether the specified element is contained in the receiver. */
 public boolean contains(double element) {
   return bufferSet.contains(element);
 }
Esempio n. 10
0
 /** Not yet commented. */
 protected DoubleBuffer[] buffersToCollapse() {
   int minLevel = bufferSet._getMinLevelOfFullOrPartialBuffers();
   return bufferSet._getFullOrPartialBuffersWithLevel(minLevel);
 }