From 3287aa13a182fdbc9f48f038ba199650ee8379cf Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Wed, 1 Jan 2014 16:04:33 -0800 Subject: [PATCH] Added comments for godoc --- ostat.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ostat.go b/ostat.go index ac1c2a0..6020fcc 100644 --- a/ostat.go +++ b/ostat.go @@ -7,8 +7,12 @@ import ( // from http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Online_algorithm +// These constants are used in initialization of the OnlineStat const ( + // http://en.wikipedia.org/wiki/Statistical_population Population = iota + + // http://en.wikipedia.org/wiki/Sample_(statistics) Sample ) @@ -37,6 +41,10 @@ func NewPopulationStat() *OnlineStat { } } +// Let's say you have already stored some values and want to start an +// OnlineStat mid-stream; This is the function for you! Just provide it with +// the data in the sinature, and you'll get a properly initialized OnlineStat. +// N.b. the typ is either ostat.Population or ostat.Sample func MidStreamStat(n uint64, mean, stddev, min, max float64, typ uint64) *OnlineStat { return &OnlineStat{ n: n, @@ -48,6 +56,7 @@ func MidStreamStat(n uint64, mean, stddev, min, max float64, typ uint64) *Online } } +// this is how you feed new values into your OnlineStat. func (os *OnlineStat) Push(v float64) { os.n += 1 if v < os.Min { @@ -62,6 +71,7 @@ func (os *OnlineStat) Push(v float64) { os.m2 = os.m2 + delta*(v-os.mean) } +// http://en.wikipedia.org/wiki/Expected_value func (os *OnlineStat) Mean() float64 { if os.n == 0 { return 0.0 @@ -69,6 +79,7 @@ func (os *OnlineStat) Mean() float64 { return os.mean } +// http://en.wikipedia.org/wiki/Variance func (os *OnlineStat) Variance() float64 { if os.n == 0 { return 0.0 @@ -76,6 +87,7 @@ func (os *OnlineStat) Variance() float64 { return os.m2 / float64(os.n-os.typ) } +// http://en.wikipedia.org/wiki/Variance func (os *OnlineStat) StdDev() float64 { return math.Sqrt(os.Variance()) }