Skip to content

geometric_mean

relationalai.semantics.std.aggregates
geometric_mean(*args: AggValue) -> Aggregate

Compute the geometric mean of values using the exp-log trick.

geometric_mean(x) = (x1 * x2 * ... * xn) ** (1/n) = exp(mean(ln(x))). Defined for non-negative values: a zero input forces the result to 0.0 (exp(-inf) = 0.0 by IEEE 754); a negative input forces the result to NaN. Results are floating-point approximations — integer inputs are cast to Float before aggregation.

Parameters

  • *args

    (AggValue, default: ()) - Values to compute the geometric mean over. Can include Distinct wrapper for distinct aggregation.

Returns

  • Aggregate - An Aggregate representing the geometric mean. Always returns Float.

Examples

Compute geometric mean of growth rates:

select(aggregates.geometric_mean(Investment.growth_rate))

Compute geometric mean per portfolio:

select(Portfolio.name, aggregates.geometric_mean(Investment.growth_rate).per(Portfolio))