File tree 1 file changed +10
-2
lines changed
src/hotspot/share/utilities
1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -41,9 +41,17 @@ void AbsSeq::add(double val) {
41
41
_dvariance = 0.0 ;
42
42
} else {
43
43
// otherwise, calculate both
44
- _davg = (1.0 - _alpha) * val + _alpha * _davg;
44
+ // Formula from "Incremental calculation of weighted mean and variance" by Tony Finch
45
+ // diff := x - mean
46
+ // incr := alpha * diff
47
+ // mean := mean + incr
48
+ // variance := (1 - alpha) * (variance + diff * incr)
49
+ // PDF available at https://fanf2.user.srcf.net/hermes/doc/antiforgery/stats.pdf
50
+ // Note: alpha is actually (1.0 - _alpha) in our code
45
51
double diff = val - _davg;
46
- _dvariance = (1.0 - _alpha) * diff * diff + _alpha * _dvariance;
52
+ double incr = (1.0 - _alpha) * diff;
53
+ _davg += incr;
54
+ _dvariance = _alpha * (_dvariance + diff * incr);
47
55
}
48
56
}
49
57
You can’t perform that action at this time.
0 commit comments