Documentation
¶
Index ¶
- type Histogram
- func (h *Histogram) Add(v float64)
- func (h *Histogram) AddN(v float64, n int)
- func (h *Histogram) AddWeight(v, w float64)
- func (h *Histogram) Bin(i int) (value, weight float64)
- func (h *Histogram) Copy(x *Histogram) *Histogram
- func (h *Histogram) Count() int
- func (h *Histogram) Max() float64
- func (h *Histogram) Mean() float64
- func (h *Histogram) Merge(x, y *Histogram)
- func (h *Histogram) MergeWith(x *Histogram)
- func (h *Histogram) Min() float64
- func (h *Histogram) NumBins() int
- func (h *Histogram) Quantile(q float64) float64
- func (h *Histogram) Reset(sz int)
- func (h *Histogram) Sum() float64
- func (h *Histogram) Variance() float64
- func (h *Histogram) Weight() float64
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Histogram ¶
type Histogram struct {
// contains filtered or unexported fields
}
Histogram is a probabilistic, fixed-size data structure, able to accommodate massive data streams while predicting distributions and quantiles much more accurately than a sample-based approach.
Please note that a historgram is not thread-safe. All operations must be protected by a mutex if used across multiple goroutines.
Example ¶
// Create a new instance
h := histogram.New(16)
// Add values
for i := 1; i < 100; i++ {
h.Add(float64(i))
}
fmt.Printf("min : %.1f\n", h.Min())
fmt.Printf("max : %.1f\n", h.Max())
fmt.Printf("sum : %.0f\n", h.Sum())
fmt.Printf("mean : %.1f\n", h.Mean())
fmt.Printf("p50 : %.1f\n", h.Quantile(0.5))
fmt.Printf("p95 : %.1f\n", h.Quantile(0.95))
Output: min : 1.0 max : 99.0 sum : 4950 mean : 50.0 p50 : 49.8 p95 : 94.6
func (*Histogram) AddWeight ¶
AddWeight adds observations of v with the weight w to the distribution.
func (*Histogram) Bin ¶
Bin returns bin (bucket) data. Requested index must be 0 <= i < NumBins() or it will panic.
func (*Histogram) Copy ¶
Copy copies h to x and returns x. If x is passed as nil a new Histogram will be inited.
func (*Histogram) Mean ¶
Mean returns the (approximate) average observed value. Returns NaN if Count is zero.
func (*Histogram) Quantile ¶
Quantile returns the (approximate) quantile of the distribution. Accepted values for q are between 0.0 and 1.0. Returns NaN if Count is zero or bad inputs.
func (*Histogram) Sum ¶
Sum returns the (approximate) sum of all observed values. Returns NaN if Count is zero.