Moving Window Algorithm
- moving_window(signal: ndarray, window_length: int, threshold: float | int | list[float | int] | ndarray) tuple[ndarray, ndarray][source]¶
Perform Moving Window (MW) encoding on the input signal.
This function takes a continuous signal and converts it into a spike train using a moving window and threshold-based approach. A spike is generated when the signal exceeds the calculated base plus or minus a specified threshold.
Refer to the Moving Window (MW) Encoding for a detailed explanation of the Moving Window encoding algorithm.
Code Example:
import numpy as np from spikify.encoders.temporal.contrast import moving_window signal = np.array([0.1, 0.3, 0.2, 0.5, 0.8, 1.0]) window_length = 3 threshold = 0.2 encoded_signal, thresholds = moving_window(signal, window_length, threshold)
- Parameters:
signal (numpy.ndarray) – Input signal to encode (1D or 2D: time × features or channels).
window_length (int) – The size of the sliding window for calculating the signal base mean.
threshold (float | int | list[float | int] | numpy.ndarray) – Threshold(s) for spike generation; scalar or 1D sequence matching features.
- Returns:
spikes: A numpy array representing the encoded spike train. (values in {-1, 0, +1})
thresholds: Per-feature or channel thresholds used for encoding, returned for use in decoding, shape (features or channels,).
- Return type:
- Raises:
ValueError – If the input signal is empty or if the threshold dimensions do not match the signal f eature dimensions.