Documentation ¶
Overview ¶
Example ¶
package main import ( "fmt" "github.com/axiomhq/quantiles" ) func main() { 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 ¶
- type Sketch
- func (stream *Sketch) ApproximationError(level int64) (float64, error)
- func (stream *Sketch) FinalSummary() (*Summary, error)
- func (stream *Sketch) Finalize() error
- func (stream *Sketch) GenerateBoundaries(numBoundaries int64) ([]float64, error)
- func (stream *Sketch) GenerateQuantiles(numQuantiles int64) ([]float64, error)
- func (stream *Sketch) MaxDepth() int
- func (stream *Sketch) Push(value float64, weight float64) error
- func (stream *Sketch) PushSummary(summary []SumEntry) error
- func (stream *Sketch) Quantile(q float64) (float64, error)
- type SumEntry
- type Summary
- func (sum *Summary) ApproximationError() float64
- func (sum *Summary) Clear()
- func (sum *Summary) Entries() []SumEntry
- func (sum *Summary) GenerateBoundaries(numBoundaries int64) []float64
- func (sum *Summary) GenerateQuantiles(numQuantiles int64) []float64
- func (sum *Summary) MaxValue() float64
- func (sum *Summary) Merge(other *Summary)
- func (sum *Summary) MinValue() float64
- func (sum *Summary) Quantile(q float64) (float64, error)
- func (sum *Summary) Size() int64
- func (sum *Summary) TotalWeight() float64
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Sketch ¶
type Sketch struct {
// contains filtered or unexported fields
}
Sketch ...
func NewDefault ¶
func NewDefault() *Sketch
NewDefault returns a new Sketch with the eps = 0.01 and maxElements 1000
func (*Sketch) ApproximationError ¶
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 ¶
FinalSummary ...
func (*Sketch) GenerateBoundaries ¶
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 ¶
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) PushSummary ¶
PushSummary pushes full summary while maintaining approximation error invariants.
type SumEntry ¶
type SumEntry struct {
// contains filtered or unexported fields
}
SumEntry represents a summary entry
type Summary ¶
type Summary struct {
// contains filtered or unexported fields
}
Summary is a summarizes the stream entries
func (*Summary) ApproximationError ¶
ApproximationError ...
func (*Summary) GenerateBoundaries ¶
GenerateBoundaries ...
func (*Summary) GenerateQuantiles ¶
GenerateQuantiles returns a slice of float64 of size numQuantiles+1, the ith entry is the `i * 1/numQuantiles+1` quantile
func (*Summary) Merge ¶
Merge another summary into the this summary (great for esimating quantiles over several streams)
func (*Summary) TotalWeight ¶
TotalWeight returns the total weight of the summary