It increments the mean based on a new value
(interval int, inc float64)
| 244 | |
| 245 | // It increments the mean based on a new value |
| 246 | func (k *averageSeries) addIncrementMean(interval int, inc float64) { |
| 247 | currentMean := k.values[interval] |
| 248 | if math.IsNaN(currentMean.mean) && !math.IsNaN(inc) { |
| 249 | k.values[interval] = averageValue{mean: inc, weight: 1} |
| 250 | return |
| 251 | } |
| 252 | currentMean.weight++ |
| 253 | currentMean.add(inc/currentMean.weight - currentMean.mean/currentMean.weight) |
| 254 | k.values[interval] = currentMean |
| 255 | } |
| 256 | |
| 257 | // It calculates the incremental weighted mean using kahan-neumaier summation and a delta approach. |
| 258 | // By adding incremental values we prevent overflow |