Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8252093

formula used to calculate decaying variance in numberSeq

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P4
    • 16
    • 16
    • hotspot
    • b14

    Description

      In `src/hotspot/share/utilities/numberSeq.cpp#L44-L46`

      ```
          _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

          Activity

            People

              ayang Albert Yang
              ayang Albert Yang
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: