View source on GitHub |
Auto correlation along one axis.
tfp.stats.auto_correlation(
x,
axis=-1,
max_lags=None,
center=True,
normalize=True,
name='auto_correlation'
)
Given a 1-D
wide sense stationary (WSS) sequence X
, the auto correlation
RXX
may be defined as (with E
expectation and Conj
complex conjugate)
RXX[m] := E{ W[m] Conj(W[0]) } = E{ W[0] Conj(W[-m]) },
W[n] := (X[n] - MU) / S,
MU := E{ X[0] },
S**2 := E{ (X[0] - MU) Conj(X[0] - MU) }.
This function takes the viewpoint that x
is (along one axis) a finite
sub-sequence of a realization of (WSS) X
, and then uses x
to produce an
estimate of RXX[m]
as follows:
After extending x
from length L
to inf
by zero padding, the auto
correlation estimate rxx[m]
is computed for m = 0, 1, ..., max_lags
as
rxx[m] := (L - m)**-1 sum_n w[n + m] Conj(w[n]),
w[n] := (x[n] - mu) / s,
mu := L**-1 sum_n x[n],
s**2 := L**-1 sum_n (x[n] - mu) Conj(x[n] - mu)
The error in this estimate is proportional to 1 / sqrt(len(x) - m)
, so users
often set max_lags
small enough so that the entire output is meaningful.
Note that since mu
is an imperfect estimate of E{ X[0] }
, and we divide by
len(x) - m
rather than len(x) - m - 1
, our estimate of auto correlation
contains a slight bias, which goes to zero as len(x) - m --> infinity
.
Returns | |
---|---|
rxx : Tensor of same dtype as x . rxx.shape[i] = x.shape[i] for
i != axis , and rxx.shape[axis] = max_lags + 1 .
|
Raises | |
---|---|
TypeError
|
If x is not a supported type.
|