tff.aggregators.MeanFactory
Stay organized with collections
Save and categorize content based on your preferences.
Aggregation factory for weighted mean.
Inherits From: WeightedAggregationFactory
tff.aggregators.MeanFactory(
value_sum_factory: Optional[tff.aggregators.UnweightedAggregationFactory
] = None,
weight_sum_factory: Optional[tff.aggregators.UnweightedAggregationFactory
] = None,
no_nan_division: bool = False
)
Used in the notebooks
The created tff.templates.AggregationProcess
computes the weighted mean of
values placed at CLIENTS
, and outputs the mean placed at SERVER
.
The input arguments of the next
attribute of the process returned by
create
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
.
Methods
create
View source
create(
value_type: factory.ValueType, weight_type: factory.ValueType
) -> tff.templates.AggregationProcess
Creates a tff.aggregators.AggregationProcess
with weights.
The provided value_type
and weight_type
are non-federated tff.Type
s.
That is, neither is a tff.FederatedType
.
The returned tff.aggregators.AggregationProcess
will be created
for aggregation of pairs of values matching value_type
and weight_type
placed at tff.CLIENTS
. That is, its next
method will expect type
<S@SERVER, {value_type}@CLIENTS, {weight_type}@CLIENTS>
, where S
is the
unplaced return type of its initialize
method.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-09-20 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-09-20 UTC."],[],[],null,["# tff.aggregators.MeanFactory\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/federated/blob/v0.87.0 Version 2.0, January 2004 Licensed under the Apache License, Version 2.0 (the) |\n\nAggregation factory for weighted mean.\n\nInherits From: [`WeightedAggregationFactory`](../../tff/aggregators/WeightedAggregationFactory) \n\n tff.aggregators.MeanFactory(\n value_sum_factory: Optional[../../tff/aggregators/UnweightedAggregationFactory] = None,\n weight_sum_factory: Optional[../../tff/aggregators/UnweightedAggregationFactory] = None,\n no_nan_division: bool = False\n )\n\n### Used in the notebooks\n\n| Used in the tutorials |\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [Tuning recommended aggregations for learning](https://www.tensorflow.org/federated/tutorials/tuning_recommended_aggregators) - [Composing Learning Algorithms](https://www.tensorflow.org/federated/tutorials/composing_learning_algorithms) |\n\nThe created [`tff.templates.AggregationProcess`](../../tff/templates/AggregationProcess) computes the weighted mean of\nvalues placed at `CLIENTS`, and outputs the mean placed at `SERVER`.\n\nThe input arguments of the `next` attribute of the process returned by\n`create` are `\u003cstate, value, weight\u003e`, where `weight` is a scalar broadcasted\nto the structure of `value`, and the weighted mean refers to the expression\n`sum(value * weight) / sum(weight)`.\n\nThe implementation is parameterized by two inner aggregation factories\nresponsible for the summations above, with the following high-level steps.\n\n- Multiplication of `value` and `weight` at `CLIENTS`.\n- Delegation to inner `value_sum_factory` and `weight_sum_factory` to realize the sum of weighted values and weights.\n- Division of summed weighted values and summed weights at `SERVER`.\n\nNote that the the division at `SERVER` can protect against division by 0, as\nspecified by `no_nan_division` constructor argument.\n\nThe `state` is the composed `state` of the aggregation processes created by\nthe two inner aggregation factories. The same holds for `measurements`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `value_sum_factory` | An optional [`tff.aggregators.UnweightedAggregationFactory`](../../tff/aggregators/UnweightedAggregationFactory) responsible for summation of weighted values. If not specified, [`tff.aggregators.SumFactory`](../../tff/aggregators/SumFactory) is used. |\n| `weight_sum_factory` | An optional [`tff.aggregators.UnweightedAggregationFactory`](../../tff/aggregators/UnweightedAggregationFactory) responsible for summation of weights. If not specified, [`tff.aggregators.SumFactory`](../../tff/aggregators/SumFactory) is used. |\n| `no_nan_division` | A bool. If True, the computed mean is 0 if sum of weights is equal to 0. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `TypeError` | If provided `value_sum_factory` or `weight_sum_factory` is not an instance of [`tff.aggregators.UnweightedAggregationFactory`](../../tff/aggregators/UnweightedAggregationFactory). |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `create`\n\n[View source](https://github.com/tensorflow/federated/blob/v0.87.0\nVersion 2.0, January 2004\nLicensed under the Apache License, Version 2.0 (the) \n\n create(\n value_type: factory.ValueType, weight_type: factory.ValueType\n ) -\u003e ../../tff/templates/AggregationProcess\n\nCreates a `tff.aggregators.AggregationProcess` with weights.\n\nThe provided `value_type` and `weight_type` are non-federated [`tff.Type`](../../tff/types/Type)s.\nThat is, neither is a [`tff.FederatedType`](../../tff/types/FederatedType).\n\nThe returned `tff.aggregators.AggregationProcess` will be created\nfor aggregation of pairs of values matching `value_type` and `weight_type`\nplaced at [`tff.CLIENTS`](../../tff#CLIENTS). That is, its `next` method will expect type\n`\u003cS@SERVER, {value_type}@CLIENTS, {weight_type}@CLIENTS\u003e`, where `S` is the\nunplaced return type of its `initialize` method.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|---------------|-----------------------------------------------------|\n| `value_type` | A non-federated [`tff.Type`](../../tff/types/Type). |\n| `weight_type` | A non-federated [`tff.Type`](../../tff/types/Type). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A [`tff.templates.AggregationProcess`](../../tff/templates/AggregationProcess). ||\n\n\u003cbr /\u003e"]]