// 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++ }