Class CompensatedSum
- java.lang.Object
-
- org.apache.flink.api.java.summarize.aggregation.CompensatedSum
-
- All Implemented Interfaces:
Serializable
@Internal public class CompensatedSum extends Object implements Serializable
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, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static CompensatedSumZERO
-
Constructor Summary
Constructors Constructor Description CompensatedSum(double value, double delta)Used to calculate sums using the Kahan summation algorithm.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CompensatedSumadd(double value)Increments the Kahan sum by adding a value without a correction term.CompensatedSumadd(double value, double delta)Increments the Kahan sum by adding a value and a correction term.CompensatedSumadd(CompensatedSum other)Increments the Kahan sum by adding two sums, and updating the correction term for reducing numeric errors.doubledelta()The correction term.doublevalue()The value of the sum.
-
-
-
Field Detail
-
ZERO
public static final CompensatedSum ZERO
-
-
Method Detail
-
value
public double value()
The value of the sum.
-
delta
public double delta()
The correction term.
-
add
public CompensatedSum add(double value, double delta)
Increments the Kahan sum by adding a value and a correction term.
-
add
public CompensatedSum add(double value)
Increments the Kahan sum by adding a value without a correction term.
-
add
public CompensatedSum add(CompensatedSum other)
Increments the Kahan sum by adding two sums, and updating the correction term for reducing numeric errors.
-
-