Class CompensatedSum

java.lang.Object
org.elasticsearch.search.aggregations.metrics.CompensatedSum

public class CompensatedSum
extends java.lang.Object
Used to calculate sums using the Kahan summation algorithm.

The Kahan summation algorithm (also known as compensated summation) reduces the numerical errors that occur when adding a sequence of finite precision floating point numbers. Numerical errors arise due to truncation and rounding. These errors can lead to numerical instability.

See Also:
Kahan Summation Algorithm
  • Constructor Summary

    Constructors
    Constructor Description
    CompensatedSum​(double value, double delta)
    Used to calculate sums using the Kahan summation algorithm.
  • Method Summary

    Modifier and Type Method Description
    CompensatedSum add​(double value)
    Increments the Kahan sum by adding a value without a correction term.
    CompensatedSum add​(double value, double delta)
    Increments the Kahan sum by adding two sums, and updating the correction term for reducing numeric errors.
    double delta()
    The correction term.
    void reset​(double value, double delta)
    Resets the internal state to use the new value and compensation delta
    double value()
    The value of the sum.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CompensatedSum

      public CompensatedSum​(double value, double delta)
      Used to calculate sums using the Kahan summation algorithm.
      Parameters:
      value - the sum
      delta - correction term
  • Method Details

    • value

      public double value()
      The value of the sum.
    • delta

      public double delta()
      The correction term.
    • add

      public CompensatedSum add​(double value)
      Increments the Kahan sum by adding a value without a correction term.
    • reset

      public void reset​(double value, double delta)
      Resets the internal state to use the new value and compensation delta
    • add

      public CompensatedSum add​(double value, double delta)
      Increments the Kahan sum by adding two sums, and updating the correction term for reducing numeric errors.