|
|
|
|
@ -121,27 +121,23 @@ func bucketQuantile(q float64, buckets buckets) float64 { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// histogramQuantile calculates the quantile 'q' based on the given histogram.
|
|
|
|
|
// The quantile value is interpolated assuming a linear distribution within a bucket.
|
|
|
|
|
// A natural lower bound of 0 is assumed if the upper bound of the
|
|
|
|
|
// lowest bucket is greater 0. In that case, interpolation in the lowest bucket
|
|
|
|
|
// happens linearly between 0 and the upper bound of the lowest bucket.
|
|
|
|
|
// However, if the lowest bucket has an upper bound less or equal 0, this upper
|
|
|
|
|
// bound is returned if the quantile falls into the lowest bucket.
|
|
|
|
|
//
|
|
|
|
|
// The quantile value is interpolated assuming a linear distribution within a
|
|
|
|
|
// bucket.
|
|
|
|
|
// TODO(beorn7): Find an interpolation method that is a better fit for
|
|
|
|
|
// exponential buckets (and think about configurable interpolation).
|
|
|
|
|
//
|
|
|
|
|
// A natural lower bound of 0 is assumed if the histogram has no negative buckets.
|
|
|
|
|
//
|
|
|
|
|
// There are a number of special cases (once we have a way to report errors
|
|
|
|
|
// happening during evaluations of AST functions, we should report those
|
|
|
|
|
// explicitly):
|
|
|
|
|
//
|
|
|
|
|
// If 'buckets' has 0 observations, NaN is returned.
|
|
|
|
|
// If the histogram has 0 observations, NaN is returned.
|
|
|
|
|
//
|
|
|
|
|
// If q<0, -Inf is returned.
|
|
|
|
|
//
|
|
|
|
|
// The following special cases are ignored from conventional histograms because
|
|
|
|
|
// we don't have a +Inf bucket in new histograms:
|
|
|
|
|
// If the highest bucket is not +Inf, NaN is returned.
|
|
|
|
|
// If 'buckets' has fewer than 2 elements, NaN is returned.
|
|
|
|
|
//
|
|
|
|
|
// TODO(codesome): Support negative buckets.
|
|
|
|
|
// If q>1, +Inf is returned.
|
|
|
|
|
func histogramQuantile(q float64, h *histogram.FloatHistogram) float64 { |
|
|
|
|
if q < 0 { |
|
|
|
|
return math.Inf(-1) |
|
|
|
|
@ -157,7 +153,7 @@ func histogramQuantile(q float64, h *histogram.FloatHistogram) float64 { |
|
|
|
|
var ( |
|
|
|
|
bucket *histogram.FloatBucket |
|
|
|
|
count float64 |
|
|
|
|
it = h.AllFloatBucketIterator() |
|
|
|
|
it = h.AllBucketIterator() |
|
|
|
|
rank = q * h.Count |
|
|
|
|
idx = -1 |
|
|
|
|
) |
|
|
|
|
@ -176,8 +172,9 @@ func histogramQuantile(q float64, h *histogram.FloatHistogram) float64 { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if idx == 0 && bucket.Lower < 0 && bucket.Upper > 0 { |
|
|
|
|
// Zero bucket has the result and it happens to be the first bucket of this histogram.
|
|
|
|
|
// So we consider 0 to be the lower bound.
|
|
|
|
|
// Zero bucket has the result and it happens to be the first
|
|
|
|
|
// bucket of this histogram. So we consider 0 to be the lower
|
|
|
|
|
// bound.
|
|
|
|
|
bucket.Lower = 0 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|