diff options
| -rw-r--r-- | stats.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/stats.go b/stats.go new file mode 100644 index 0000000..bc5be7c --- /dev/null +++ b/stats.go @@ -0,0 +1,29 @@ +// Provides some basic statisitcs functionality. Specifically tailored around +// dealing with large streams of data at the moment. +package stats + +import ( + "math" +) + +// Stores the average, standard deviation, and the current number of entities +// processed +type Stats struct { + Mean float64 + Variance float64 + N float64 +} + +// Returns the square root of 1/2 the variance, or Standard Deviation from the +// mean +func (s *Stats) Stdev() float64 { + return math.Sqrt(s.Variance / 2) +} + +// Adds an entry to our struct, taking care of adjusting the Mean and Variance +func (s *Stats) AddEntry(e float64) { + m := s.Mean + s.Mean += (e - m) / s.N + s.Variance += (e - m) * (e - s.Mean) + s.N++ +} |
