Calculates a percentile based on a continuous distribution of the column value

@param arg argument
@return percentile_cont(arg)
11657
public static <T extends Number> WithinGroup<T> percentileCont(T arg) {
        if (arg.doubleValue() < 0.0 || arg.doubleValue() > 1.0) {
            throw new IllegalArgumentException("The percentile value should be a number between 0 and 1");
        }
        return percentileCont(ConstantImpl.create(arg));
    }
853737
public static long ceil(SoyValue arg) {
    if (arg instanceof IntegerData) {
      return ((IntegerData) arg).longValue();
    } else {
      return (long) Math.ceil(arg.floatValue());
    }
  }
203517
def median_interval(data, alpha=_alpha):
    
    q = [100*alpha/2., 50, 100*(1-alpha/2.)]
    lo,med,hi = np.percentile(data,q)
    return interval(med,lo,hi)
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
1098949
public static BigDecimal average(EvaluationContext ctx, Object... args) {
        if (args.length == 0) {
            throw new RuntimeException("Wrong number of arguments");
        }

        return sum(ctx, args).divide(new BigDecimal(args.length));
    }
843679
public function percentile(float $p) : ColumnVector
    {
        if ($p < 0. or $p > 100.) {
            throw new InvalidArgumentException('P must be between 0 and 100,'
                . " $p given.");
        }

        if ($this->n < 1) {
            throw new RuntimeException('Median is not defined for matrices'
                . ' with less than 1 column.');
        }

        $b = [];

        foreach ($this->a as $row) {
            sort($row);

            $x = ($p / 100) * ($this->n - 1) + 1;

            $xHat = (int) $x;
    
            $remainder = $x - $xHat;
    
            $t = $row[$xHat - 1];
    
            $b[] = $t + $remainder * ($row[$xHat] - $t);
        }

        return ColumnVector::quick($b);
    }
868329
public final Latency withPercentile98th(double value) {
    double newValue = value;
    return new Latency(this.median, newValue, this.percentile99th, this.percentile999th, this.mean, this.min, this.max);
  }
722565
def percentAt(self, value):
        
        min_val = self.minimum()
        max_val = self.maximum()
        
        if value < min_val:
            return 0.0
        elif max_val < value:
            return 1.0
        
        # round the max value to sync with the values in the grid
        max_val = self.rounded(max_val)
        
        try:
            perc = (value - min_val) / float(max_val - min_val)
        except (TypeError, ZeroDivisionError):
            return 0.0
        
        return max(min(perc, 1.0), 0.0)
193453
def perc(arr, p=95, **kwargs):
    """"""
    offset = (100 - p) / 2
    return np.percentile(arr, (offset, 100 - offset), **kwargs)
1134496
public static function percentile(array $values, float $p) : float
    {
        if (empty($values)) {
            throw new InvalidArgumentException('Percentile is not defined for'
                . ' an empty set.');
        }

        if ($p < 0. or $p > 100.) {
            throw new InvalidArgumentException('P must be between 0 and 1,'
                . " $p given.");
        }

        $n = count($values);

        sort($values);

        $x = ($p / 100) * ($n - 1) + 1;

        $xHat = (int) $x;

        $remainder = $x - $xHat;

        $a = $values[$xHat - 1];
        $b = $values[$xHat];

        return $a + $remainder * ($b - $a);
    }
109006
public function aggregate($function, $columns = array('*'), $percentile = null)
    {
        $this->aggregate = array_merge([
            'label' => $this->from
        ], compact('function', 'columns', 'percentile'));

        $previousColumns = $this->columns;

        $results = $this->get($columns);

        // Once we have executed the query, we will reset the aggregate property so
        // that more select queries can be executed against the database without
        // the aggregate value getting in the way when the grammar builds it.
        $this->aggregate = null;

        $this->columns = $previousColumns;

        if ($results->valid())
        {
            return $results->current()[0];
        }
    }
528378
def quantiles(self, k=5):
        """"""
        arr = self.array()
        q = list(np.linspace(0, 100, k))
        return np.percentile(arr.compressed(), q)
1332988
private Counter counterFor(int i) {
    Counter c = counters.get(i);
    if (c == null) {
      Id counterId = id.withTags(Statistic.percentile, new BasicTag("percentile", TAG_VALUES[i]));
      c = registry.counter(counterId);
      counters.set(i, c);
    }
    return c;
  }
491219
public int getValueAtPercentile(double percentile) {
        int permyriad = (int) (percentile * 100);
        switch (permyriad) {
            case 0: return p0;
            case 500: return p5;
            case 1000: return p10;
            case 1500: return p15;
            case 2000: return p20;
            case 2500: return p25;
            case 3000: return p30;
            case 3500: return p35;
            case 4000: return p40;
            case 4500: return p45;
            case 5000: return p50;
            case 5500: return p55;
            case 6000: return p60;
            case 6500: return p65;
            case 7000: return p70;
            case 7500: return p75;
            case 8000: return p80;
            case 8500: return p85;
            case 9000: return p90;
            case 9500: return p95;
            case 9900: return p99;
            case 9950: return p99_5;
            case 9990: return p99_9;
            case 9995: return p99_95;
            case 9999: return p99_99;
            case 10000: return p100;
            default: throw new IllegalArgumentException("Percentile (" + percentile + ") is not currently cached");
        }
    }
224863
def percentile(self, percentile):
        
        assert(percentile >= 0 and percentile <= 100)
        assert(self.kind in ["exponential", "linear", "enumerated", "boolean"])

        fraction = percentile / 100
        to_count = fraction * self.buckets.sum()
        percentile_bucket = 0

        for percentile_bucket in range(len(self.buckets)):
            freq = self.buckets.values[percentile_bucket]
            if to_count - freq <= 0:
                break
            to_count -= freq

        percentile_lower_boundary = self.buckets.index[percentile_bucket]
        percentile_frequency = self.buckets.values[percentile_bucket]

        if percentile_bucket == len(self.buckets) - 1 or percentile_frequency == 0:
            return percentile_lower_boundary

        width = self.buckets.index[percentile_bucket + 1] - self.buckets.index[percentile_bucket]
        return percentile_lower_boundary + width * to_count / percentile_frequency
416710
def percentile(arr, percent):
    
    arr = sorted(arr)
    index = (len(arr) - 1) * percent
    floor = math.floor(index)
    ceil = math.ceil(index)
    if floor == ceil:
        return arr[int(index)]
    low_value = arr[int(floor)] * (ceil - index)
    high_value = arr[int(ceil)] * (index - floor)
    return low_value + high_value
652569
public Double getSurvivalTimePercentile(String group, double percentile) {

		StrataInfo si = sfi.getStrataInfoHashMap().get(group);
		ArrayList<Double> percentage = si.getSurv();
		Integer percentileIndex = null;
		for (int i = 0; i < percentage.size(); i++) {
			if (percentage.get(i) == percentile) {
				if (i + 1 < percentage.size()) {
					percentileIndex = i + 1;
				}
				break;
			} else if (percentage.get(i) < percentile) {
				percentileIndex = i;
				break;
			}
		}
		if (percentileIndex != null) {
			return si.getTime().get(percentileIndex);
		} else {
			return null;
		}
	}