tdigest

package
v9.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package tdigest provides an implementation of Ted Dunning's t-digest, an approximate histogram for online, distributed applications. For more details, refer to Dunning's paper and the reference implementations.

https://github.com/tdunning/t-digest/blob/master/docs/t-digest-paper/histo.pdf

https://github.com/tdunning/t-digest/blob/master/src/main/java/com/tdunning/math/stats/

Package tdigest is a generated protocol buffer package.

It is generated from these files:
	tdigest/tdigest.proto

It has these top-level messages:
	MergingDigestData
	Centroid

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLengthTdigest = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowTdigest   = fmt.Errorf("proto: integer overflow")
)

Functions

This section is empty.

Types

type Centroid

type Centroid struct {
	Mean    float64   `protobuf:"fixed64,1,opt,name=mean,proto3" json:"mean,omitempty"`
	Weight  float64   `protobuf:"fixed64,2,opt,name=weight,proto3" json:"weight,omitempty"`
	Samples []float64 `protobuf:"fixed64,3,rep,packed,name=samples" json:"samples,omitempty"`
}

func (*Centroid) Descriptor

func (*Centroid) Descriptor() ([]byte, []int)

func (*Centroid) GetMean

func (m *Centroid) GetMean() float64

func (*Centroid) GetSamples

func (m *Centroid) GetSamples() []float64

func (*Centroid) GetWeight

func (m *Centroid) GetWeight() float64

func (*Centroid) Marshal

func (m *Centroid) Marshal() (dAtA []byte, err error)

func (*Centroid) MarshalTo

func (m *Centroid) MarshalTo(dAtA []byte) (int, error)

func (*Centroid) ProtoMessage

func (*Centroid) ProtoMessage()

func (*Centroid) Reset

func (m *Centroid) Reset()

func (*Centroid) Size

func (m *Centroid) Size() (n int)

func (*Centroid) String

func (m *Centroid) String() string

func (*Centroid) Unmarshal

func (m *Centroid) Unmarshal(dAtA []byte) error

type MergingDigest

type MergingDigest struct {
	// contains filtered or unexported fields
}

A t-digest using the merging implementation. MergingDigest is not safe for use by multiple goroutines simultaneously, and its methods must not be invoked concurrently (including Quantile and CDF).

func NewMerging

func NewMerging(compression float64, debug bool) *MergingDigest

Initializes a new merging t-digest using the given compression parameter. Lower compression values result in reduced memory consumption and less precision, especially at the median. Values from 20 to 1000 are recommended in Dunning's paper.

The debug flag adds a list to each centroid, which stores all the samples that have gone into that centroid. While this is useful for statistical analysis, it makes the t-digest significantly slower and requires it to store every sample. This defeats the purpose of using an approximating histogram at all, so this feature should only be used in tests.

func NewMergingFromData

func NewMergingFromData(d *MergingDigestData) *MergingDigest

NewMergingFromData returns a MergingDigest with values initialized from MergingDigestData. This should be the way to generate a MergingDigest from a serialized protobuf.

func (*MergingDigest) Add

func (td *MergingDigest) Add(value float64, weight float64)

Adds a new value to the t-digest, with a given weight that must be positive. Infinities and NaN cannot be added.

func (*MergingDigest) CDF

func (td *MergingDigest) CDF(value float64) float64

Returns the approximate percentage of values in td that are below value (ie the cumulative distribution function). Returns NaN if the digest is empty.

func (*MergingDigest) Centroids

func (td *MergingDigest) Centroids() []Centroid

This function provides direct access to the internal list of centroids in this t-digest. Having access to this list is very important for analyzing the t-digest's statistical properties. However, since it violates the encapsulation of the t-digest, it should be used sparingly. Mutating the returned slice can result in undefined behavior.

This function will panic if debug is not enabled for this t-digest.

func (*MergingDigest) Count

func (td *MergingDigest) Count() float64

func (*MergingDigest) Data

func (td *MergingDigest) Data() *MergingDigestData

Data returns a MergingDigestData based on the MergingDigest (which contains just a subset of the fields). This can be used with proto.Marshal to encode a MergingDigest as a protobuf.

func (*MergingDigest) GobDecode

func (td *MergingDigest) GobDecode(b []byte) error

func (*MergingDigest) GobEncode

func (td *MergingDigest) GobEncode() ([]byte, error)

func (*MergingDigest) Max

func (td *MergingDigest) Max() float64

func (*MergingDigest) Merge

func (td *MergingDigest) Merge(other *MergingDigest)

Merge another digest into this one. Neither td nor other can be shared concurrently during the execution of this method.

func (*MergingDigest) Min

func (td *MergingDigest) Min() float64

func (*MergingDigest) Quantile

func (td *MergingDigest) Quantile(quantile float64) float64

Returns a value such that the fraction of values in td below that value is approximately equal to quantile. Returns NaN if the digest is empty.

func (*MergingDigest) ReciprocalSum

func (td *MergingDigest) ReciprocalSum() float64

func (*MergingDigest) Sum

func (td *MergingDigest) Sum() float64

type MergingDigestData

type MergingDigestData struct {
	// Use values rather than pointers for the Centroid array.  This avoids
	// a ton of code changes and probably a lot of allocations as well.
	MainCentroids []Centroid `protobuf:"bytes,1,rep,name=main_centroids,json=mainCentroids" json:"main_centroids"`
	Compression   float64    `protobuf:"fixed64,2,opt,name=compression,proto3" json:"compression,omitempty"`
	Min           float64    `protobuf:"fixed64,3,opt,name=min,proto3" json:"min,omitempty"`
	Max           float64    `protobuf:"fixed64,4,opt,name=max,proto3" json:"max,omitempty"`
	ReciprocalSum float64    `protobuf:"fixed64,5,opt,name=reciprocalSum,proto3" json:"reciprocalSum,omitempty"`
}

MergingDigestData contains all fields necessary to generate a MergingDigest. This type should generally just be used when serializing MergingDigest's, and doesn't have much of a purpose on its own.

func (*MergingDigestData) Descriptor

func (*MergingDigestData) Descriptor() ([]byte, []int)

func (*MergingDigestData) GetCompression

func (m *MergingDigestData) GetCompression() float64

func (*MergingDigestData) GetMainCentroids

func (m *MergingDigestData) GetMainCentroids() []Centroid

func (*MergingDigestData) GetMax

func (m *MergingDigestData) GetMax() float64

func (*MergingDigestData) GetMin

func (m *MergingDigestData) GetMin() float64

func (*MergingDigestData) GetReciprocalSum

func (m *MergingDigestData) GetReciprocalSum() float64

func (*MergingDigestData) Marshal

func (m *MergingDigestData) Marshal() (dAtA []byte, err error)

func (*MergingDigestData) MarshalTo

func (m *MergingDigestData) MarshalTo(dAtA []byte) (int, error)

func (*MergingDigestData) ProtoMessage

func (*MergingDigestData) ProtoMessage()

func (*MergingDigestData) Reset

func (m *MergingDigestData) Reset()

func (*MergingDigestData) Size

func (m *MergingDigestData) Size() (n int)

func (*MergingDigestData) String

func (m *MergingDigestData) String() string

func (*MergingDigestData) Unmarshal

func (m *MergingDigestData) Unmarshal(dAtA []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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