Help protect the Great Barrier Reef with TensorFlow on Kaggle Join Challenge

tfp.experimental.stats.RunningMean

Computes a running mean.

Inherits From: AutoCompositeTensor

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.

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

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

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_unflatten

View source

update

View source

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