HarmonicMeanAggregator

A HarmonicMeanAggregator is an Aggregator that calculates the harmonic mean of numeric values, returning the harmonic mean as a Double. If no values were encountered, then the returned harmonic mean is Double.NaN. If any encountered value is zero, then the harmonic mean is Double.NaN. If the sum of all values is zero, then the harmonic mean is Double.NaN. This Aggregator overrides the terminateDoubleDouble method, so that the harmonic mean is also available as a DoubleDouble. This allows the harmonic mean to be used by other Aggregators as a high-precision DoubleDouble.

Usage

Create and use a HarmonicMeanAggregator, with one of the following methods:

  • Aggregator agg = new HarmonicMeanAggregator("property");
  • Aggregator agg = Aggregator.getAggregator("HarmonicMean(property)");

The values returned by the property of the object must be numeric.

The harmonic mean is calculated by dividing n by the sum of all values, where n is the number of values.