caio.co/de/go-tdigest


Make serialization compatible with the java version 💬 by Caio 10 years ago (log)
This patch adjusts how deltas are encoded so it behaves exactly the same
as the reference implementation. A test is added to make sure this
doesn't break in the future.

Tree


T-Digest

A map-reduce and parallel streaming friendly data-structure for accurate quantile approximation.

This package provides a very crude implementation of Ted Dunning's t-digest data structure in Go.

Build Status GoDoc

Installation

go get github.com/caio/go-tdigest

Usage

package main

import (
        "fmt"
        "math/rand"

        "github.com/caio/go-tdigest"
)

func main() {
        var t = tdigest.New(100)

        for i := 0; i < 10000; i++ {
                t.Add(rand.Float64(), 1)
        }

        fmt.Printf("p(.5) = %.6f\n", t.Percentile(0.5))
}

Disclaimer

I've written this solely with the purpose of understanding how the data-structure works, it hasn't been throughly verified nor have I bothered with optimizations for now.

References

This is a very simple 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.