neurodsp.rhythm.sliding_window_matching¶
- neurodsp.rhythm.sliding_window_matching(sig, fs, win_len, win_spacing, max_iterations=100, window_starts_custom=None, var_thresh=None)[source]¶
Find recurring patterns in a time series using the sliding window matching algorithm.
- Parameters
- sig1d array
Time series.
- fsfloat
Sampling rate, in Hz.
- win_lenfloat
Window length, in seconds. This is L in the original paper.
- win_spacingfloat
Minimum spacing between windows, in seconds. This is G in the original paper.
- max_iterationsint, optional, default: 100
Maximum number of iterations of potential changes in window placement.
- window_starts_custom1d array, optional, default: None
Custom pre-set locations of initial windows.
- var_thresh: float, optional, default: None
Removes initial windows with variance below a set threshold. This speeds up runtime proportional to the number of low variance windows in the data.
- Returns
- windows2d array
Putative patterns discovered in the input signal.
- window_starts1d array
Indices at which each window begins for the final set of windows.
Notes
This algorithm is originally described in [1]. This re-implementation is a minimal, modified version of original ([2]), which has more available options.
The win_len parameter should be chosen to be about the size of the motif of interest. The larger this window size, the more likely the pattern to reflect slower patterns.
The win_spacing parameter also determines the number of windows that are used.
If looking at high frequency activity, you may want to apply a highpass filter, so that the algorithm does not converge on a low frequency motif.
This version has the following changes to speed up convergence:
Each iteration is similar to an epoch, randomly moving all windows in random order. The original implementation randomly selects windows and does not guarantee even resampling.
New window acceptance is determined via increased correlation coefficients and reduced variance across windows.
Phase optimization / realignment to escape local minima.
References
- 1
Gips, B., Bahramisharif, A., Lowet, E., Roberts, M. J., de Weerd, P., Jensen, O., & van der Eerden, J. (2017). Discovering recurring patterns in electrophysiological recordings. Journal of Neuroscience Methods, 275, 66-79. DOI: https://doi.org/10.1016/j.jneumeth.2016.11.001
- 2
Matlab Code implementation: https://github.com/bartgips/SWM
Examples
Search for reoccurring patterns using sliding window matching in a simulated beta signal:
>>> from neurodsp.sim import sim_combined >>> components = {'sim_bursty_oscillation' : {'freq' : 20, 'phase' : 'min'}, ... 'sim_powerlaw' : {'f_range' : (2, None)}} >>> sig = sim_combined(10, fs=500, components=components, component_variances=(1, .05)) >>> windows, starts = sliding_window_matching(sig, fs=500, win_len=0.05, ... win_spacing=0.05, var_thresh=.5)