catapult: Compute sample meanlogs
IN-199
Change-Id: Ifd4e4b6779596794650706939e68e74ed5d1af99
diff --git a/catapult/histogram.go b/catapult/histogram.go
index 49aa143..76916af 100644
--- a/catapult/histogram.go
+++ b/catapult/histogram.go
@@ -106,20 +106,26 @@
//
// count, max, meanlogs, mean, min, sum, variance
//
+// meanlogs is the mean of the logs of the absolute values of the given values.
+//
// https://github.com/catapult-project/catapult/issues/4150
func computeRunningStatistics(values []float64) []float64 {
count := float64(len(values))
min := math.Inf(1)
max := math.Inf(-1)
var sum float64
- for _, v := range values {
+ var meanlogs float64
+
+ for i, v := range values {
min = math.Min(min, v)
max = math.Max(max, v)
sum += v
+ // Compute meanlogs as a cumulative moving average:
+ // https://en.wikipedia.org/wiki/Moving_average
+ meanlogs += (math.Log10(math.Abs(v)) - meanlogs) / float64(i)
}
mean := stat.Mean(values, nil)
variance := stat.Variance(values, nil)
- var meanlogs float64 // FIXME(kjharland): figure out what 'meanlogs' is.
return []float64{count, max, meanlogs, mean, min, sum, variance}
}