Computes the geometric mean of the given numbers. The geometric mean is calculated as: ⁿ√(x₁ × x₂ × ... × xₙ) Example: For numbers [2, 8], the geometric mean is √(2×8) = √16 = 4.0 Note: This method may produce unexpected results for negative numbers, as it computes the real-val
(final Iterable<Double> numbers)
| 74 | * Mean</a> |
| 75 | */ |
| 76 | public static Double geometric(final Iterable<Double> numbers) { |
| 77 | checkIfNotEmpty(numbers); |
| 78 | double product = StreamSupport.stream(numbers.spliterator(), false).reduce(1d, (x, y) -> x * y); |
| 79 | int size = IterableUtils.size(numbers); |
| 80 | return Math.pow(product, 1.0 / size); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Computes the harmonic mean of the given numbers. |