Activity
-
lint fixes by Caio 6 months ago
-
meta: link to issues by Caio 8 months ago
-
Fix comment for AddWeighted by Michael Coopersmith 10 months ago
- Tag v4.0.1 created by Caio on commit 428259572a 2 years ago
-
go tdigest: only create a newLocalRNG if one is not provided by options 💬 by Zach Dylag 2 years ago
Allocating and seeding rand objects can be a surprisingly expensive operation. Especially if the user is already re-using RNGs, or needs to generate their own for whatever reason, this extra setup can be a lot of overhead for an object that does not get used.
- Tag v4.0.0 created by Caio on commit 11d00f0ab3 2 years ago
-
Migrate to Go Modules by Caio 2 years ago
-
migration to modules: get rid of `dep` stuff by Caio 2 years ago
- Tag v3.1.0 created by Caio on commit 6d14e0c285 5 years ago
T-Digest
A fast map-reduce and parallel streaming friendly data-structure for accurate quantile approximation.
This package provides an implementation of Ted Dunning's t-digest data structure in Go.
Project Status
This project is actively maintained. We are happy to collaborate on features and issues if/when they arrive.
Installation
This package uses go modules. Our releases are tagged and signed following the Semantic Versioning scheme.
go get github.com/caio/go-tdigest/v4
Example Usage
package main
import (
"fmt"
"math/rand"
"github.com/caio/go-tdigest/v4"
)
func main() {
// Analogue to tdigest.New(tdigest.Compression(100))
t, _ := tdigest.New()
for i := 0; i < 10000; i++ {
// Analogue to t.AddWeighted(rand.Float64(), 1)
t.Add(rand.Float64())
}
fmt.Printf("p(.5) = %.6f\n", t.Quantile(0.5))
fmt.Printf("CDF(Quantile(.5)) = %.6f\n", t.CDF(t.Quantile(0.5)))
}
Configuration
You can configure your digest upon creation with options documented at options.go. Example:
// Construct a digest with compression=200 and its own
// (thread-unsafe) RNG seeded with 0xCA10:
digest, _ := tdigest.New(
tdigest.Compression(200),
tdigest.LocalRandomNumberGenerator(0xCA10),
)
References
This is a port of the reference implementation with some ideas borrowed from the python version. If you wanna get a quick grasp of how it works and why it's useful, this video and companion article is pretty helpful.