Weighted Harmonic Mean¶
- class pumas.aggregation.weighted_harmonic_mean.WeightedHarmonicMeanAggregation(params: Dict[str, Any] | None = None)[source]
Computes the weighted harmonic mean of a set of values with corresponding weights.
\[H = \frac{\sum_{i=1}^{n} w_i}{\sum_{i=1}^{n} \frac{w_i}{x_i}}\]- Where:
\(H\) is the weighted harmonic mean
\(x_i\) are the values
\(w_i\) are the corresponding weights
\(n\) is the number of observations
Example: >>> from pumas.aggregation import aggregation_catalogue
>>> aggregator_class = aggregation_catalogue.get("harmonic_mean")
>>> aggregator = aggregator_class()
>>> values = [1.0, 2.0, 3.0] >>> weights = [0.2, 0.3, 0.5] >>> result = aggregator.compute_numeric(values=values, weights=weights) >>> print(f"{result:.2f}") 1.94
>>> result = aggregator(values=values, weights=weights) # Same as compute_numeric >>> print(f"{result:.2f}") 1.94
>>> from uncertainties import ufloat >>> values = [ufloat(1.0, 0.1), ufloat(2.0, 0.2), ufloat(3.0, 0.3)] >>> weights = [0.2, 0.3, 0.5] >>> result = aggregator.compute_ufloat(values=values, weights=weights) >>> print(result) 1.94+/-0.11
- compute_numeric(values: List[float | None], weights: List[float | None] | None = None) float[source]
Compute the weighted harmonic mean for uncertain float input values.
- Parameters:
values (List[float]) – The list of uncertain float values to be aggregated.
weights (Optional[List[float]]) – The list of weights corresponding to each value. If None, equal weights are assumed.
- Returns:
The computed weighted harmonic mean with uncertainty.
- Return type:
UFloat
- compute_ufloat(values: List[AffineScalarFunc | None], weights: List[float | None] | None = None) AffineScalarFunc[source]
Compute the weighted harmonic mean for uncertain float input values.
- Parameters:
values (List[UFloat]) – The list of uncertain float values to be aggregated.
weights (Optional[List[float]]) – The list of weights corresponding to each value. If None, equal weights are assumed.
- Returns:
The computed weighted harmonic mean with uncertainty.
- Return type:
UFloat