β I wrote a series of posts in August 2024 about histograms. Itβs a year later, and I felt compelled to condense them today. On second thought, this work is entirely over-shadowed by my post from September 2024 about Modeling Systems With Generating Functions. The only thing relevant from Augustβs posts is the following fact:
β There exists a moment bound tighter than the Chernoff bound.
However, this result only shows that such a bound exists, not that it exists for a small . In practice, computing and storing is both computationally expensive and likely to overflow. There are a few approaches we can take to mitigate that risk.
Store Log of Observations β can store the moments of instead of . This is still a valid bound because is non-decreasing.
Use Online Mean β can maintain online means of rather storing .
// Observe - implemented w. the two strategies mentioned above...
func (mh *momentsHistogram) Observe(o uint64) {
mh.tot++
var b = bits.Len64(o)&0x0000003f // bits.Len64(o) == βlog2(o)β
var c = (mh.tot - 1) / mh.tot
for m := 0; m < et.n; m++ {
// calculate running avg. - divide and then add, cannot keep full sum
// (even for log-moments) w.o. overflow coming quickly...
mh.mmts[m] *= c
mh.mmts[m] += (math.Pow(b, float64(m)) / et.tot)
}
}