Weighted Summation¶
- class pumas.aggregation.weighted_summation.WeightedSummationAggregation(params: Dict[str, Any] | None = None)[source]
Computes the weighted summation of a set of values with corresponding weights.
\[A = \sum_{i=1}^{n}{w_i x_i}\]- Where:
\(A\) is the weighted summation
\(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 the values and weights arrays
Usage Example:
>>> from pumas.aggregation import aggregation_catalogue
>>> aggregator_class = aggregation_catalogue.get("summation")
>>> 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 summation for numeric 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.
- Return type:
float
- compute_ufloat(values: List[AffineScalarFunc | None], weights: List[float | None] | None = None) AffineScalarFunc[source]
Compute the weighted summation 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