diff options
| author | Mitch Riedstra <mitch@riedstra.us> | 2019-03-09 00:45:08 -0500 |
|---|---|---|
| committer | Mitch Riedstra <mitch@riedstra.us> | 2019-03-09 00:45:08 -0500 |
| commit | cc9fb4ed26c47ff2b195b3a986b4beee7d0998e8 (patch) | |
| tree | 2f4ceb9f895701d17a032406ee4e2d4025d5ae9c /stats.go | |
| download | stats-cc9fb4ed26c47ff2b195b3a986b4beee7d0998e8.tar.gz stats-cc9fb4ed26c47ff2b195b3a986b4beee7d0998e8.tar.xz | |
initial
Diffstat (limited to 'stats.go')
| -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++ +} |
