Documentation ¶
Overview ¶
Package distribution contains distribution metrics, fixed width and geometric bucketers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultBucketer = GeometricBucketer(math.Pow(10, 0.2), 100)
DefaultBucketer is a bucketer with sensible bucket sizes.
Functions ¶
This section is empty.
Types ¶
type Bucketer ¶
type Bucketer struct {
// contains filtered or unexported fields
}
A Bucketer maps samples into discrete buckets.
func FixedWidthBucketer ¶
FixedWidthBucketer returns a Bucketer that uses numFiniteBuckets+2 buckets:
bucket[0] covers (-Inf...0) bucket[i] covers [width*(i-1)...width*i) for i > 0 and i <= numFiniteBuckets bucket[numFiniteBuckets+1] covers [width*numFiniteBuckets...+Inf)
The width must be greater than 0, and the number of finite buckets must be greater than 0.
func GeometricBucketer ¶
GeometricBucketer returns a Bucketer that uses numFiniteBuckets+2 buckets:
bucket[0] covers (−Inf, 1) bucket[i] covers [growthFactor^(i−1), growthFactor^i) for i > 0 and i <= numFiniteBuckets bucket[numFiniteBuckets+1] covers [growthFactor^(numFiniteBuckets−1), +Inf)
growthFactor must be positive, and the number of finite buckets must be greater than 0.
func NewBucketer ¶
NewBucketer creates a bucketer from custom parameters.
func (*Bucketer) Bucket ¶
Bucket returns the index of the bucket for sample. TODO(dsansome): consider reimplementing sort.Search inline to avoid overhead of calling a function to compare two values.
func (*Bucketer) GrowthFactor ¶
GrowthFactor returns the growth factor used to configure this Bucketer.
func (*Bucketer) NumBuckets ¶
NumBuckets returns the number of buckets including the underflow and overflow buckets.
func (*Bucketer) NumFiniteBuckets ¶
NumFiniteBuckets returns the number of finite buckets.
func (*Bucketer) OverflowBucket ¶
OverflowBucket returns the index of the overflow bucket.
func (*Bucketer) UnderflowBucket ¶
UnderflowBucket returns the index of the underflow bucket.
type Distribution ¶
type Distribution struct {
// contains filtered or unexported fields
}
A Distribution holds a statistical summary of a collection of floating-point values.
func New ¶
func New(b *Bucketer) *Distribution
New creates a new distribution using the given bucketer. Passing a nil Bucketer will use DefaultBucketer.
func (*Distribution) Add ¶
func (d *Distribution) Add(sample float64)
Add adds the sample to the distribution and updates the statistics.
func (*Distribution) Bucketer ¶
func (d *Distribution) Bucketer() *Bucketer
Bucketer returns the bucketer used in this distribution.
func (*Distribution) Buckets ¶
func (d *Distribution) Buckets() []int64
Buckets provides access to the underlying buckets slice. len(Buckets) will be <= Bucketer().NumBuckets()
func (*Distribution) Count ¶
func (d *Distribution) Count() int64
Count returns the number of times Add has been called.
func (*Distribution) LastNonZeroBucket ¶
func (d *Distribution) LastNonZeroBucket() int
LastNonZeroBucket returns the index into Buckets() of the last bucket that is set (non-zero). Returns -1 if Count() == 0.
func (*Distribution) Sum ¶
func (d *Distribution) Sum() float64
Sum returns the sum of all samples passed to Add.