Given a list of percentiles (floats between 0 and 1), return a
    list of the values at those percentiles, interpolating if
    necessary.
518551
def percentiles(self, percentiles):
    """"""
    try:
      scores = [0.0]*len(percentiles)

      if self.count > 0:
        values = self.samples()
        values.sort()

        for i in range(len(percentiles)):
          p = percentiles[i]
          pos = p * (len(values) + 1)
          if pos < 1:
            scores[i] = values[0]
          elif pos > len(values):
            scores[i] = values[-1]
          else:
            upper, lower = values[int(pos - 1)], values[int(pos)]
            scores[i] = lower + (pos - floor(pos)) * (upper - lower)

      return scores
    except IndexError:
      return [float('NaN')] * len(percentiles)
532404
def average_percentile(values):
    
    if not values:
        return None, None, None

    value_avg = round(float(sum(values)) / len(values), 2)
    value_max = round(percentile(values, 95), 2)
    value_min = round(percentile(values, 5), 2)
    return value_avg, value_min, value_max
566574
public static <T> Map<Percentage, T> percentiles(final List<T> sortedList) {
        N.checkArgNotNullOrEmpty(sortedList, "The spcified 'sortedList' can not be null or empty");

        final int size = sortedList.size();
        final Map<Percentage, T> m = new LinkedHashMap<>(N.initHashCapacity(Percentage.values().length));

        for (Percentage p : Percentage.values()) {
            m.put(p, sortedList.get((int) (size * p.doubleValue())));
        }

        return ImmutableMap.of(m);
    }
528378
def quantiles(self, k=5):
        """"""
        arr = self.array()
        q = list(np.linspace(0, 100, k))
        return np.percentile(arr.compressed(), q)
139135
def _group_percentile(self, clusters, adj_list, counts):
        '''  '''

        retained_umis = self._get_best_percentile(clusters, counts)
        groups = [[x] for x in retained_umis]

        return groups
92510
def take_percentile(arr, percent):
    
    size = len(arr)
    stop = min(int(size * percent), len(arr))
    return arr[0:stop]
299003
def interpolator(self, x, values):
        
        # hacking the barycentric interpolator by computing the weights in advance
        p = Bary([0.])
        N = len(values)
        weights = np.ones(N)
        weights[0] = .5
        weights[1::2] = -1
        weights[-1] *= .5
        p.wi = weights
        p.xi = x
        p.set_yi(values)
        return p
1286569
def create_quantiles(items: Sequence, lower_bound, upper_bound):
    """"""

    interval = (upper_bound - lower_bound) / len(items)

    quantiles = ((g, (x - interval, x)) for g, x in
                 zip(items, accumulate(repeat(interval, len(items)))))

    return quantiles
612044
def percentile_index(a, q):
    
    return np.where(
        a==np.percentile(a, q, interpolation='nearest')
    )[0][0]
185697
def calc_percentiles(self, col_name, where_col_list, where_value_list):
        
        #col_data = self.get_col_data_by_name(col_name)
        col_data = self.select_where(where_col_list, where_value_list, col_name)
        #print('calc_percentiles: col_data = ', col_data, ' where_col_list = ', where_col_list, ', where_value_list = ', where_value_list)
        if len(col_data) == 0:
            #print("Nothing to calculate")
            return 0,0,0
        else:
            first  = self.percentile(col_data, .25)
            third  = self.percentile(col_data, .75)
            median = self.percentile(col_data, .50)
            #print('CALC_PERCENTILES =  first, third, median ',  first, third, median )
            return  first, third, median
1269027
public static AssociativeArray percentiles(FlatDataCollection flatDataCollection, int cutPoints) {
        double[] doubleArray = flatDataCollection.stream().filter(x -> x!=null).mapToDouble(TypeInference::toDouble).toArray();
        int n = doubleArray.length;
        if(n<=0 || cutPoints<=0 || n<cutPoints) {
            throw new IllegalArgumentException("All the parameters must be positive and n larger than cutPoints.");
        }
        Arrays.sort(doubleArray);
        
        /*
        Uses the Haverage algorithm which is used by SPSS as described at: 
        http://publib.boulder.ibm.com/infocenter/spssstat/v20r0m0/index.jsp?topic=%2Fcom.ibm.spss.statistics.help%2Falg_examine_haverage.htm        
        */

        AssociativeArray percintiles = new AssociativeArray();
        double counter = 1.0;
        while(true) {
            double perc = counter/cutPoints;
            
            Double tc2=(n+1.0)*perc;
                

            int CCk2=tc2.intValue();
            int CCk2_plus1=CCk2+1;

            int Ck2=CCk2-1; //actual pointers on the table. These are used because the arrays start from 0 the counting
            int Ck2_plus1=CCk2_plus1-1;

            double g2Star=tc2-CCk2;
            
            if(Ck2<doubleArray.length) {
                Double key=100*perc;
                Double Ck2Value = doubleArray[Ck2];
                if(Ck2_plus1<doubleArray.length) {
                    Double Ck2_plus1Value = doubleArray[Ck2_plus1];
                    percintiles.put(key, (1-g2Star)*Ck2Value+g2Star*Ck2_plus1Value);
                }
                else {
                    percintiles.put(key, Ck2Value);
                    break;
                }
            }
            else {
                break;
            }

            ++counter;
        }
        
        return percintiles;
    }
1281982
def interpolate(self, interpValues):
                
        self.__operations.append(["interpolate", interpValues])          
        
        df = self.sampleDF
        self.interpValues = interpValues
        for interParamName, value  in interpValues.items():
            self.__report += "Interpolation of the parameters for independent variables '" \
                             + interParamName + "' at value " + str(value) + ".\n"   
            for ind, (paramTrace, resType) in enumerate(zip(df["obj_parameter"], df["Result type"])):
                if resType == "numericalTrace" and interParamName in paramTrace.indepNames:
                    val = paramTrace.getInterp1dValues(value, interParamName, statsToReturn=["mean"])
                    if isinstance(val, list):
                        if len(val) == 1:
                            val = val[0]
                        else:
                            raise ValueError("This case has not been implemented yet.")
                    df.loc[ind, "Values"] = float(val)
450996
def percentile(self, percentile):
        """"""
        return self.bin_centers[np.argmin(np.abs(self.cumulative_density * 100 - percentile))]
359051
public static IntRange GetRange( int[] values, double percent ){
        int total = 0, n = values.length;

        // for all values
        for ( int i = 0; i < n; i++ )
        {
            // accumalate total
            total += values[i];
        }

        int min, max, hits;
        int h = (int) ( total * ( percent + ( 1 - percent ) / 2 ) );

        // get range min value
        for ( min = 0, hits = total; min < n; min++ )
        {
            hits -= values[min];
            if ( hits < h )
                break;
        }
        // get range max value
        for ( max = n - 1, hits = total; max >= 0; max-- )
        {
            hits -= values[max];
            if ( hits < h )
                break;
        }
        return new IntRange( min, max );
    }
942511
def scoreatpercentile(inlist, percent):
    
    if percent > 1:
        print("\nDividing percent>1 by 100 in lscoreatpercentile().\n")
        percent = percent / 100.0
    targetcf = percent * len(inlist)
    h, lrl, binsize, extras = histogram(inlist)
    cumhist = cumsum(copy.deepcopy(h))
    for i in range(len(cumhist)):
        if cumhist[i] >= targetcf:
            break
    score = binsize * ((targetcf - cumhist[i - 1]) / float(h[i])) + (lrl + binsize * i)
    return score
990537
def percentile(self, lst_data, percent , key=lambda x:x):
        
        new_list = sorted(lst_data)
        #print('new list = ' , new_list)
        #n = float(len(lst_data))
        k = (len(new_list)-1) * percent
        f = math.floor(k)
        c = math.ceil(k)
        if f == c:
            #print(key(new_list[int(k)]))
            return key(new_list[int(k)])
        d0 = float(key(new_list[int(f)])) * (c-k)
        d1 = float(key(new_list[int(c)])) * (k-f)
        return d0+d1
962630
def quantile(x, q, weights=None):
    
    if weights is None:
        return np.percentile(x, [100. * qi for qi in q])
    else:
        idx = np.argsort(x)
        xsorted = x[idx]
        cdf = np.add.accumulate(weights[idx])
        cdf /= cdf[-1]
        return np.interp(q, cdf, xsorted).tolist()