tfp.experimental.stats.RunningCentralMoments

Holds metadata for and computes running central moments.

RunningCentralMoments will compute arbitrary central moments in streaming fashion following the formula proposed by Philippe Pebay (2008) [1]. For reference, the formula we refer to is the incremental version of arbitrary moments (equation 2.9). Since the algorithm computes moments as a function of lower ones, even if not requested, all lower moments will be computed as well. The moments that are actually returned is specified by the moment parameter at initialization. Note, while any arbitrarily high central moment is theoretically supported, RunningCentralMoments cannot guarantee numerical stability for all moments.

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

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

shape Python Tuple or TensorShape representing the shape of incoming samples.
moment Integer or iterable of integers that represent the desired moments to return.
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 streaming computation for all central moments.

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

Returns
all_moments A Tensor representing estimates of the requested central moments. Its leading dimension indexes the moment, in order of those requested (i.e. in order of self.moment).

initialize

View source

Initializes an empty RunningCentralMomentsState.

The RunningCentralMomentsState contains a RunningMeanState and a Tensor representing the sum of exponentiated residuals. The sum of exponentiated residuals is a Tensor of shape (self.max_moment - 1, self.shape), which contains the sum of residuals raised to the nth power, for all 2 <= n <= self.max_moment.

Returns
state RunningCentralMomentsState representing a stream of no inputs.

update

View source

Update the RunningCentralMomentsState with a new sample.

Args
state RunningCentralMomentsState that represents the current state of running statistics.
new_sample Incoming Tensor sample with shape and dtype compatible with those used to form the RunningCentralMomentsState.

Returns
state RunningCentralMomentsState with updated calculations.