package quantile
import "github.com/theupdateframework/notary/Godeps/_workspace/src/github.com/beorn7/perks/quantile"
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 ¶
- type Sample
- type Samples
- type Stream
- func NewHighBiased(epsilon float64) *Stream
- func NewLowBiased(epsilon float64) *Stream
- func NewTargeted(targets map[float64]float64) *Stream
- func (s *Stream) Count() int
- func (s *Stream) Insert(v float64)
- func (s *Stream) Merge(samples Samples)
- func (s *Stream) Query(q float64) float64
- func (s *Stream) Reset()
- func (s *Stream) Samples() Samples
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 (Samples) Less ¶
func (Samples) Swap ¶
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) Insert ¶
Insert inserts v into the stream.
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.
func (*Stream) Reset ¶
func (s *Stream) Reset()
Reset reinitializes and clears the list reusing the samples buffer memory.
func (*Stream) Samples ¶
Samples returns stream samples held by s.
Source Files ¶
- Version
- v0.2.0
- Published
- Feb 25, 2016
- Platform
- linux/amd64
- Imports
- 2 packages
- Last checked
- 2 days ago –
Tools for package owners.