tfp.experimental.stats.RunningMean

Holds metadata for and computes a running 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. If more than one sample is accepted and chunking is enabled, the chunked axis will define chunking semantics for all samples.

RunningMean objects do not hold state information. That information, which includes intermediate calculations, are held in a RunningMeanState as returned via initialize and update method calls.

RunningMean is meant to serve general streaming expectations. For a specialized version that fits streaming over MCMC samples, see ExpectationsReducer in tfp.experimental.mcmc.

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.

Methods

finalize

View source

Finalizes expectation computation for the state.

If the finalized method is invoked on a running state of no inputs, RunningMean will return a corresponding structure of tf.zeros.

Args
state RunningMeanState that represents the current state of running statistics.

Returns
mean An estimate of the mean.

initialize

View source

Initializes an empty RunningMeanState.

Returns
state RunningMeanState representing a stream of no inputs.

update

View source

Update the RunningMeanState 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
state RunningMeanState that represents the current state of running statistics.
new_sample Incoming Tensor sample with shape and dtype compatible with those used to form the RunningMeanState.
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
state RunningMeanState with updated calculations.

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