Documentation ¶
Overview ¶
Package quantile computes approximate quantiles over an unbounded data stream within low memory and CPU bounds.
A small amount of accuracy is traded to achieve the above properties.
Multiple streams can be merged before calling Query to generate a single set of results. This is meaningful when the streams represent the same type of data. See Merge and Samples.
For more detailed information about the algorithm used, see:
Effective Computation of Biased Quantiles over Data Streams ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Sample ¶
type Sample struct { Value float64 `json:",string"` Width float64 `json:",string"` Delta float64 `json:",string"` }
Sample holds an observed value and meta information for compression. JSON tags have been added for convenience.
type Samples ¶
type Samples []Sample
Samples represents a slice of samples. It implements sort.Interface.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream computes quantiles for a stream of float64s. It is not thread-safe by design. Take care when using across multiple goroutines.
func NewHighBiased ¶
NewHighBiased returns an initialized Stream for high-biased quantiles (e.g. 0.01, 0.1, 0.5) where the needed quantiles are not known a priori, but error guarantees can still be given even for the higher ranks of the data distribution.
The provided epsilon is a relative error, i.e. the true quantile of a value returned by a query is guaranteed to be within 1-(1±Epsilon)*(1-Quantile).
See http://www.cs.rutgers.edu/~muthu/bquant.pdf for time, space, and error properties.
func NewLowBiased ¶
NewLowBiased returns an initialized Stream for low-biased quantiles (e.g. 0.01, 0.1, 0.5) where the needed quantiles are not known a priori, but error guarantees can still be given even for the lower ranks of the data distribution.
The provided epsilon is a relative error, i.e. the true quantile of a value returned by a query is guaranteed to be within (1±Epsilon)*Quantile.
See http://www.cs.rutgers.edu/~muthu/bquant.pdf for time, space, and error properties.
func NewTargeted ¶
NewTargeted returns an initialized Stream concerned with a particular set of quantile values that are supplied a priori. Knowing these a priori reduces space and computation time. The targets map maps the desired quantiles to their absolute errors, i.e. the true quantile of a value returned by a query is guaranteed to be within (Quantile±Epsilon).
See http://www.cs.rutgers.edu/~muthu/bquant.pdf for time, space, and error properties.
func (*Stream) Count ¶
Count returns the total number of samples observed in the stream since initialization.
func (*Stream) Merge ¶
Merge merges samples into the underlying streams samples. This is handy when merging multiple streams from separate threads, database shards, etc.
ATTENTION: This method is broken and does not yield correct results. The underlying algorithm is not capable of merging streams correctly.
func (*Stream) Query ¶
Query returns the computed qth percentiles value. If s was created with NewTargeted, and q is not in the set of quantiles provided a priori, Query will return an unspecified result.