Weighted Arithmetic Mean

class pumas.aggregation.weighted_arithmetic_mean.WeightedArithmeticMeanAggregation(params: Dict[str, Any] | None = None)[source]

Computes the weighted arithmetic mean of a set of values with corresponding weights.

\[A = \frac{\sum_{i=1}^{n}{w_i x_i}}{\sum_{i=1}^{n}{w_i}}\]
Where:
  • \(A\) is the weighted arithmetic mean

  • \(x_i\) is each value in the values array

  • \(w_i\) is the weight corresponding to each value \(x_i\)

  • \(n\) is the number of elements in values and weights arrays

Usage Example:

>>> from pumas.aggregation import aggregation_catalogue
>>> aggregator_class = aggregation_catalogue.get("arithmetic_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}")
2.30
>>> result = aggregator(values=values, weights=weights) # Same as compute_numeric
>>> print(f"{result:.2f}")
2.30
>>> 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)
2.30+/-0.16
compute_numeric(values: List[float | None], weights: List[float | None] | None = None) float[source]

Compute the weighted arithmetic mean for uncertain float input values.

Parameters:
  • values (List[float]) – The list of numeric 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 summation with uncertainty.

Return type:

float

compute_ufloat(values: List[AffineScalarFunc | None], weights: List[float | None] | None = None) AffineScalarFunc[source]

Compute the weighted arithmetic 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 summation with uncertainty.

Return type:

UFloat