tff.aggregators.UnweightedReservoirSamplingFactory
Stay organized with collections
Save and categorize content based on your preferences.
An UnweightedAggregationFactory
for reservoir sampling values.
Inherits From: UnweightedAggregationFactory
tff.aggregators.UnweightedReservoirSamplingFactory(
sample_size: int, return_sampling_metadata: bool = False
)
The created tff.templates.AggregationProcess
samples values placed at
CLIENTS
, and outputs the sample placed at SERVER
.
The process has empty state
. The measurements
of this factory counts the
number of non-finite (NaN
or Inf
values) leaves in the client values
before sampling. Specifically, the returned measurements
has the same
structure as the client value, and every leaf node is a tf.int64
scalar
tensor counting the number of clients having non-finite value in that leaf.
For example, suppose we are aggregating from three clients:
client_value_1 = collections.OrderedDict(a=[1.0, 2.0], b=[1.0, np.nan])
client_value_2 = collections.OrderedDict(a=[np.nan, np.inf], b=[1.0, 2.0])
client_value_3 = collections.OrderedDict(a=[1.0, 2.0], b=[np.inf, np.nan])
Then measurements
will be:
collections.OrderedDict(a=tf.constant(1, dtype=int64),
b=tf.constant(2, dtype=int64)
For more about reservoir sampling see
https://en.wikipedia.org/wiki/Reservoir_sampling
Args |
sample_size
|
An integer specifying the number of clients sampled (by
reservoir sampling algorithm). Values from the sampled clients are
collected at the server (see the class documentation for details).
|
return_sampling_metadata
|
If True, the result property in the returned
tff.templates.MeasuredProcessOutput object contains a dictionary of
sampled values and other sampling metadata (such as random values
generated during reservoir sampling). Otherwise, it only contains the
sampled values.
|
Raises |
TypeError
|
If any argument type mismatches.
|
ValueError
|
If sample_size is not positive.
|
Methods
create
View source
create(
value_type: tff.types.Type
) -> tff.templates.AggregationProcess
Creates a tff.aggregators.AggregationProcess
without weights.
The provided value_type
is a non-federated tff.Type
, that is, not a
tff.FederatedType
.
The returned tff.aggregators.AggregationProcess
will be created for
aggregation of values matching value_type
placed at tff.CLIENTS
.
That is, its next
method will expect type
<S@SERVER, {value_type}@CLIENTS>
, where S
is the unplaced return type of
its initialize
method.
Args |
value_type
|
A non-federated tff.Type .
|
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.UnweightedReservoirSamplingFactory\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\nAn `UnweightedAggregationFactory` for reservoir sampling values.\n\nInherits From: [`UnweightedAggregationFactory`](../../tff/aggregators/UnweightedAggregationFactory) \n\n tff.aggregators.UnweightedReservoirSamplingFactory(\n sample_size: int, return_sampling_metadata: bool = False\n )\n\nThe created [`tff.templates.AggregationProcess`](../../tff/templates/AggregationProcess) samples values placed at\n`CLIENTS`, and outputs the sample placed at `SERVER`.\n\nThe process has empty `state`. The `measurements` of this factory counts the\nnumber of non-finite (`NaN` or `Inf` values) leaves in the client values\n*before* sampling. Specifically, the returned `measurements` has the same\nstructure as the client value, and every leaf node is a [`tf.int64`](https://www.tensorflow.org/api_docs/python/tf#int64) scalar\ntensor counting the number of clients having non-finite value in that leaf.\n\nFor example, suppose we are aggregating from three clients: \n\n client_value_1 = collections.OrderedDict(a=[1.0, 2.0], b=[1.0, np.nan])\n client_value_2 = collections.OrderedDict(a=[np.nan, np.inf], b=[1.0, 2.0])\n client_value_3 = collections.OrderedDict(a=[1.0, 2.0], b=[np.inf, np.nan])\n\nThen `measurements` will be: \n\n collections.OrderedDict(a=tf.constant(1, dtype=int64),\n b=tf.constant(2, dtype=int64)\n\nFor more about reservoir sampling see\n\u003chttps://en.wikipedia.org/wiki/Reservoir_sampling\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `sample_size` | An integer specifying the number of clients sampled (by reservoir sampling algorithm). Values from the sampled clients are collected at the server (see the class documentation for details). |\n| `return_sampling_metadata` | If True, the `result` property in the returned [`tff.templates.MeasuredProcessOutput`](../../tff/templates/MeasuredProcessOutput) object contains a dictionary of sampled values and other sampling metadata (such as random values generated during reservoir sampling). Otherwise, it only contains the sampled values. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|-----------------------------------|\n| `TypeError` | If any argument type mismatches. |\n| `ValueError` | If `sample_size` is not positive. |\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: ../../tff/types/Type\n ) -\u003e ../../tff/templates/AggregationProcess\n\nCreates a `tff.aggregators.AggregationProcess` without weights.\n\nThe provided `value_type` is a non-federated [`tff.Type`](../../tff/types/Type), that is, not a\n[`tff.FederatedType`](../../tff/types/FederatedType).\n\nThe returned `tff.aggregators.AggregationProcess` will be created for\naggregation of values matching `value_type` placed at [`tff.CLIENTS`](../../tff#CLIENTS).\nThat is, its `next` method will expect type\n`\u003cS@SERVER, {value_type}@CLIENTS\u003e`, where `S` is the unplaced return type of\nits `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\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"]]