pyhctsa.operations.stationarity.sliding_window

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

Sliding window measures of stationarity.

This function analyzes time series stationarity by sliding a window along the series, calculating specified statistics in each window, and then comparing these local estimates across windows. For each window, it computes a statistic (window_stat) and then summarizes the variation of these statistics across windows (across_win_stat).

This implementation is based on:

References

Note: SlidingWindow(y,’mean’,’std’,X,1) is equivalent to StatAv(y,’seg’,X)

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 (not implemented)

  • ’mom3’: skewness (third moment)

  • ’mom4’: kurtosis (fourth moment)

  • ’mom5’: fifth moment

  • ’lillie’: Lilliefors Gaussianity test p-value (not implemented)

  • ’AC1’: lag-1 autocorrelation

  • ’apen’: Approximate Entropy with m=1, r=0.2

  • ’sampen’: Sample Entropy with m=2, r=0.1

across_win_stat : str, optional (default='std')

Method to compare statistics across windows:

  • ’std’: standard deviation (normalized by full series std)

  • ’ent’: distribution entropy (not implemented)

  • ’apen’: Approximate Entropy with m=1, r=0.2

  • ’sampen’: Sample Entropy with m=2, r=0.15

num_seg : int, optional (default=5)

Number of segments to divide the time series into (controls the window length)

inc_move : int, optional (default=2)

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

Returns:

A measure of how the local statistics vary across the time series, normalized relative to the same measure computed on the full time series. Returns np.nan if time series is too short for specified segmentation.

Return type:

Dict[str, float]