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

formula used to calculate decaying variance in numberSeq

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 16
    • Fix Version/s: 16
    • Component/s: hotspot
    • Subcomponent:
    • Resolved In Build:
      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

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

                Dates

                Created:
                Updated:
                Resolved: