5.1.1.1.1.4. FedEval.aggregator.mean

5.1.1.1.1.4.1. Module Contents

5.1.1.1.1.4.1.1. Functions

weighted_average(...)

return the weighted average of the given client-side params according to the given weights.

trimmed_mean(→ FedEval.aggregator.ModelWeight.ModelWeights)

Return the coordinate-wise mean of the given client-side params after trimming a certain ratio

FedEval.aggregator.mean.weighted_average(client_params: Iterable[FedEval.aggregator.ModelWeight.ModelWeights], weights: Iterable[float | int]) FedEval.aggregator.ModelWeight.ModelWeights

return the weighted average of the given client-side params according to the given weights.

Parameters:
  • client_params (Iterable[ModelWeights]) – the weights form different clients, ordered like [params1, params2, …]

  • weights (Iterable[Union[float, int]]) – aggregate weights of different clients, usually set according to the clients’ training sample size. E.g., A, B, and C have 10, 20, and 30 images, then the aggregate_weights can be [1/6, 1/3, 1/2] or [10, 20, 30].

Raises:

ValueError – if the number of client params and weights are not the same

Returns:

the aggregated parameters which have the same format with any instance from the client_params

Return type:

ModelWeights

FedEval.aggregator.mean.trimmed_mean(client_params: Iterable[FedEval.aggregator.ModelWeight.ModelWeights], ratio: float = 0.05) FedEval.aggregator.ModelWeight.ModelWeights

Return the coordinate-wise mean of the given client-side params after trimming a certain ratio of the extreme parameter values.

Parameters:
  • client_params (Iterable[ModelWeights]) – The weights from different clients, ordered like [params1, params2, …].

  • ratio (float, optional) – The ratio of extreme parameter values to trim. Should be between 0 and 0.5. Defaults to 0.05.

Raises:

ValueError – If trim_ratio is not in [0, 0.5).

Returns:

The aggregated parameters which have the same format with any instance from the client_params.

Return type:

ModelWeights