tfp.experimental.stats.RunningMean
Stay organized with collections
Save and categorize content based on your preferences.
Computes a running mean.
Inherits From: AutoCompositeTensor
tfp.experimental.stats.RunningMean(
num_samples, mean
)
In computation, samples can be provided individually or in chunks. A
"chunk" of size M implies incorporating M samples into a single expectation
computation at once, which is more efficient than one by one.
RunningMean
is meant to serve general streaming expectations.
For a specialized version that fits streaming over MCMC samples, see
ExpectationsReducer
in tfp.experimental.mcmc
.
Args |
num_samples
|
A Tensor counting the number of samples
accumulated so far.
|
mean
|
A Tensor broadcast-compatible with num_samples giving the
current mean.
|
Methods
from_example
View source
@classmethod
from_example(
example
)
Initialize an empty RunningMean
.
Args |
example
|
A Tensor . The RunningMean will accept samples
of the same dtype and broadcast-compatible shape as the example.
|
Returns |
state
|
RunningMean representing a stream of no inputs. Note
that by convention, the supplied example is used only for
initialization, but not counted as a sample.
|
from_shape
View source
@classmethod
from_shape(
shape, dtype=tf.float32
)
Initialize an empty RunningMean
.
Args |
shape
|
Python Tuple or TensorShape representing the shape of
incoming samples.
|
dtype
|
Dtype of incoming samples and the resulting statistics.
By default, the dtype is tf.float32 . Any integer dtypes will be
cast to corresponding floats (i.e. tf.int32 will be cast to
tf.float32 ), as intermediate calculations should be performing
floating-point division.
|
Returns |
state
|
RunningMean representing a stream of no inputs.
|
tree_flatten
View source
tree_flatten()
tree_unflatten
View source
@classmethod
tree_unflatten(
_, tensors
)
update
View source
update(
new_sample, axis=None
)
Update the RunningMean
with a new sample.
The update formula is from Philippe Pebay (2008) [1] and is identical to
that used to calculate the intermediate mean in
tfp.experimental.stats.RunningCovariance
and
tfp.experimental.stats.RunningVariance
.
Args |
new_sample
|
Incoming Tensor sample with shape and dtype compatible with
those used to form the RunningMean .
|
axis
|
If chunking is desired, this is an integer that specifies the axis
with chunked samples. For individual samples, set this to None . By
default, samples are not chunked (axis is None).
|
Returns |
mean
|
RunningMean updated to the new sample.
|
References
[1]: Philippe Pebay. Formulas for Robust, One-Pass Parallel Computation of
Covariances and Arbitrary-Order Statistical Moments. Technical Report
SAND2008-6212, 2008.
https://prod-ng.sandia.gov/techlib-noauth/access-control.cgi/2008/086212.pdf
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 2023-11-21 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 2023-11-21 UTC."],[],[],null,["# tfp.experimental.stats.RunningMean\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/probability/blob/v0.23.0/tensorflow_probability/python/experimental/stats/sample_stats.py#L415-L527) |\n\nComputes a running mean.\n\nInherits From: [`AutoCompositeTensor`](../../../tfp/experimental/AutoCompositeTensor) \n\n tfp.experimental.stats.RunningMean(\n num_samples, mean\n )\n\nIn computation, samples can be provided individually or in chunks. A\n\"chunk\" of size M implies incorporating M samples into a single expectation\ncomputation at once, which is more efficient than one by one.\n\n`RunningMean` is meant to serve general streaming expectations.\nFor a specialized version that fits streaming over MCMC samples, see\n`ExpectationsReducer` in [`tfp.experimental.mcmc`](../../../tfp/experimental/mcmc).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------|-----------------------------------------------------------------------------|\n| `num_samples` | A `Tensor` counting the number of samples accumulated so far. |\n| `mean` | A `Tensor` broadcast-compatible with `num_samples` giving the current mean. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `from_example`\n\n[View source](https://github.com/tensorflow/probability/blob/v0.23.0/tensorflow_probability/python/experimental/stats/sample_stats.py#L470-L483) \n\n @classmethod\n from_example(\n example\n )\n\nInitialize an empty `RunningMean`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|-----------|--------------------------------------------------------------------------------------------------------------------|\n| `example` | A `Tensor`. The `RunningMean` will accept samples of the same dtype and broadcast-compatible shape as the example. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `state` | `RunningMean` representing a stream of no inputs. Note that by convention, the supplied example is used only for initialization, but not counted as a sample. |\n\n\u003cbr /\u003e\n\n### `from_shape`\n\n[View source](https://github.com/tensorflow/probability/blob/v0.23.0/tensorflow_probability/python/experimental/stats/sample_stats.py#L449-L468) \n\n @classmethod\n from_shape(\n shape, dtype=tf.float32\n )\n\nInitialize an empty `RunningMean`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `shape` | Python `Tuple` or `TensorShape` representing the shape of incoming samples. |\n| `dtype` | Dtype of incoming samples and the resulting statistics. By default, the dtype is [`tf.float32`](https://www.tensorflow.org/api_docs/python/tf#float32). Any integer dtypes will be cast to corresponding floats (i.e. [`tf.int32`](https://www.tensorflow.org/api_docs/python/tf#int32) will be cast to [`tf.float32`](https://www.tensorflow.org/api_docs/python/tf#float32)), as intermediate calculations should be performing floating-point division. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---------|---------------------------------------------------|\n| `state` | `RunningMean` representing a stream of no inputs. |\n\n\u003cbr /\u003e\n\n### `tree_flatten`\n\n[View source](https://github.com/tensorflow/probability/blob/v0.23.0/tensorflow_probability/python/experimental/stats/sample_stats.py#L442-L443) \n\n tree_flatten()\n\n### `tree_unflatten`\n\n[View source](https://github.com/tensorflow/probability/blob/v0.23.0/tensorflow_probability/python/experimental/stats/sample_stats.py#L445-L447) \n\n @classmethod\n tree_unflatten(\n _, tensors\n )\n\n### `update`\n\n[View source](https://github.com/tensorflow/probability/blob/v0.23.0/tensorflow_probability/python/experimental/stats/sample_stats.py#L485-L522) \n\n update(\n new_sample, axis=None\n )\n\nUpdate the `RunningMean` with a new sample.\n\nThe update formula is from Philippe Pebay (2008) \\[1\\] and is identical to\nthat used to calculate the intermediate mean in\n[`tfp.experimental.stats.RunningCovariance`](../../../tfp/experimental/stats/RunningCovariance) and\n[`tfp.experimental.stats.RunningVariance`](../../../tfp/experimental/stats/RunningVariance).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|--------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `new_sample` | Incoming `Tensor` sample with shape and dtype compatible with those used to form the `RunningMean`. |\n| `axis` | If chunking is desired, this is an integer that specifies the axis with chunked samples. For individual samples, set this to `None`. By default, samples are not chunked (`axis` is None). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|--------|------------------------------------------|\n| `mean` | `RunningMean` updated to the new sample. |\n\n\u003cbr /\u003e\n\n#### References\n\n\\[1\\]: Philippe Pebay. Formulas for Robust, One-Pass Parallel Computation of\nCovariances and Arbitrary-Order Statistical Moments. *Technical Report\nSAND2008-6212* , 2008.\n\u003chttps://prod-ng.sandia.gov/techlib-noauth/access-control.cgi/2008/086212.pdf\u003e"]]