pyhctsa.operations.stationarity.sliding_window

pyhctsa.operations.stationarity.sliding_window(y, window_stat='mean', across_win_stat='std', num_seg=5, inc_move=2, asym_tau=1)

Sliding window measures of stationarity.

Slides a window along the time series, measures a statistic (window_stat) in each window, and outputs a summary (across_win_stat) of this set of local estimates of that statistic. Each window is 1/num_seg of the series long and moves on by 1/inc_move of its own length at each step. A stationary series gives similar values in every window.

References

Parameters:
y : array-like

The input time series to analyze.

window_stat : str, optional (default='mean')

Statistic to calculate in each window:

  • ’mean’: arithmetic mean

  • ’std’: standard deviation

  • ’ent’: distribution entropy (kernel-smoothed)

  • ’permen’: normalized permutation entropy, PermEn(3, 1)

  • ’specen’: normalized Shannon spectral entropy of the window’s power spectrum (window mean removed before the FFT; the DC bin is excluded and the entropy is normalized by the log of the number of frequencies, floor(n/2))

  • ’mom3’: skewness (standardized third moment)

  • ’mom4’: kurtosis (standardized fourth moment)

  • ’mom5’: standardized fifth moment

  • ’lillie’: the Lilliefors test statistic (KS distance from a fitted Gaussian CDF), not its p-value

  • ’AC1’: lag-1 autocorrelation

  • ’asymAC1’: mean(x_t * x_{t+tau} * (x_{t+tau} - x_t)) with x z-scored within the window (tau = asym_tau): a nonlinear autocorrelation variant that is antisymmetric under time reversal, so zero in expectation for any time-reversible process

  • ’apen’, ‘sampen’: approximate entropy (m=1, r=0.2) and sample entropy (m=2, r=0.1) of each window (kept for backward compatibility; hctsa does not offer them)

Default is 'mean'.

across_win_stat : str, optional

Method to summarize the sequence of local estimates:

  • ’std’: standard deviation, normalized by that of the full series

  • ’ent’: (kernel-smoothed) distributional entropy of the sequence of local estimates (pyhctsa.operations.distribution.fit_kernel_smooth(); NaN if the local estimates are all the same)

  • ’permen’: normalized permutation entropy, PermEn(3, 1), of the sequence of local estimates

  • ’apen’, ‘sampen’: approximate entropy (m=1, r=0.2) and sample entropy (m=2, r=0.15) (kept for backward compatibility; hctsa does not offer them)

Default is 'std'.

num_seg : int, optional

Number of segments to divide the time series into, which sets the window length, floor(N / num_seg). Default is 5.

inc_move : int, optional

Controls window overlap - window moves by window_length/inc_move at each step (e.g., inc_move=2 means 50% overlap between windows). Default is 2.

asym_tau : int or str, optional

The lag, tau, of the ‘asymAC1’ window statistic (ignored for other statistics): an integer number of samples, or a rule for pyhctsa.utils.get_tau() (e.g., 'ac1e', the floor of the first 1/e crossing of the autocorrelation function) applied to the whole series, so that the lag reflects the series’ own correlation time. A window that is not longer than tau + 1 samples gives NaN. Default is 1.

Returns:

The summary, across_win_stat, of the local estimates of window_stat: how the local statistic varies across the time series (for ‘std’, relative to the full-series standard deviation). NaN if the windows are too short, or if all window statistics are NaN.

Return type:

float