tff.aggregators.MeanFactory

AggregationProcessFactory for mean.

Inherits From: AggregationProcessFactory

The created tff.templates.AggregationProcess computes a weighted mean of values placed at CLIENTS, and outputs the mean placed at SERVER.

The input arguments of the next attribute of the process are <state, value, weight>, where weight is a scalar broadcasted to the structure of value, and the weighted mean refers to the expression sum(value * weight) / sum(weight).

The implementation is parameterized by two inner aggregation factories responsible for the summations above, with the following high-level steps.

  • Multiplication of value and weight at CLIENTS.
  • Delegation to inner value_sum_factory and weight_sum_factory to realize the sum of weighted values and weights.
  • Division of summed weighted values and summed weights at SERVER.

Note that the the division at SERVER can protect against division by 0, as specified by no_nan_division constructor argument.

The state is the composed state of the aggregation processes created by the two inner aggregation factories. The same holds for measurements.

value_sum_factory An optional tff.aggregators.AggregationProcessFactory responsible for summation of weighted values. If not specified, tff.aggregators.SumFactory is used.
weight_sum_factory An optional tff.aggregators.AggregationProcessFactory responsible for summation of weights. If not specified, tff.aggregators.SumFactory is used.
no_nan_division A bool. If True, the computed mean is 0 if sum of weights is equal to 0.

TypeError If provided value_sum_factory or weight_sum_factory is not an instance of tff.aggregators.AggregationProcessFactory.

Methods

create

View source

Creates a tff.aggregators.AggregationProcess aggregating value_type.

The provided value_type is a non-federated tff.Type object, that is, value_type.is_federated() should return False. Provided value_type must be a tff.TensorType or a tff.StructType.

The returned tff.aggregators.AggregationProcess will be created for computation of a weighted mean of values matching value_type. That is, its next method will expect type <S@SERVER, {value_type}@CLIENTS, {float32}@CLIENTS>, where S is the unplaced return type of its initialize method and all elements of value_type must be of floating dtype.

Args
value_type A tff.Type without placement.

Returns
A tff.templates.AggregationProcess.