distribution

package
v0.0.0-...-d0ced46 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 3 Imported by: 47

Documentation

Overview

Package distribution contains distribution metrics, fixed width and geometric bucketers.

Index

Constants

This section is empty.

Variables

View Source
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

func FixedWidthBucketer(width float64, numFiniteBuckets int) *Bucketer

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

func GeometricBucketer(growthFactor float64, numFiniteBuckets int) *Bucketer

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 greater than 1.0, and the number of finite buckets must be greater than 0.

func GeometricBucketerWithScale

func GeometricBucketerWithScale(growthFactor float64, numFiniteBuckets int, scale float64) *Bucketer

GeometricBucketerWithScale returns a Bucketer that uses numFiniteBuckets+2 buckets:

bucket[0] covers (−Inf, scale)
bucket[i] covers [scale*growthFactor^(i−1), scale*growthFactor^i) for i > 0 and i <= numFiniteBuckets
bucket[numFiniteBuckets+1] covers [scale*growthFactor^(numFiniteBuckets−1), +Inf)

growthFactor must be greater than 1.0, the number of finite buckets and scale must be greater than 0.

func NewBucketer

func NewBucketer(width, growthFactor float64, numFiniteBuckets int, scale float64) *Bucketer

NewBucketer creates a bucketer from custom parameters.

func (*Bucketer) Bucket

func (b *Bucketer) Bucket(sample float64) int

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

func (b *Bucketer) GrowthFactor() float64

GrowthFactor returns the growth factor used to configure this Bucketer.

func (*Bucketer) NumBuckets

func (b *Bucketer) NumBuckets() int

NumBuckets returns the number of buckets including the underflow and overflow buckets.

func (*Bucketer) NumFiniteBuckets

func (b *Bucketer) NumFiniteBuckets() int

NumFiniteBuckets returns the number of finite buckets.

func (*Bucketer) OverflowBucket

func (b *Bucketer) OverflowBucket() int

OverflowBucket returns the index of the overflow bucket.

func (*Bucketer) Scale

func (b *Bucketer) Scale() float64

Scale returns the scale used to configure this Bucketer.

func (*Bucketer) UnderflowBucket

func (b *Bucketer) UnderflowBucket() int

UnderflowBucket returns the index of the underflow bucket.

func (*Bucketer) Width

func (b *Bucketer) Width() float64

Width returns the bucket width used to configure this Bucketer.

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) Clone

func (d *Distribution) Clone() *Distribution

Clone creates deep copy of this distribution.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL