quantiles: github.com/axiomhq/quantiles Index | Examples | Files | Directories

package quantiles

import "github.com/axiomhq/quantiles"

Code:

sketch := quantiles.NewDefault()
for i := 0.0; i < 1e6; i++ {
    if err := sketch.Push(i, 1.0); err != nil {
        panic(err)
    }
}
fmt.Print("ApproximationError:")
fmt.Println(sketch.ApproximationError(1))

fmt.Print("Finalize:")
fmt.Println(sketch.Finalize())

fmt.Print("GenerateQuantiles(4):")
fmt.Println(sketch.GenerateQuantiles(4))

fmt.Print("GenerateQuantiles(10):")
fmt.Println(sketch.GenerateQuantiles(10))

sum, err := sketch.FinalSummary()
if err != nil {
    panic(err)
}
fmt.Print("GenerateQuantiles(4):")
fmt.Println(sum.GenerateQuantiles(4))

Output:

ApproximationError:0.006218905472636816 <nil>
Finalize:<nil>
GenerateQuantiles(4):[0 249854 499710 749566 999999] <nil>
GenerateQuantiles(10):[0 98302 200702 299006 401406 499710 598014 700414 798718 900094 999999] <nil>
GenerateQuantiles(4):[0 249854 499710 749566 999999]

Index

Examples

Package Files

buffer.go sketch.go summary.go utils.go

type Sketch Uses

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

Sketch ...

func New Uses

func New(eps float64, maxElements int64) (*Sketch, error)

New returns a new Sketch for a given eps and maxElements

func NewDefault Uses

func NewDefault() *Sketch

NewDefault returns a new Sketch with the eps = 0.01 and maxElements 1000

func (*Sketch) ApproximationError Uses

func (stream *Sketch) ApproximationError(level int64) (float64, error)

ApproximationError calculates approximation error for the specified level. If the passed level is negative, the approximation error for the entire summary is returned. Note that after Finalize is called, only the overall error is available.

func (*Sketch) FinalSummary Uses

func (stream *Sketch) FinalSummary() (*Summary, error)

FinalSummary ...

func (*Sketch) Finalize Uses

func (stream *Sketch) Finalize() error

Finalize flushes approximator and finalizes state.

func (*Sketch) GenerateBoundaries Uses

func (stream *Sketch) GenerateBoundaries(numBoundaries int64) ([]float64, error)

GenerateBoundaries generates requested number of boundaries after finalizing stream. The returned boundaries can be queried using std::lower_bound to get the bucket for a given value. The boundaries, while still guaranteeing approximation bounds, don't necessarily represent the actual quantiles of the distribution. Boundaries are preferable over quantiles when the caller is less interested in the actual quantiles distribution and more interested in getting a representative sample of boundary values.

func (*Sketch) GenerateQuantiles Uses

func (stream *Sketch) GenerateQuantiles(numQuantiles int64) ([]float64, error)

GenerateQuantiles generates requested number of quantiles after finalizing stream. The returned quantiles can be queried using std::lower_bound to get the bucket for a given value.

func (*Sketch) MaxDepth Uses

func (stream *Sketch) MaxDepth() int

MaxDepth ...

func (*Sketch) Push Uses

func (stream *Sketch) Push(value float64, weight float64) error

Push a value and a weight into the stream

func (*Sketch) PushSummary Uses

func (stream *Sketch) PushSummary(summary []SumEntry) error

PushSummary pushes full summary while maintaining approximation error invariants.

func (*Sketch) Quantile Uses

func (stream *Sketch) Quantile(q float64) (float64, error)

Quantile ...

type SumEntry Uses

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

SumEntry represents a summary entry

func (SumEntry) MaxRank Uses

func (se SumEntry) MaxRank() float64

MaxRank returns the entries maximum rank

func (SumEntry) MinRank Uses

func (se SumEntry) MinRank() float64

MinRank returns the entries minimum rank

func (SumEntry) Value Uses

func (se SumEntry) Value() float64

Value returns the entries value

func (SumEntry) Weight Uses

func (se SumEntry) Weight() float64

Weight returns the entries weight

type Summary Uses

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

Summary is a summarizes the stream entries

func (*Summary) ApproximationError Uses

func (sum *Summary) ApproximationError() float64

ApproximationError ...

func (*Summary) Clear Uses

func (sum *Summary) Clear()

Clear reset the summary

func (*Summary) Entries Uses

func (sum *Summary) Entries() []SumEntry

Entries returns all summary entries

func (*Summary) GenerateBoundaries Uses

func (sum *Summary) GenerateBoundaries(numBoundaries int64) []float64

GenerateBoundaries ...

func (*Summary) GenerateQuantiles Uses

func (sum *Summary) GenerateQuantiles(numQuantiles int64) []float64

GenerateQuantiles returns a slice of float64 of size numQuantiles+1, the ith entry is the `i * 1/numQuantiles+1` quantile

func (*Summary) MaxValue Uses

func (sum *Summary) MaxValue() float64

MaxValue returns the max weight value of the summary

func (*Summary) Merge Uses

func (sum *Summary) Merge(other *Summary)

Merge another summary into the this summary (great for esimating quantiles over several streams)

func (*Summary) MinValue Uses

func (sum *Summary) MinValue() float64

MinValue returns the min weight value of the summary

func (*Summary) Quantile Uses

func (sum *Summary) Quantile(q float64) (float64, error)

Quantile returns the value for quantile q

func (*Summary) Size Uses

func (sum *Summary) Size() int64

Size returns the size (num of entries) in the summary

func (*Summary) TotalWeight Uses

func (sum *Summary) TotalWeight() float64

TotalWeight returns the total weight of the summary

Directories

PathSynopsis
demo

Package quantiles imports 3 packages (graph) and is imported by 1 packages. Updated 2018-08-15. Refresh now. Tools for package owners.