示例#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));
  }