View source on GitHub |
Windowed estimates of variance.
tfp.substrates.numpy.stats.windowed_variance(
x, low_indices=None, high_indices=None, axis=0, name=None
)
Computes variances among data in the Tensor x
along the given windows:
result[i] = variance(x[low_indices[i]:high_indices[i]+1])
accurately and efficiently. To wit, if K is the size of
low_indices
and high_indices
, and N
is the size of x
along
the given axis
, the computation takes O(K + N) work, O(log(N))
depth (the length of the longest series of operations that are
performed sequentially), and only uses O(1) TensorFlow kernel
invocations. The underlying algorithm is an adaptation of the
streaming reduction for accurate variance computations given in [1].
This function can be useful for assessing the behavior over time of trailing-window estimators from some iterative process, such as the last half of an MCMC chain.
Suppose x
has shape Bx + [N] + E
, where the Bx
component has
rank axis
, and low_indices
and high_indices
broadcast to shape
[M]
. Then each element of low_indices
and high_indices
must be between 0 and N+1, and the shape of the output will be
Bx + [M] + E
. Batch shape in the indices is not currently supported.
The default windows are
[0, 1), [1, 2), [1, 3), [2, 4), [2, 5), ...
This corresponds to analyzing x
as though it were streaming, for
example successive states of an MCMC sampler, and we were interested
in the variance of the last half of the data at each point.
Returns | |
---|---|
variances
|
A numeric Tensor holding the windowed variances of
x along the axis dimension.
|
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