quantile

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2016 License: Apache-2.0 Imports: 2 Imported by: 0

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

http://www.cs.rutgers.edu/~muthu/bquant.pdf

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.

func (Samples) Len

func (a Samples) Len() int

func (Samples) Less

func (a Samples) Less(i, j int) bool

func (Samples) Swap

func (a Samples) Swap(i, j int)

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

func NewHighBiased(epsilon float64) *Stream

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

func NewLowBiased(epsilon float64) *Stream

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

func NewTargeted(targets map[float64]float64) *Stream

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

func (s *Stream) Count() int

Count returns the total number of samples observed in the stream since initialization.

func (*Stream) Insert

func (s *Stream) Insert(v float64)

Insert inserts v into the stream.

func (*Stream) Merge

func (s *Stream) Merge(samples Samples)

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

func (s *Stream) Query(q float64) float64

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.

func (*Stream) Reset

func (s *Stream) Reset()

Reset reinitializes and clears the list reusing the samples buffer memory.

func (*Stream) Samples

func (s *Stream) Samples() Samples

Samples returns stream samples held by s.

Jump to

Keyboard shortcuts

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