Details

Enhancement

Resolution: Fixed

P4

16

b14
Description
In `src/hotspot/share/utilities/numberSeq.cpp#L44L46`
```
_davg = (1.0  _alpha) * val + _alpha * _davg;
double diff = val  _davg;
_dvariance = (1.0  _alpha) * diff * diff + _alpha * _dvariance;
```
The way how decaying variance is calculated doesn't match the description in
https://en.wikipedia.org/wiki/Moving_average#Exponentially_weighted_moving_variance_and_standard_deviation
Note that the formula in Wikipedia page use alpha, but that alpha is actually corresponding to `1.0_alpha` in the openjdk source.
If one translates the formula in the wikipedia page to openjdk source, it should be:
```
double diff = val  _davg;
_davg = _davg + (1.0  _alpha) * diff; // or the original code (they are the same) _davg = (1.0  _alpha) * val + _alpha * _davg;
_dvariance = _alpha ( _dvariance + (1.0  _alpha) * diff * diff); // the one is differennt
```
The formula derivation is shown "Incremental calculation of weighted mean and variance" by Tony Finch, pdf available at https://fanf2.user.srcf.net/hermes/doc/antiforgery/stats.pdf
```
_davg = (1.0  _alpha) * val + _alpha * _davg;
double diff = val  _davg;
_dvariance = (1.0  _alpha) * diff * diff + _alpha * _dvariance;
```
The way how decaying variance is calculated doesn't match the description in
https://en.wikipedia.org/wiki/Moving_average#Exponentially_weighted_moving_variance_and_standard_deviation
Note that the formula in Wikipedia page use alpha, but that alpha is actually corresponding to `1.0_alpha` in the openjdk source.
If one translates the formula in the wikipedia page to openjdk source, it should be:
```
double diff = val  _davg;
_davg = _davg + (1.0  _alpha) * diff; // or the original code (they are the same) _davg = (1.0  _alpha) * val + _alpha * _davg;
_dvariance = _alpha ( _dvariance + (1.0  _alpha) * diff * diff); // the one is differennt
```
The formula derivation is shown "Incremental calculation of weighted mean and variance" by Tony Finch, pdf available at https://fanf2.user.srcf.net/hermes/doc/antiforgery/stats.pdf
Attachments
Issue Links
 relates to

JDK8252859 Inconsistent use of alpha in class AbsSeq
 Resolved