コード例 #1
0
    /**
     * Estimation based on K<sup>th</sup> selection. This may be overridden in specific enums to
     * compute slightly different estimations.
     *
     * @param work array of numbers to be used for finding the percentile
     * @param pos indicated positional index prior computed from calling {@link #index(double, int)}
     * @param pivotsHeap an earlier populated cache if exists; will be used
     * @param length size of array considered
     * @param kthSelector a {@link KthSelector} used for pivoting during search
     * @return estimated percentile
     */
    protected double estimate(
        final double[] work,
        final int[] pivotsHeap,
        final double pos,
        final int length,
        final KthSelector kthSelector) {

      final double fpos = FastMath.floor(pos);
      final int intPos = (int) fpos;
      final double dif = pos - fpos;

      if (pos < 1) {
        return kthSelector.select(work, pivotsHeap, 0);
      }
      if (pos >= length) {
        return kthSelector.select(work, pivotsHeap, length - 1);
      }

      final double lower = kthSelector.select(work, pivotsHeap, intPos - 1);
      final double upper = kthSelector.select(work, pivotsHeap, intPos);
      return lower + dif * (upper - lower);
    }
コード例 #2
0
 /**
  * Get the {@link PivotingStrategyInterface} used in KthSelector for computation.
  *
  * @return the pivoting strategy set
  */
 public PivotingStrategyInterface getPivotingStrategy() {
   return kthSelector.getPivotingStrategy();
 }