Reduces a TFF sequence value given a zero and reduction operator op.
tff.sequence_reduce(value,zero,op)
This method reduces a set of elements of a TFF sequence value, using a given
zero in the algebra (i.e., the result of reducing an empty sequence) of some
type U, and a reduction operator op with type signature (<U,T> -> U)
that incorporates a single T-typed element of value into the U-typed
result of partial reduction. In the special case of T equal to U, this
corresponds to the classical notion of reduction of a set using a commutative
associative binary operator. The generalized reduction (with T not equal to
U) requires that repeated application of op to reduce a set of T always
yields the same U-typed result, regardless of the order in which elements
of T are processed in the course of the reduction.
One can also invoke sequence_reduce on a federated sequence, in which case
the reductions are performed pointwise; under the hood, we construct an
expression of the form
federated_map(x -> sequence_reduce(x, zero, op), value). See also the
discussion on sequence_map.
Args
value
A value that is either a TFF sequence, or a federated sequence.
zero
The result of reducing a sequence with no elements.
op
An operator with type signature (<U,T> -> U), where T is the type of
the elements of the sequence, and U is the type of zero to be used in
performing the reduction.
Returns
The U-typed result of reducing elements in the sequence, or if the value
is federated, a federated U that represents the result of locally
reducing each member constituent of value.
Raises
TypeError
If the arguments are not of the types specified above.
[null,null,["Last updated 2025-01-17 UTC."],[],[],null,["# tff.sequence_reduce\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\nReduces a TFF sequence `value` given a `zero` and reduction operator `op`. \n\n tff.sequence_reduce(\n value, zero, op\n )\n\nThis method reduces a set of elements of a TFF sequence `value`, using a given\n`zero` in the algebra (i.e., the result of reducing an empty sequence) of some\ntype `U`, and a reduction operator `op` with type signature `(\u003cU,T\u003e -\u003e U)`\nthat incorporates a single `T`-typed element of `value` into the `U`-typed\nresult of partial reduction. In the special case of `T` equal to `U`, this\ncorresponds to the classical notion of reduction of a set using a commutative\nassociative binary operator. The generalized reduction (with `T` not equal to\n`U`) requires that repeated application of `op` to reduce a set of `T` always\nyields the same `U`-typed result, regardless of the order in which elements\nof `T` are processed in the course of the reduction.\n\nOne can also invoke `sequence_reduce` on a federated sequence, in which case\nthe reductions are performed pointwise; under the hood, we construct an\nexpression of the form\n`federated_map(x -\u003e sequence_reduce(x, zero, op), value)`. See also the\ndiscussion on `sequence_map`.\n| **Note:** When applied to a federated value this function does the reduce point-wise.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `value` | A value that is either a TFF sequence, or a federated sequence. |\n| `zero` | The result of reducing a sequence with no elements. |\n| `op` | An operator with type signature `(\u003cU,T\u003e -\u003e U)`, where `T` is the type of the elements of the sequence, and `U` is the type of `zero` to be used in performing the reduction. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| The `U`-typed result of reducing elements in the sequence, or if the `value` is federated, a federated `U` that represents the result of locally reducing each member constituent of `value`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|-------------|--------------------------------------------------------|\n| `TypeError` | If the arguments are not of the types specified above. |\n\n\u003cbr /\u003e"]]